aboutsummaryrefslogtreecommitdiff
path: root/clang/test/FixIt
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2022-07-22 15:24:54 -0400
committerAaron Ballman <aaron@aaronballman.com>2022-07-22 15:24:54 -0400
commit7068aa98412ade19a34b7ed126f4669f581b2311 (patch)
tree31e4435d3eab49fd73d57be3d62ba0d06d789b93 /clang/test/FixIt
parentb5c7213647aae9c456c0a82af46e7dae9e04bf49 (diff)
downloadllvm-7068aa98412ade19a34b7ed126f4669f581b2311.zip
llvm-7068aa98412ade19a34b7ed126f4669f581b2311.tar.gz
llvm-7068aa98412ade19a34b7ed126f4669f581b2311.tar.bz2
Strengthen -Wint-conversion to default to an error
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
Diffstat (limited to 'clang/test/FixIt')
-rw-r--r--clang/test/FixIt/dereference-addressof.c8
-rw-r--r--clang/test/FixIt/selector-fixit.m4
2 files changed, 6 insertions, 6 deletions
diff --git a/clang/test/FixIt/dereference-addressof.c b/clang/test/FixIt/dereference-addressof.c
index 950fadc..037622e 100644
--- a/clang/test/FixIt/dereference-addressof.c
+++ b/clang/test/FixIt/dereference-addressof.c
@@ -11,12 +11,12 @@ void f(float a) {} // expected-note{{passing argument to parameter 'a' here
void f2(int *aPtr, int a, float *bPtr, char c) {
float fl = 0;
- ip(a); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'; take the address with &}}
- i(aPtr); // expected-warning{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; dereference with *}}
- ii(&a); // expected-warning{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; remove &}}
+ ip(a); // expected-error{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'; take the address with &}}
+ i(aPtr); // expected-error{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; dereference with *}}
+ ii(&a); // expected-error{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; remove &}}
fp(*bPtr); // expected-error{{passing 'float' to parameter of incompatible type 'float *'; remove *}}
f(bPtr); // expected-error{{passing 'float *' to parameter of incompatible type 'float'; dereference with *}}
- a = aPtr; // expected-warning{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}}
+ a = aPtr; // expected-error{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}}
fl = bPtr + a; // expected-error{{assigning to 'float' from incompatible type 'float *'; dereference with *}}
bPtr = bPtr[a]; // expected-error{{assigning to 'float *' from incompatible type 'float'; take the address with &}}
}
diff --git a/clang/test/FixIt/selector-fixit.m b/clang/test/FixIt/selector-fixit.m
index e9d2f19..103f0f0 100644
--- a/clang/test/FixIt/selector-fixit.m
+++ b/clang/test/FixIt/selector-fixit.m
@@ -1,6 +1,6 @@
// RUN: cp %s %t
-// RUN: %clang_cc1 -x objective-c -Wundeclared-selector -fixit %t
-// RUN: %clang_cc1 -x objective-c -Wundeclared-selector -Werror %t
+// RUN: %clang_cc1 -x objective-c -Wundeclared-selector -Wno-int-conversion -fixit %t
+// RUN: %clang_cc1 -x objective-c -Wundeclared-selector -Wno-int-conversion -Werror %t
// rdar://14039037
@interface NSObject @end