Skip to content

Commit b8605d0

Browse files
AaronBallmanronlieb
authored andcommitted
Split -Wcast-function-type into a separate group (llvm#86131)
We want to add -Wcast-function-type to -Wextra (as done in 1de7e6c), but we do not want to add -Wcast-function-type-strict in at the same time (https://lab.llvm.org/buildbot/#/builders/57/builds/33601/steps/5/logs/stdio). This moves the existing warning to a new group (-Wcast-function-type-mismatch), puts the new group under the existing -Wcast-function-type warning group, and adds -Wcast-function-type-mismatch to -Wextra. Change-Id: I30b415f834c3655d74000c247d8cb7ff98426042
1 parent 179df8e commit b8605d0

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,25 @@ Modified Compiler Flags
213213
the ``promoted`` algorithm for complex division when possible rather than the
214214
less basic (limited range) algorithm.
215215

216-
- Added ``-Wcast-function-type`` as a warning enabled by ``-Wextra``. #GH76872
216+
- Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
217+
warning group. Moved the diagnostic previously controlled by
218+
``-Wcast-function-type`` to the new warning group and added
219+
``-Wcast-function-type-mismatch`` to ``-Wextra``. #GH76872
220+
221+
.. code-block:: c
222+
223+
int x(long);
224+
typedef int (f2)(void*);
225+
typedef int (f3)();
226+
227+
void func(void) {
228+
// Diagnoses under -Wcast-function-type, -Wcast-function-type-mismatch,
229+
// -Wcast-function-type-strict, -Wextra
230+
f2 *b = (f2 *)x;
231+
// Diagnoses under -Wcast-function-type, -Wcast-function-type-strict
232+
f3 *c = (f3 *)x;
233+
}
234+
217235
218236
Removed Compiler Flags
219237
-------------------------

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,10 @@ def SelTypeCast : DiagGroup<"cast-of-sel-type">;
597597
def FunctionDefInObjCContainer : DiagGroup<"function-def-in-objc-container">;
598598
def BadFunctionCast : DiagGroup<"bad-function-cast">;
599599
def CastFunctionTypeStrict : DiagGroup<"cast-function-type-strict">;
600-
def CastFunctionType : DiagGroup<"cast-function-type", [CastFunctionTypeStrict]>;
600+
def CastFunctionTypeMismatch : DiagGroup<"cast-function-type-mismatch">;
601+
def CastFunctionType : DiagGroup<"cast-function-type",
602+
[CastFunctionTypeStrict,
603+
CastFunctionTypeMismatch]>;
601604
def ObjCPropertyImpl : DiagGroup<"objc-property-implementation">;
602605
def ObjCPropertyNoAttribute : DiagGroup<"objc-property-no-attribute">;
603606
def ObjCPropertyAssignOnObjectType : DiagGroup<"objc-property-assign-on-object-type">;
@@ -1063,7 +1066,7 @@ def Extra : DiagGroup<"extra", [
10631066
EmptyInitStatement,
10641067
StringConcatation,
10651068
FUseLdPath,
1066-
CastFunctionType,
1069+
CastFunctionTypeMismatch,
10671070
]>;
10681071

10691072
def Most : DiagGroup<"most", [

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9197,7 +9197,7 @@ def warn_bad_function_cast : Warning<
91979197
InGroup<BadFunctionCast>, DefaultIgnore;
91989198
def warn_cast_function_type : Warning<
91999199
"cast %diff{from $ to $ |}0,1converts to incompatible function type">,
9200-
InGroup<CastFunctionType>, DefaultIgnore;
9200+
InGroup<CastFunctionTypeMismatch>, DefaultIgnore;
92019201
def warn_cast_function_type_strict : Warning<warn_cast_function_type.Summary>,
92029202
InGroup<CastFunctionTypeStrict>, DefaultIgnore;
92039203
def err_cast_pointer_to_non_pointer_int : Error<

clang/test/Sema/warn-cast-function-type-strict.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
2-
// RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
1+
// RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify=expected,strict
2+
// RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify=expected,strict
33
// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
44

55
int t(int array[static 12]);
@@ -38,16 +38,16 @@ int e2func(enum E2);
3838

3939
void foo(void) {
4040
a = (f1 *)x;
41-
a = (f1 *)efunc; // expected-warning {{cast from 'int (*)(enum E)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
42-
a = (f1 *)e2func; // expected-warning {{cast from 'int (*)(enum E2)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
41+
a = (f1 *)efunc; // strict-warning {{cast from 'int (*)(enum E)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
42+
a = (f1 *)e2func; // strict-warning {{cast from 'int (*)(enum E2)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
4343
b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}} */
44-
c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)()') converts to incompatible function type}} */
44+
c = (f3 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)()') converts to incompatible function type}} */
4545
d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)()') converts to incompatible function type}} */
46-
e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)(void)') converts to incompatible function type}} */
46+
e = (f5 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)(void)') converts to incompatible function type}} */
4747
f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
48-
g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}} */
48+
g = (f7 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}} */
4949
h = (f8 *)t;
5050
i = (f9 *)u;
5151
// FIXME: return type qualifier should not be included in the function type . Warning should be absent after this issue is fixed. https://github.com/llvm/llvm-project/issues/39494 .
52-
j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 *' (aka 'int (*)(int)') converts to incompatible function type}} */
52+
j = (f10 *)v; /* strict-warning {{cast from 'const int (*)(int)' to 'f10 *' (aka 'int (*)(int)') converts to incompatible function type}} */
5353
}

clang/test/SemaCXX/warn-cast-function-type-strict.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
2-
// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict -verify
1+
// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify=expected,strict
2+
// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict -verify=expected,strict
33
// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
44

55
int x(long);
@@ -38,15 +38,15 @@ int e2func(E2);
3838

3939
void foo() {
4040
a = (f1 *)x;
41-
a = (f1 *)efunc; // expected-warning {{cast from 'int (*)(E)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
42-
a = (f1 *)e2func; // expected-warning {{cast from 'int (*)(E2)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
41+
a = (f1 *)efunc; // strict-warning {{cast from 'int (*)(E)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
42+
a = (f1 *)e2func; // strict-warning {{cast from 'int (*)(E2)' to 'f1 *' (aka 'int (*)(long)') converts to incompatible function type}}
4343
b = (f2 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}
4444
b = reinterpret_cast<f2 *>(x); // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}
45-
c = (f3 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)(...)') converts to incompatible function type}}
45+
c = (f3 *)x; // strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)(...)') converts to incompatible function type}}
4646
d = (f4 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)(...)') converts to incompatible function type}}
47-
e = (f5 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)()') converts to incompatible function type}}
47+
e = (f5 *)x; // strict-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)()') converts to incompatible function type}}
4848
f = (f6 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}}
49-
g = (f7 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}}
49+
g = (f7 *)x; // strict-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}}
5050

5151
mf p1 = (mf)&S::foo; // expected-warning {{cast from 'void (S::*)(int *)' to 'mf' (aka 'void (S::*)(int)') converts to incompatible function type}}
5252

revert_patches.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ ee08d9cba561 AMDGPU: Remove global/flat atomic fadd intrinics (#97051)
8181
Revert: breaks build of hipCUB
8282
commit 55783bd0 [HIP] fix host min/max in header (#82956)
8383
---
84-
Revert :breaks hip catch tests.
85-
1de7e6c8cba2 [clang] move -Wcast-function-type under -Wextra (#77178)
86-
999d4f840777 Split -Wcast-function-type into a separate group (#86131)
87-
---
8884
Revert "Recommit "[InstCombine] Expand `foldSelectICmpAndOr` -> `foldSelectICmpAndBinOp` to work for more binops" (3rd Try)"
8985
Backup fix for SWDEV-454675
9086
This reverts commit 54ec8bcaf85e3a3341c97640331d58e24ac0d2cd.

0 commit comments

Comments
 (0)