Skip to content

Commit b247698

Browse files
authored
[Clang] [Sema] Make -Wincompatible-pointer-types an error by default (#157364)
GCC 14 also made this an error by default, so we’re following suit. Fixes #74605
1 parent dffe5e3 commit b247698

File tree

107 files changed

+405
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+405
-392
lines changed

clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-implicits.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
1+
// RUN: %check_clang_tidy %s --extra-arg=-Wno-error=incompatible-pointer-types bugprone-easily-swappable-parameters %t \
22
// RUN: -config='{CheckOptions: { \
33
// RUN: bugprone-easily-swappable-parameters.MinimumLength: 2, \
44
// RUN: bugprone-easily-swappable-parameters.IgnoredParameterNames: "", \

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ C/C++ Language Potentially Breaking Changes
5858

5959
- The ``__has_builtin`` function now only considers the currently active target when being used with target offloading.
6060

61+
- The ``-Wincompatible-pointer-types`` diagnostic now defaults to an error;
62+
it can still be downgraded to a warning by passing ``-Wno-error=incompatible-pointer-types``. (#GH74605)
63+
6164
C++ Specific Potentially Breaking Changes
6265
-----------------------------------------
6366
- For C++20 modules, the Reduced BMI mode will be the default option. This may introduce

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9048,7 +9048,7 @@ def ext_typecheck_convert_incompatible_pointer : ExtWarn<
90489048
"; take the address with &|"
90499049
"; remove *|"
90509050
"; remove &}3">,
9051-
InGroup<IncompatiblePointerTypes>;
9051+
InGroup<IncompatiblePointerTypes>, DefaultError;
90529052
def err_typecheck_convert_incompatible_pointer : Error<
90539053
"incompatible pointer types "
90549054
"%select{%diff{assigning to $ from $|assigning to different types}0,1"

clang/test/APINotes/nullability.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main() {
1515

1616
take_pointer_and_int(0, 0); // expected-warning{{null passed to a callee that requires a non-null argument}}
1717

18-
float *fp = global_int; // expected-warning{{incompatible pointer types initializing 'float *' with an expression of type 'int * _Nonnull'}}
18+
float *fp = global_int; // expected-error{{incompatible pointer types initializing 'float *' with an expression of type 'int * _Nonnull'}}
1919
return 0;
2020
}
2121

clang/test/APINotes/nullability.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ int main() {
1111
A *a;
1212

1313
#if SWIFT_VERSION_3_0
14-
float *fp = // expected-warning{{incompatible pointer types initializing 'float *' with an expression of type 'A * _Nullable'}}
14+
float *fp = // expected-error{{incompatible pointer types initializing 'float *' with an expression of type 'A * _Nullable'}}
1515
[a transform: 0 integer: 0];
1616
#else
17-
float *fp = // expected-warning{{incompatible pointer types initializing 'float *' with an expression of type 'A *'}}
17+
float *fp = // expected-error{{incompatible pointer types initializing 'float *' with an expression of type 'A *'}}
1818
[a transform: 0 integer: 0]; // expected-warning{{null passed to a callee that requires a non-null argument}}
1919
#endif
2020

clang/test/APINotes/types.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
// CHECK-NEXT: } AnonEnumWithTypedefName
1313

1414
void test(OverriddenTypes *overridden) {
15-
int *ip1 = global_int_ptr; // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'double (*)(int, int)'}}
15+
int *ip1 = global_int_ptr; // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'double (*)(int, int)'}}
1616

17-
int *ip2 = global_int_fun( // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
18-
ip2, // expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'double *'}}
19-
ip2); // expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'float *'}}
17+
int *ip2 = global_int_fun( // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
18+
ip2, // expected-error{{incompatible pointer types passing 'int *' to parameter of type 'double *'}}
19+
ip2); // expected-error{{incompatible pointer types passing 'int *' to parameter of type 'float *'}}
2020

21-
int *ip3 = [overridden // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
22-
methodToMangle: ip3 // expected-warning{{incompatible pointer types sending 'int *' to parameter of type 'double *'}}
23-
second: ip3]; // expected-warning{{incompatible pointer types sending 'int *' to parameter of type 'float *'}}
21+
int *ip3 = [overridden // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
22+
methodToMangle: ip3 // expected-error{{incompatible pointer types sending 'int *' to parameter of type 'double *'}}
23+
second: ip3]; // expected-error{{incompatible pointer types sending 'int *' to parameter of type 'float *'}}
2424

25-
int *ip4 = overridden.intPropertyToMangle; // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'double *'}}
25+
int *ip4 = overridden.intPropertyToMangle; // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'double *'}}
2626
}
2727

2828
// expected-note@SomeKit/SomeKit.h:42{{passing argument to parameter 'ptr' here}}

clang/test/AST/ByteCode/atomic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ _Atomic int ai = 0;
88
// FIXME: &ai is an address constant, so this should be accepted as an
99
// initializer, but the bit-cast inserted due to the pointer conversion is
1010
// tripping up the test for whether the initializer is a constant expression.
11-
// The warning is correct but the error is not.
12-
_Atomic(int *) aip3 = &ai; // both-warning {{incompatible pointer types initializing '_Atomic(int *)' with an expression of type '_Atomic(int) *'}} \
11+
// The first error is correct; the second is not.
12+
_Atomic(int *) aip3 = &ai; // both-error {{incompatible pointer types initializing '_Atomic(int *)' with an expression of type '_Atomic(int) *'}} \
1313
// both-error {{initializer element is not a compile-time constant}}
1414

1515
#include <stdatomic.h>

clang/test/AST/ByteCode/c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ const unsigned char _str2[] = {S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7]};
349349
const int compared = strcmp(_str, (const char *)_str2); // all-error {{initializer element is not a compile-time constant}}
350350

351351

352-
const int compared2 = strcmp(strcmp, _str); // all-warning {{incompatible pointer types}} \
352+
const int compared2 = strcmp(strcmp, _str); // all-error {{incompatible pointer types}} \
353353
// all-error {{initializer element is not a compile-time constant}}
354354

355355
int foo(x) // all-warning {{a function definition without a prototype is deprecated in all versions of C}}

clang/test/Analysis/OSAtomic_mac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int *invalidSLocOnRedecl(void) {
1515
// something like "The "compare" part of CompareAndSwap depends on an
1616
// undefined value".
1717
int *b;
18-
OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
18+
OSAtomicCompareAndSwapPtrBarrier(0, 0, (void**)&b); // no-crash
1919
return b;
2020
}
2121

clang/test/Analysis/bsd-string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,5 @@ void f11(void) {
137137
int a, b;
138138
void unknown_val_crash(void) {
139139
// We're unable to evaluate the integer-to-pointer cast.
140-
strlcat(&b, a, 0); // no-crash
140+
strlcat((char*)&b, a, 0); // no-crash
141141
}

0 commit comments

Comments
 (0)