
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
29 lines
1.4 KiB
Objective-C
29 lines
1.4 KiB
Objective-C
@import config;
|
|
|
|
int *test_foo(void) {
|
|
return foo();
|
|
}
|
|
|
|
char *test_bar(void) {
|
|
return bar(); // expected-error{{call to undeclared function 'bar'; ISO C99 and later do not support implicit function declarations}} \
|
|
// expected-error{{incompatible integer to pointer conversion}}
|
|
}
|
|
|
|
#undef WANT_FOO // expected-note{{macro was #undef'd here}}
|
|
@import config; // expected-warning{{#undef of configuration macro 'WANT_FOO' has no effect on the import of 'config'; pass '-UWANT_FOO' on the command line to configure the module}}
|
|
|
|
#define WANT_FOO 2 // expected-note{{macro was defined here}}
|
|
@import config; // expected-warning{{definition of configuration macro 'WANT_FOO' has no effect on the import of 'config'; pass '-DWANT_FOO=...' on the command line to configure the module}}
|
|
|
|
#undef WANT_FOO
|
|
#define WANT_FOO 1
|
|
@import config; // okay
|
|
|
|
#define WANT_BAR 1 // expected-note{{macro was defined here}}
|
|
@import config; // expected-warning{{definition of configuration macro 'WANT_BAR' has no effect on the import of 'config'; pass '-DWANT_BAR=...' on the command line to configure the module}}
|
|
|
|
// RUN: rm -rf %t
|
|
// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -x objective-c -fmodules-cache-path=%t -DWANT_FOO=1 -emit-module -fmodule-name=config %S/Inputs/module.map
|
|
// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -DWANT_FOO=1 %s -verify
|
|
|