mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 22:36:34 +00:00

Clang has traditionally allowed C programs to implicitly convert integers to pointers and pointers to integers, despite it not being valid to do so except under special circumstances (like converting the integer 0, which is the null pointer constant, to a pointer). In C89, this would result in undefined behavior per 3.3.4, and in C99 this rule was strengthened to be a constraint violation instead. Constraint violations are most often handled as an error. This patch changes the warning to default to an error in all C modes (it is already an error in C++). This gives us better security posture by calling out potential programmer mistakes in code but still allows users who need this behavior to use -Wno-error=int-conversion to retain the warning behavior, or -Wno-int-conversion to silence the diagnostic entirely. Differential Revision: https://reviews.llvm.org/D129881
27 lines
1.1 KiB
Objective-C
27 lines
1.1 KiB
Objective-C
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
|
|
|
|
struct S { int a; };
|
|
|
|
extern int charStarFunc(char *); // expected-note{{passing argument to parameter here}}
|
|
extern int charFunc(char); // expected-note{{passing argument to parameter here}}
|
|
|
|
@interface Test
|
|
+alloc;
|
|
-(int)charStarMeth:(char *)s; // expected-note{{passing argument to parameter 's' here}}
|
|
-structMeth:(struct S)s; // expected-note{{passing argument to parameter 's' here}}
|
|
-structMeth:(struct S)s
|
|
:(struct S)s2; // expected-note{{passing argument to parameter 's2' here}}
|
|
@end
|
|
|
|
void test(void) {
|
|
id obj = [Test alloc];
|
|
struct S sInst;
|
|
|
|
charStarFunc(1); // expected-error {{incompatible integer to pointer conversion passing 'int' to parameter of type 'char *'}}
|
|
charFunc("abc"); // expected-error {{incompatible pointer to integer conversion passing 'char[4]' to parameter of type 'char'}}
|
|
|
|
[obj charStarMeth:1]; // expected-error {{incompatible integer to pointer conversion sending 'int'}}
|
|
[obj structMeth:1]; // expected-error {{sending 'int'}}
|
|
[obj structMeth:sInst :1]; // expected-error {{sending 'int'}}
|
|
}
|