Skip to content

Conversation

Sirraide
Copy link
Member

@Sirraide Sirraide commented Sep 7, 2025

GCC 14 also made this an error by default, and I thought it’d make sense to follow suit.

Fixes #74605

@Sirraide Sirraide requested review from cor3ntin and shafik September 7, 2025 21:00
@Sirraide Sirraide added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Sep 7, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang:static analyzer clang:openmp OpenMP related changes to Clang clang:bytecode Issues for the clang bytecode constexpr interpreter labels Sep 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 7, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-clang-static-analyzer-1
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: None (Sirraide)

Changes

GCC 14 also made this an error by default, and I thought it’d make sense to follow suit.


Patch is 146.31 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/157364.diff

98 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1)
  • (modified) clang/test/APINotes/nullability.c (+1-1)
  • (modified) clang/test/APINotes/nullability.m (+2-2)
  • (modified) clang/test/APINotes/types.m (+8-8)
  • (modified) clang/test/AST/ByteCode/atomic.c (+2-2)
  • (modified) clang/test/AST/ByteCode/c.c (+1-1)
  • (modified) clang/test/Analysis/OSAtomic_mac.c (+1-1)
  • (modified) clang/test/Analysis/bsd-string.c (+1-1)
  • (modified) clang/test/Analysis/novoidtypecrash.c (+1-1)
  • (modified) clang/test/Analysis/override-werror.c (+3-3)
  • (modified) clang/test/Analysis/uninit-vals-union.c (+2-1)
  • (modified) clang/test/C/C23/n3007.c (+1-1)
  • (modified) clang/test/C/C2y/n3369.c (+3-3)
  • (modified) clang/test/C/drs/dr0xx.c (+1-1)
  • (modified) clang/test/CodeGen/2008-03-05-syncPtr.c (+1-1)
  • (modified) clang/test/CodeGen/X86/cmpccxadd-builtins-error.c (+1-1)
  • (modified) clang/test/CodeGen/X86/math-builtins.c (+6-6)
  • (modified) clang/test/CodeGen/arm64-microsoft-intrinsics.c (+13-6)
  • (modified) clang/test/CodeGen/builtin-rename.c (+1-1)
  • (modified) clang/test/CodeGen/ms-intrinsics-underaligned.c (+1-1)
  • (modified) clang/test/CodeGen/ubsan-pass-object-size.c (+2-1)
  • (modified) clang/test/CodeGen/vla.c (+2-2)
  • (modified) clang/test/CodeGen/vlt_to_pointer.c (+1-1)
  • (modified) clang/test/FixIt/fixit-objc-arc.m (+3-3)
  • (modified) clang/test/Frontend/fixed_point_unknown_conversions.c (+2-2)
  • (modified) clang/test/Index/preamble.c (+1-1)
  • (modified) clang/test/Index/warning-flags.c (+3-3)
  • (modified) clang/test/Misc/remap-file.c (+3-3)
  • (modified) clang/test/Modules/diamond-pch.c (+1-1)
  • (modified) clang/test/Modules/diamond.c (+1-1)
  • (modified) clang/test/Modules/serialized-diags.m (+2-2)
  • (modified) clang/test/OpenMP/vla_crash.c (+2-2)
  • (modified) clang/test/PCH/functions.c (+1-1)
  • (modified) clang/test/PCH/objc_exprs.m (+5-5)
  • (modified) clang/test/PCH/objc_kindof.m (+1-1)
  • (modified) clang/test/PCH/variables.c (+1-1)
  • (modified) clang/test/Parser/declarators.c (+1-1)
  • (modified) clang/test/Sema/MicrosoftExtensions.c (+1-1)
  • (modified) clang/test/Sema/atomic-expr.c (+2-2)
  • (modified) clang/test/Sema/atomic-ops.c (+7-7)
  • (modified) clang/test/Sema/attr-format.c (+1-1)
  • (modified) clang/test/Sema/c2x-auto.c (+1-1)
  • (modified) clang/test/Sema/conditional-expr.c (+3-3)
  • (modified) clang/test/Sema/decl-type-merging.c (+2-2)
  • (modified) clang/test/Sema/enum.c (+1-1)
  • (modified) clang/test/Sema/format-strings.c (+2-2)
  • (modified) clang/test/Sema/function.c (+2-2)
  • (modified) clang/test/Sema/merge-decls.c (+2-2)
  • (modified) clang/test/Sema/nullability.c (+7-7)
  • (modified) clang/test/Sema/pass-object-size.c (+1-1)
  • (modified) clang/test/Sema/ptrauth-atomic-ops.c (+1-1)
  • (modified) clang/test/Sema/ptrauth.c (+7-7)
  • (modified) clang/test/Sema/static-array.c (+2-2)
  • (modified) clang/test/Sema/struct-compat.c (+1-1)
  • (modified) clang/test/Sema/var-redecl.c (+1-1)
  • (modified) clang/test/Sema/vector-assign.c (+1-1)
  • (modified) clang/test/Sema/vla.c (+2-2)
  • (modified) clang/test/SemaObjC/arc-decls.m (+1-1)
  • (modified) clang/test/SemaObjC/arc-objcbridge-related-attribute.m (+5-5)
  • (modified) clang/test/SemaObjC/arc.m (+3-3)
  • (modified) clang/test/SemaObjC/attr-objc-NSObject.m (+1-1)
  • (modified) clang/test/SemaObjC/check-objcbridge-related-attribute-lookup.m (+6-6)
  • (modified) clang/test/SemaObjC/class-method-self.m (+2-2)
  • (modified) clang/test/SemaObjC/comptypes-1.m (+12-12)
  • (modified) clang/test/SemaObjC/comptypes-4.m (+1-1)
  • (modified) clang/test/SemaObjC/comptypes-5.m (+1-1)
  • (modified) clang/test/SemaObjC/comptypes-6.m (+1-1)
  • (modified) clang/test/SemaObjC/comptypes-7.m (+8-8)
  • (modified) clang/test/SemaObjC/conditional-expr-2.m (+1-1)
  • (modified) clang/test/SemaObjC/conditional-expr.m (+3-3)
  • (modified) clang/test/SemaObjC/id.m (+2-2)
  • (modified) clang/test/SemaObjC/incompatible-protocol-qualified-types.m (+3-3)
  • (modified) clang/test/SemaObjC/instancetype.m (+5-5)
  • (modified) clang/test/SemaObjC/ivar-lookup.m (+1-1)
  • (modified) clang/test/SemaObjC/kindof.m (+21-21)
  • (modified) clang/test/SemaObjC/method-prototype-scope.m (+1-1)
  • (modified) clang/test/SemaObjC/nullability.m (+42-42)
  • (modified) clang/test/SemaObjC/objcbridge-related-attribute.m (+5-5)
  • (modified) clang/test/SemaObjC/parameterized_classes.m (+4-4)
  • (modified) clang/test/SemaObjC/parameterized_classes_arc.m (+8-8)
  • (modified) clang/test/SemaObjC/parameterized_classes_subst.m (+83-83)
  • (modified) clang/test/SemaObjC/protocol-typecheck.m (+1-1)
  • (modified) clang/test/SemaObjC/protocol-warn.m (+1-1)
  • (modified) clang/test/SemaObjC/related-result-type-inference.m (+2-2)
  • (modified) clang/test/SemaObjC/unqualified-to-qualified-class-warn.m (+1-1)
  • (modified) clang/test/SemaObjC/warn-incompatible-builtin-types.m (+9-9)
  • (modified) clang/test/SemaObjC/warn-superclass-method-mismatch.m (+1-1)
  • (modified) clang/test/SemaObjCXX/blocks.mm (+1-1)
  • (modified) clang/test/SemaObjCXX/objc-pointer-conv.mm (+2-2)
  • (modified) clang/test/SemaObjCXX/overload.mm (+5-5)
  • (modified) clang/test/SemaObjCXX/parameterized_classes_subst.mm (+3-3)
  • (modified) clang/test/SemaObjCXX/related-result-type-inference.mm (+2-2)
  • (modified) clang/test/SemaOpenACC/combined-construct-if-clause.c (+1-1)
  • (modified) clang/test/SemaOpenACC/compute-construct-if-clause.c (+1-1)
  • (modified) clang/test/SemaOpenCL/address-spaces.cl (+3-4)
  • (modified) clang/test/SemaOpenCL/atomic-ops.cl (+2-2)
  • (modified) clang/test/SemaOpenCL/to_addr_builtin.cl (+2-2)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d1ef91b7e7c14..04815d064b4ea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -58,6 +58,9 @@ C/C++ Language Potentially Breaking Changes
 
 - The ``__has_builtin`` function now only considers the currently active target when being used with target offloading.
 
+- The ``-Wincompatible-pointer-types`` diagnostic now defaults to an error;
+  it can still be downgraded to a warning by passing ``-Wno-error=incompatible-pointer-types``.
+
 C++ Specific Potentially Breaking Changes
 -----------------------------------------
 - For C++20 modules, the Reduced BMI mode will be the default option. This may introduce
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 711efbe727892..097c0b92d53dc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9048,7 +9048,7 @@ def ext_typecheck_convert_incompatible_pointer : ExtWarn<
   "; take the address with &|"
   "; remove *|"
   "; remove &}3">,
-  InGroup<IncompatiblePointerTypes>;
+  InGroup<IncompatiblePointerTypes>, DefaultError;
 def err_typecheck_convert_incompatible_pointer : Error<
   "incompatible pointer types "
   "%select{%diff{assigning to $ from $|assigning to different types}0,1"
diff --git a/clang/test/APINotes/nullability.c b/clang/test/APINotes/nullability.c
index e07fc2e5c1174..4b310d4fb0068 100644
--- a/clang/test/APINotes/nullability.c
+++ b/clang/test/APINotes/nullability.c
@@ -15,7 +15,7 @@ int main() {
 
   take_pointer_and_int(0, 0); // expected-warning{{null passed to a callee that requires a non-null argument}}
 
-  float *fp = global_int; // expected-warning{{incompatible pointer types initializing 'float *' with an expression of type 'int * _Nonnull'}}
+  float *fp = global_int; // expected-error{{incompatible pointer types initializing 'float *' with an expression of type 'int * _Nonnull'}}
   return 0;
 }
 
diff --git a/clang/test/APINotes/nullability.m b/clang/test/APINotes/nullability.m
index 21ec6680fa714..2c32caf6260a6 100644
--- a/clang/test/APINotes/nullability.m
+++ b/clang/test/APINotes/nullability.m
@@ -11,10 +11,10 @@ int main() {
   A *a;
 
 #if SWIFT_VERSION_3_0
-  float *fp =  // expected-warning{{incompatible pointer types initializing 'float *' with an expression of type 'A * _Nullable'}}
+  float *fp =  // expected-error{{incompatible pointer types initializing 'float *' with an expression of type 'A * _Nullable'}}
     [a transform: 0 integer: 0];
 #else
-  float *fp =  // expected-warning{{incompatible pointer types initializing 'float *' with an expression of type 'A *'}}
+  float *fp =  // expected-error{{incompatible pointer types initializing 'float *' with an expression of type 'A *'}}
     [a transform: 0 integer: 0]; // expected-warning{{null passed to a callee that requires a non-null argument}}
 #endif
 
diff --git a/clang/test/APINotes/types.m b/clang/test/APINotes/types.m
index 752f102643284..9e78d406b9ed9 100644
--- a/clang/test/APINotes/types.m
+++ b/clang/test/APINotes/types.m
@@ -12,17 +12,17 @@
 // CHECK-NEXT: } AnonEnumWithTypedefName
 
 void test(OverriddenTypes *overridden) {
-  int *ip1 = global_int_ptr; // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'double (*)(int, int)'}}
+  int *ip1 = global_int_ptr; // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'double (*)(int, int)'}}
 
-  int *ip2 = global_int_fun( // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
-               ip2, // expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'double *'}}
-               ip2); // expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'float *'}}
+  int *ip2 = global_int_fun( // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
+               ip2, // expected-error{{incompatible pointer types passing 'int *' to parameter of type 'double *'}}
+               ip2); // expected-error{{incompatible pointer types passing 'int *' to parameter of type 'float *'}}
 
-  int *ip3 = [overridden // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
-                methodToMangle: ip3 // expected-warning{{incompatible pointer types sending 'int *' to parameter of type 'double *'}}
-                        second: ip3]; // expected-warning{{incompatible pointer types sending 'int *' to parameter of type 'float *'}}
+  int *ip3 = [overridden // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'char *'}}
+                methodToMangle: ip3 // expected-error{{incompatible pointer types sending 'int *' to parameter of type 'double *'}}
+                        second: ip3]; // expected-error{{incompatible pointer types sending 'int *' to parameter of type 'float *'}}
 
-  int *ip4 = overridden.intPropertyToMangle; // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'double *'}}
+  int *ip4 = overridden.intPropertyToMangle; // expected-error{{incompatible pointer types initializing 'int *' with an expression of type 'double *'}}
 }
 
 // expected-note@SomeKit/SomeKit.h:42{{passing argument to parameter 'ptr' here}}
diff --git a/clang/test/AST/ByteCode/atomic.c b/clang/test/AST/ByteCode/atomic.c
index c8469d4a938b8..a93787ccd1e02 100644
--- a/clang/test/AST/ByteCode/atomic.c
+++ b/clang/test/AST/ByteCode/atomic.c
@@ -8,8 +8,8 @@ _Atomic int ai = 0;
 // FIXME: &ai is an address constant, so this should be accepted as an
 // initializer, but the bit-cast inserted due to the pointer conversion is
 // tripping up the test for whether the initializer is a constant expression.
-// The warning is correct but the error is not.
-_Atomic(int *) aip3 = &ai; // both-warning {{incompatible pointer types initializing '_Atomic(int *)' with an expression of type '_Atomic(int) *'}} \
+// The first error is correct; the second is not.
+_Atomic(int *) aip3 = &ai; // both-error {{incompatible pointer types initializing '_Atomic(int *)' with an expression of type '_Atomic(int) *'}} \
                            // both-error {{initializer element is not a compile-time constant}}
 
 #include <stdatomic.h>
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index b6d2a69271afb..6681a4f427093 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -349,7 +349,7 @@ const unsigned char _str2[] = {S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7]};
 const int compared = strcmp(_str, (const char *)_str2); // all-error {{initializer element is not a compile-time constant}}
 
 
-const int compared2 = strcmp(strcmp, _str); // all-warning {{incompatible pointer types}} \
+const int compared2 = strcmp(strcmp, _str); // all-error {{incompatible pointer types}} \
                                             // all-error {{initializer element is not a compile-time constant}}
 
 int foo(x) // all-warning {{a function definition without a prototype is deprecated in all versions of C}}
diff --git a/clang/test/Analysis/OSAtomic_mac.c b/clang/test/Analysis/OSAtomic_mac.c
index 5cf7e93014323..9e3fef782de34 100644
--- a/clang/test/Analysis/OSAtomic_mac.c
+++ b/clang/test/Analysis/OSAtomic_mac.c
@@ -15,7 +15,7 @@ int *invalidSLocOnRedecl(void) {
   // something like "The "compare" part of CompareAndSwap depends on an
   // undefined value".
   int *b;
-  OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
+  OSAtomicCompareAndSwapPtrBarrier(0, 0, (void**)&b); // no-crash
   return b;
 }
 
diff --git a/clang/test/Analysis/bsd-string.c b/clang/test/Analysis/bsd-string.c
index 93b2214786009..0c22dd0719132 100644
--- a/clang/test/Analysis/bsd-string.c
+++ b/clang/test/Analysis/bsd-string.c
@@ -137,5 +137,5 @@ void f11(void) {
 int a, b;
 void unknown_val_crash(void) {
   // We're unable to evaluate the integer-to-pointer cast.
-  strlcat(&b, a, 0); // no-crash
+  strlcat((char*)&b, a, 0); // no-crash
 }
diff --git a/clang/test/Analysis/novoidtypecrash.c b/clang/test/Analysis/novoidtypecrash.c
index 5af30c2010438..325dd505a4201 100644
--- a/clang/test/Analysis/novoidtypecrash.c
+++ b/clang/test/Analysis/novoidtypecrash.c
@@ -3,7 +3,7 @@ x;
 y(void **z) { // no-crash
   *z = x;
   int *w;
-  y(&w);
+  y((void**)&w);
   *w;
 }
 
diff --git a/clang/test/Analysis/override-werror.c b/clang/test/Analysis/override-werror.c
index e84c20fc0696f..1aeed80492cca 100644
--- a/clang/test/Analysis/override-werror.c
+++ b/clang/test/Analysis/override-werror.c
@@ -5,9 +5,9 @@
 // -Werror.  This allows basic warnings not to interfere with producing
 // analyzer results.
 
-char* f(int *p) {
-  return p; // expected-warning{{incompatible pointer types}} \
-               werror-warning{{incompatible pointer types}}
+void f(int *p) {
+  int; // expected-warning{{declaration does not declare anything}} \
+          werror-warning{{declaration does not declare anything}}
 }
 
 void g(int *p) {
diff --git a/clang/test/Analysis/uninit-vals-union.c b/clang/test/Analysis/uninit-vals-union.c
index e16cccfc9115a..3992a3a160c5e 100644
--- a/clang/test/Analysis/uninit-vals-union.c
+++ b/clang/test/Analysis/uninit-vals-union.c
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core.builtin -verify -Wno-unused %s
+// expected-no-diagnostics
 
 typedef union {
   int y;
@@ -8,6 +9,6 @@ typedef struct { int x; } A;
 
 void foo(void) {
   U u = {};
-  A *a = &u; // expected-warning{{incompatible pointer types}}
+  A *a = (A*)&u;
   a->x;      // no-crash
 }
diff --git a/clang/test/C/C23/n3007.c b/clang/test/C/C23/n3007.c
index 34ec419b71b27..b8b84519fc19d 100644
--- a/clang/test/C/C23/n3007.c
+++ b/clang/test/C/C23/n3007.c
@@ -13,7 +13,7 @@ void test_qualifiers(int x, const int y, int * restrict z) {
   static auto c = 1UL;
   int* pa = &a; // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
   const int* pb = &b;
-  int* pc = &c; // expected-warning {{incompatible pointer types initializing 'int *' with an expression of type 'unsigned long *'}}
+  int* pc = &c; // expected-error {{incompatible pointer types initializing 'int *' with an expression of type 'unsigned long *'}}
 
   const int ci = 12;
   auto yup = ci;
diff --git a/clang/test/C/C2y/n3369.c b/clang/test/C/C2y/n3369.c
index db26040d8cf44..dd3125709279d 100644
--- a/clang/test/C/C2y/n3369.c
+++ b/clang/test/C/C2y/n3369.c
@@ -100,11 +100,11 @@ void test_funcs() {
   int i5[5];
   char c35[3][5];
   test_func_fix_fix(5, &c35, &i3, NULL);
-  test_func_fix_fix(5, &c35, &i5, NULL); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[3]'}}
+  test_func_fix_fix(5, &c35, &i5, NULL); // expected-error {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[3]'}}
   test_func_fix_var(5, &c35, &i3, NULL);
-  test_func_fix_var(5, &c35, &i5, NULL); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[3]'}}
+  test_func_fix_var(5, &c35, &i5, NULL); // expected-error {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[3]'}}
   test_func_fix_uns(5, &c35, &i3, NULL);
-  test_func_fix_uns(5, &c35, &i5, NULL); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[3]'}}
+  test_func_fix_uns(5, &c35, &i5, NULL); // expected-error {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[3]'}}
 }
 
 void test_multidimensional_arrays() {
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index c2b1a5b4bbecd..77ade3c351171 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -459,7 +459,7 @@ void dr088_1(void) {
   /* Distinct type from the file scope forward declaration. */
   struct dr088_t_1;
   /* FIXME: this diagnostic could be improved to not be utterly baffling. */
-  dr088_f((struct dr088_t_1 *)0); /* expected-warning {{incompatible pointer types passing 'struct dr088_t_1 *' to parameter of type 'struct dr088_t_1 *'}} */
+  dr088_f((struct dr088_t_1 *)0); /* expected-error {{incompatible pointer types passing 'struct dr088_t_1 *' to parameter of type 'struct dr088_t_1 *'}} */
 }
 
 void dr088_2(struct dr088_t_1 *p) { /* Pointer to incomplete type. */ }
diff --git a/clang/test/CodeGen/2008-03-05-syncPtr.c b/clang/test/CodeGen/2008-03-05-syncPtr.c
index 8968a7dc2678c..30dc4f26e1d3e 100644
--- a/clang/test/CodeGen/2008-03-05-syncPtr.c
+++ b/clang/test/CodeGen/2008-03-05-syncPtr.c
@@ -34,7 +34,7 @@ int* foo5(int** a, int* b) {
 
 
 int* foo6(int** a, int*** b) {
-  return __sync_lock_test_and_set (a, b);
+  return __sync_lock_test_and_set (a, (int*)b);
 }
 // CHECK-LABEL: define{{.*}} ptr @foo6
 // CHECK: atomicrmw xchg {{.*}}, align 8
diff --git a/clang/test/CodeGen/X86/cmpccxadd-builtins-error.c b/clang/test/CodeGen/X86/cmpccxadd-builtins-error.c
index f7ecf12d0becf..d931c0eae01d4 100644
--- a/clang/test/CodeGen/X86/cmpccxadd-builtins-error.c
+++ b/clang/test/CodeGen/X86/cmpccxadd-builtins-error.c
@@ -12,5 +12,5 @@ long long test_cmpccxadd64(void *__A, long long __B, long long __C) {
 }
 
 long long test_cmpccxadd64_2(int *__A, long long __B, long long __C) {
-  return _cmpccxadd_epi64(__A, __B, __C, 3); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'long long *'}}
+  return _cmpccxadd_epi64(__A, __B, __C, 3); // expected-error {{incompatible pointer types passing 'int *' to parameter of type 'long long *'}}
 }
diff --git a/clang/test/CodeGen/X86/math-builtins.c b/clang/test/CodeGen/X86/math-builtins.c
index 8a85d1f6c3a76..a56f8ba1ee385 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -o - -emit-llvm %s | FileCheck %s -check-prefix=NO__ERRNO
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -o - -emit-llvm -fmath-errno %s | FileCheck %s -check-prefix=HAS_ERRNO
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -o - -emit-llvm -disable-llvm-passes -O2 %s | FileCheck %s -check-prefix=NO__ERRNO
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -o - -emit-llvm -disable-llvm-passes -O2 -fmath-errno %s | FileCheck %s -check-prefix=HAS_ERRNO
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown-gnu -w -o - -emit-llvm -fmath-errno %s | FileCheck %s --check-prefix=HAS_ERRNO_GNU
-// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -w -o - -emit-llvm -fmath-errno %s | FileCheck %s --check-prefix=HAS_ERRNO_WIN
+// RUN: %clang_cc1 -Wno-error=incompatible-pointer-types -triple x86_64-unknown-unknown -w -o - -emit-llvm %s | FileCheck %s -check-prefix=NO__ERRNO
+// RUN: %clang_cc1 -Wno-error=incompatible-pointer-types -triple x86_64-unknown-unknown -w -o - -emit-llvm -fmath-errno %s | FileCheck %s -check-prefix=HAS_ERRNO
+// RUN: %clang_cc1 -Wno-error=incompatible-pointer-types -triple x86_64-unknown-unknown -w -o - -emit-llvm -disable-llvm-passes -O2 %s | FileCheck %s -check-prefix=NO__ERRNO
+// RUN: %clang_cc1 -Wno-error=incompatible-pointer-types -triple x86_64-unknown-unknown -w -o - -emit-llvm -disable-llvm-passes -O2 -fmath-errno %s | FileCheck %s -check-prefix=HAS_ERRNO
+// RUN: %clang_cc1 -Wno-error=incompatible-pointer-types -triple x86_64-unknown-unknown-gnu -w -o - -emit-llvm -fmath-errno %s | FileCheck %s --check-prefix=HAS_ERRNO_GNU
+// RUN: %clang_cc1 -Wno-error=incompatible-pointer-types -triple x86_64-unknown-windows-msvc -w -o - -emit-llvm -fmath-errno %s | FileCheck %s --check-prefix=HAS_ERRNO_WIN
 
 // Test attributes and codegen of math builtins.
 
diff --git a/clang/test/CodeGen/arm64-microsoft-intrinsics.c b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
index 51e0038b64cde..c0ff785883c71 100644
--- a/clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -4,14 +4,21 @@
 // RUN: not %clang_cc1 -triple arm64-linux -Werror -S -o /dev/null %s 2>&1 \
 // RUN:    | FileCheck %s -check-prefix CHECK-LINUX
 
-// RUN: %clang_cc1 -triple arm64-darwin -Wno-implicit-function-declaration -fms-compatibility -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple arm64-darwin -Wno-implicit-function-declaration -fms-compatibility -emit-llvm -o - -DARM64_DARWIN %s \
 // RUN:    | FileCheck %s -check-prefix CHECK-MSCOMPAT
 
-long test_InterlockedAdd(long volatile *Addend, long Value) {
+// For some reason '_InterlockedAdd` on arm64-darwin takes an 'int*' rather than a 'long*'.
+#ifdef ARM64_DARWIN
+typedef int int32_t;
+#else
+typedef long int32_t;
+#endif
+
+long test_InterlockedAdd(int32_t volatile *Addend, long Value) {
   return _InterlockedAdd(Addend, Value);
 }
 
-long test_InterlockedAdd_constant(long volatile *Addend) {
+long test_InterlockedAdd_constant(int32_t volatile *Addend) {
   return _InterlockedAdd(Addend, -1);
 }
 
@@ -21,7 +28,7 @@ long test_InterlockedAdd_constant(long volatile *Addend) {
 // CHECK-MSVC: ret i32 %[[NEWVAL:[0-9]+]]
 // CHECK-LINUX: error: call to undeclared function '_InterlockedAdd'
 
-long test_InterlockedAdd_acq(long volatile *Addend, long Value) {
+long test_InterlockedAdd_acq(int32_t volatile *Addend, long Value) {
   return _InterlockedAdd_acq(Addend, Value);
 }
 
@@ -31,7 +38,7 @@ long test_InterlockedAdd_acq(long volatile *Addend, long Value) {
 // CHECK-MSVC: ret i32 %[[NEWVAL:[0-9]+]]
 // CHECK-LINUX: error: call to undeclared function '_InterlockedAdd_acq'
 
-long test_InterlockedAdd_nf(long volatile *Addend, long Value) {
+long test_InterlockedAdd_nf(int32_t volatile *Addend, long Value) {
   return _InterlockedAdd_nf(Addend, Value);
 }
 
@@ -41,7 +48,7 @@ long test_InterlockedAdd_nf(long volatile *Addend, long Value) {
 // CHECK-MSVC: ret i32 %[[NEWVAL:[0-9]+]]
 // CHECK-LINUX: error: call to undeclared function '_InterlockedAdd_nf'
 
-long test_InterlockedAdd_rel(long volatile *Addend, long Value) {
+long test_InterlockedAdd_rel(int32_t volatile *Addend, long Value) {
   return _InterlockedAdd_rel(Addend, Value);
 }
 
diff --git a/clang/test/CodeGen/builtin-rename.c b/clang/test/CodeGen/builtin-rename.c
index 0b71d88806237..0092e54ef37d9 100644
--- a/clang/test/CodeGen/builtin-rename.c
+++ b/clang/test/CodeGen/builtin-rename.c
@@ -4,5 +4,5 @@
 int printf(const char *, ...);
 
 int foo(void) {
-  return printf(printf);
+  return printf((const char*)printf);
 }
diff --git a/clang/test/CodeGen/ms-intrinsics-underaligned.c b/clang/test/CodeGen/ms-intrinsics-underaligned.c
index 34e2afb09f4b9..5be8ed8c6a600 100644
--- a/clang/test/CodeGen/ms-intrinsics-underaligned.c
+++ b/clang/test/CodeGen/ms-intrinsics-underaligned.c
@@ -111,6 +111,6 @@ long test_InterlockedAdd(X *x) {
 // CHECK-AARCH64-LABEL: @test_InterlockedAdd64(
 // CHECK-AARCH64:   atomicrmw {{.*}} align 8
 long test_InterlockedAdd64(X *x) {
-  return _InterlockedAdd64(&x->c, 4);
+  return _InterlockedAdd64((volatile long long*)&x->c, 4);
 }
 #endif
diff --git a/clang/test/CodeGen/ubsan-pass-object-size.c b/clang/test/CodeGen/ubsan-pass-object-size.c
index b36b8bb409aef..c606d33128322 100644
--- a/clang/test/CodeGen/ubsan-pass-object-size.c
+++ b/clang/test/CodeGen/ubsan-pass-object-size.c
@@ -14,7 +14,8 @@ int foo(int *const p __attribute__((pass_object_size(0))), int n) {
   // CHECK: __ubsan_handle_out_of_bounds
 
   {
-    int **p = &p; // Shadow the parameter. The pass_object_size info is lost.
+    int **q = &p;
+    int **p = q; // Shadow the parameter. The pass_object_size info is lost.
     // CHECK-NOT: __ubsan_handle_out_of_bounds
     x = *p[n];
   }
diff --git a/clang/test/CodeGen/vla.c b/clang/test/CodeGen/vla.c
index a22ba727df2fe..18aa744b5f6fe 100644
--- a/clang/test/CodeGen/vla.c
+++ b/clang/test/CodeGen/vla.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -Wno-int-conversion -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,NULL-INVALID
-// RUN: %clang_cc1 -Wno-int-conversion -triple i386-unknown-unknown %s -emit-llvm -fno-delete-null-pointer-checks -o - | FileCheck %s -check-prefixes=CHECK,NULL-VALID
+// RUN: %clang_cc1 -Wno-error=incompatible-pointer-types -Wno-int-conversion -triple i386-unknown-unknown %s -emit-llvm -o - | File...
[truncated]

@thesamesam
Copy link
Member

#74605

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but let's see if other people have opinions in the next few days.
That GCC did it first and did not get pushback is reassuring

@erichkeane

Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, and if GCC hasn't gotten a huge amount of pushback, then there is no reason for us not to do this.

Copy link

github-actions bot commented Sep 8, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@thesamesam
Copy link
Member

IIRC the Clang behaviour for -Wincompatible-pointer-types differs from GCC as it includes qualifiers while GCC doesn't, so it may show up with some new failures. That's not a comment for or against changing it.

@Sirraide
Copy link
Member Author

Sirraide commented Sep 8, 2025

IIRC the Clang behaviour for -Wincompatible-pointer-types differs from GCC as it includes qualifiers while GCC doesn't, so it may show up with some new failures. That's not a comment for or against changing it.

Sort of: while -Werror=incompatible-pointer-types would indeed make e.g. const char* -> char* ill-formed as well, that only applies if you make the entire warning group an error. This pr is only making a single warning an error, so e.g. const char* -> char* is still just a warning.

@thesamesam
Copy link
Member

Ah, I see. Thanks!

@Sirraide Sirraide enabled auto-merge (squash) September 15, 2025 16:05
@Sirraide Sirraide merged commit b247698 into llvm:main Sep 15, 2025
10 checks passed
@Sirraide Sirraide deleted the incompatible-pointer-types branch September 15, 2025 17:15
@Sirraide
Copy link
Member Author

Looks like this is causing errors in llvm-testsuite, but I’m candidly not sure how this is usually handled:
https://lab.llvm.org/buildbot/#/builders/210/builds/2746

@asb
Copy link
Contributor

asb commented Sep 15, 2025

Looks like this is causing errors in llvm-testsuite, but I’m candidly not sure how this is usually handled: https://lab.llvm.org/buildbot/#/builders/210/builds/2746

I think we'll want to add -Wno-incompatible-pointer-types to the relevant CMakeLists.txt. As an example, we can see @AaronBallman making such changes around https://github.com/llvm/llvm-test-suite/commits/099fc20d7e352f51d7c76a5d89fecbd15d7fae5e for the -Wimplicit-int change.

@Sirraide
Copy link
Member Author

I think we'll want to add -Wno-incompatible-pointer-types to the relevant CMakeLists.txt.

Thanks; I’ll look into it.

@Sirraide
Copy link
Member Author

Should be fixed by llvm/llvm-test-suite@8a20f8c unless more tests start failing.

@Sirraide
Copy link
Member Author

Should be fixed by llvm/llvm-test-suite@8a20f8c unless more tests start failing.

Update, there’ve been a few more, so I’m doing the same thing Aaron did and fixing them one at a time as the bot detects the failures (because I’m pretty sure waiting for the test suite to run on my system would take a lot longer...).

Sirraide added a commit that referenced this pull request Sep 15, 2025
Fix another test impacted by #157364.

On Windows, `GetComputerNameA()`, which is what this ends up calling,
takes an `LPDWORD`, but we were handing it an `int*`; fix this by
declaring it as a `DWORD` instead.
@adrian-prantl
Copy link
Collaborator

@medismailben @Sirraide This seems to have broken several tests several tests in the LLDB test suite:
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/33215/

@Sirraide
Copy link
Member Author

This seems to have broken several tests several tests in the LLDB test suite: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/33215/

Weird, I’m pretty sure I ran the LLDB tests locally and didn’t observe any errors; I’m looking into it.

@Sirraide
Copy link
Member Author

This seems to have broken several tests several tests in the LLDB test suite: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/33215/

Weird, I’m pretty sure I ran the LLDB tests locally and didn’t observe any errors; I’m looking into it.

Should be fixed by #158756.

@medismailben
Copy link
Member

medismailben commented Sep 16, 2025

@Sirraide Thanks, feel free to merge whenever

Sirraide added a commit that referenced this pull request Sep 16, 2025
… some tests (#158756)

These no longer compile because the warning now defaults to an error
after #157364, so downgrade the error to a warning for now; I’m not
familiar enough with either LLDB or MacOS to fix these warnings properly
(assuming they’re unintended).
MrSidims added a commit to KhronosGroup/SPIRV-LLVM-Translator that referenced this pull request Sep 16, 2025
InvalidAtomicBuiltins.cl requires an update after
llvm/llvm-project#157364

Signed-off-by: Sidorov, Dmitry <[email protected]>
kimsh02 pushed a commit to kimsh02/llvm-project that referenced this pull request Sep 19, 2025
Fix another test impacted by llvm#157364.

On Windows, `GetComputerNameA()`, which is what this ends up calling,
takes an `LPDWORD`, but we were handing it an `int*`; fix this by
declaring it as a `DWORD` instead.
kimsh02 pushed a commit to kimsh02/llvm-project that referenced this pull request Sep 19, 2025
… some tests (llvm#158756)

These no longer compile because the warning now defaults to an error
after llvm#157364, so downgrade the error to a warning for now; I’m not
familiar enough with either LLDB or MacOS to fix these warnings properly
(assuming they’re unintended).
itzexpoexpo pushed a commit to itzexpoexpo/llvm-project that referenced this pull request Sep 21, 2025
llvm#157364)

GCC 14 also made this an error by default, so we’re following suit.

Fixes llvm#74605
itzexpoexpo pushed a commit to itzexpoexpo/llvm-project that referenced this pull request Sep 21, 2025
Fix another test impacted by llvm#157364.

On Windows, `GetComputerNameA()`, which is what this ends up calling,
takes an `LPDWORD`, but we were handing it an `int*`; fix this by
declaring it as a `DWORD` instead.
itzexpoexpo pushed a commit to itzexpoexpo/llvm-project that referenced this pull request Sep 21, 2025
… some tests (llvm#158756)

These no longer compile because the warning now defaults to an error
after llvm#157364, so downgrade the error to a warning for now; I’m not
familiar enough with either LLDB or MacOS to fix these warnings properly
(assuming they’re unintended).
SeongjaeP pushed a commit to SeongjaeP/llvm-project that referenced this pull request Sep 23, 2025
llvm#157364)

GCC 14 also made this an error by default, so we’re following suit.

Fixes llvm#74605
SeongjaeP pushed a commit to SeongjaeP/llvm-project that referenced this pull request Sep 23, 2025
Fix another test impacted by llvm#157364.

On Windows, `GetComputerNameA()`, which is what this ends up calling,
takes an `LPDWORD`, but we were handing it an `int*`; fix this by
declaring it as a `DWORD` instead.
SeongjaeP pushed a commit to SeongjaeP/llvm-project that referenced this pull request Sep 23, 2025
… some tests (llvm#158756)

These no longer compile because the warning now defaults to an error
after llvm#157364, so downgrade the error to a warning for now; I’m not
familiar enough with either LLDB or MacOS to fix these warnings properly
(assuming they’re unintended).
iclsrc pushed a commit to intel/llvm that referenced this pull request Sep 27, 2025
InvalidAtomicBuiltins.cl requires an update after
llvm/llvm-project#157364

Signed-off-by: Sidorov, Dmitry <[email protected]>

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@28fc4d6306e812c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:bytecode Issues for the clang bytecode constexpr interpreter clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang:openmp OpenMP related changes to Clang clang:static analyzer clang Clang issues not falling into any other category clang-tidy clang-tools-extra compiler-rt:sanitizer compiler-rt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make -Wincompatible-pointer-types an error by default
9 participants