Skip to content

Commit 999d4f8

Browse files
authored
Split -Wcast-function-type into a separate group (#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.
1 parent f5ef9bd commit 999d4f8

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

clang/docs/ReleaseNotes.rst

+19-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,25 @@ Modified Compiler Flags
198198
``-Wreturn-type``, and moved some of the diagnostics previously controlled by
199199
``-Wreturn-type`` under this new flag. Fixes #GH72116.
200200

201-
- Added ``-Wcast-function-type`` as a warning enabled by ``-Wextra``. #GH76872
201+
- Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
202+
warning group. Moved the diagnostic previously controlled by
203+
``-Wcast-function-type`` to the new warning group and added
204+
``-Wcast-function-type-mismatch`` to ``-Wextra``. #GH76872
205+
206+
.. code-block:: c
207+
208+
int x(long);
209+
typedef int (f2)(void*);
210+
typedef int (f3)();
211+
212+
void func(void) {
213+
// Diagnoses under -Wcast-function-type, -Wcast-function-type-mismatch,
214+
// -Wcast-function-type-strict, -Wextra
215+
f2 *b = (f2 *)x;
216+
// Diagnoses under -Wcast-function-type, -Wcast-function-type-strict
217+
f3 *c = (f3 *)x;
218+
}
219+
202220
203221
Removed Compiler Flags
204222
-------------------------

clang/include/clang/Basic/DiagnosticGroups.td

+5-2
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,10 @@ def SelTypeCast : DiagGroup<"cast-of-sel-type">;
573573
def FunctionDefInObjCContainer : DiagGroup<"function-def-in-objc-container">;
574574
def BadFunctionCast : DiagGroup<"bad-function-cast">;
575575
def CastFunctionTypeStrict : DiagGroup<"cast-function-type-strict">;
576-
def CastFunctionType : DiagGroup<"cast-function-type", [CastFunctionTypeStrict]>;
576+
def CastFunctionTypeMismatch : DiagGroup<"cast-function-type-mismatch">;
577+
def CastFunctionType : DiagGroup<"cast-function-type",
578+
[CastFunctionTypeStrict,
579+
CastFunctionTypeMismatch]>;
577580
def ObjCPropertyImpl : DiagGroup<"objc-property-implementation">;
578581
def ObjCPropertyNoAttribute : DiagGroup<"objc-property-no-attribute">;
579582
def ObjCPropertyAssignOnObjectType : DiagGroup<"objc-property-assign-on-object-type">;
@@ -1038,7 +1041,7 @@ def Extra : DiagGroup<"extra", [
10381041
EmptyInitStatement,
10391042
StringConcatation,
10401043
FUseLdPath,
1041-
CastFunctionType,
1044+
CastFunctionTypeMismatch,
10421045
]>;
10431046

10441047
def Most : DiagGroup<"most", [

clang/include/clang/Basic/DiagnosticSemaKinds.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -9058,7 +9058,7 @@ def warn_bad_function_cast : Warning<
90589058
InGroup<BadFunctionCast>, DefaultIgnore;
90599059
def warn_cast_function_type : Warning<
90609060
"cast %diff{from $ to $ |}0,1converts to incompatible function type">,
9061-
InGroup<CastFunctionType>, DefaultIgnore;
9061+
InGroup<CastFunctionTypeMismatch>, DefaultIgnore;
90629062
def warn_cast_function_type_strict : Warning<warn_cast_function_type.Summary>,
90639063
InGroup<CastFunctionTypeStrict>, DefaultIgnore;
90649064
def err_cast_pointer_to_non_pointer_int : Error<

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

+6-6
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]);
@@ -32,13 +32,13 @@ f10 *j;
3232
void foo(void) {
3333
a = (f1 *)x;
3434
b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}} */
35-
c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)()') converts to incompatible function type}} */
35+
c = (f3 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)()') converts to incompatible function type}} */
3636
d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)()') converts to incompatible function type}} */
37-
e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)(void)') converts to incompatible function type}} */
37+
e = (f5 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)(void)') converts to incompatible function type}} */
3838
f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
39-
g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}} */
39+
g = (f7 *)x; /* strict-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}} */
4040
h = (f8 *)t;
4141
i = (f9 *)u;
4242
// 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 .
43-
j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 *' (aka 'int (*)(int)') converts to incompatible function type}} */
43+
j = (f10 *)v; /* strict-warning {{cast from 'const int (*)(int)' to 'f10 *' (aka 'int (*)(int)') converts to incompatible function type}} */
4444
}

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

+5-5
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);
@@ -33,11 +33,11 @@ void foo() {
3333
a = (f1 *)x;
3434
b = (f2 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}
3535
b = reinterpret_cast<f2 *>(x); // expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 'int (*)(void *)') converts to incompatible function type}}
36-
c = (f3 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)(...)') converts to incompatible function type}}
36+
c = (f3 *)x; // strict-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 'int (*)(...)') converts to incompatible function type}}
3737
d = (f4 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 'void (*)(...)') converts to incompatible function type}}
38-
e = (f5 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)()') converts to incompatible function type}}
38+
e = (f5 *)x; // strict-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 'void (*)()') converts to incompatible function type}}
3939
f = (f6 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}}
40-
g = (f7 *)x; // expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}}
40+
g = (f7 *)x; // strict-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 'int (*)(long, ...)') converts to incompatible function type}}
4141

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

0 commit comments

Comments
 (0)