[clang] 4be105c - Silence some false positive -Wstrict-prototype warnings
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri May 13 05:32:00 PDT 2022
Author: Aaron Ballman
Date: 2022-05-13T08:31:52-04:00
New Revision: 4be105c98a9c7e083cd878ee1751e11160b97b4a
URL: https://github.com/llvm/llvm-project/commit/4be105c98a9c7e083cd878ee1751e11160b97b4a
DIFF: https://github.com/llvm/llvm-project/commit/4be105c98a9c7e083cd878ee1751e11160b97b4a.diff
LOG: Silence some false positive -Wstrict-prototype warnings
Before issuing the warning about use of a strict prototype, check if
the declarator is required to have a prototype through some other means
determined at parse time.
This silences false positives in OpenCL code (where the functions are
forced to have a prototype) and block literal expressions.
Added:
Modified:
clang/lib/Sema/SemaType.cpp
clang/test/Parser/opencl-kernel.cl
clang/test/Sema/block-return.c
clang/test/Sema/warn-strict-prototypes.m
clang/test/SemaOpenCL/address-spaces.cl
clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
clang/test/SemaOpenCL/func.cl
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 0bb352e914a8c..05a9b56f7d8f6 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5575,8 +5575,10 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
// We suppress the warning when there's no LParen location, as this
// indicates the declaration was an implicit declaration, which gets
- // warned about separately via -Wimplicit-function-declaration.
- if (FTI.NumParams == 0 && !FTI.isVariadic && FTI.getLParenLoc().isValid())
+ // warned about separately via -Wimplicit-function-declaration. We also
+ // suppress the warning when we know the function has a prototype.
+ if (!FTI.hasPrototype && FTI.NumParams == 0 && !FTI.isVariadic &&
+ FTI.getLParenLoc().isValid())
S.Diag(DeclType.Loc, diag::warn_strict_prototypes)
<< IsBlock
<< FixItHint::CreateInsertion(FTI.getRParenLoc(), "void");
diff --git a/clang/test/Parser/opencl-kernel.cl b/clang/test/Parser/opencl-kernel.cl
index e509ed59a9ea3..01c7ed6b5ab69 100644
--- a/clang/test/Parser/opencl-kernel.cl
+++ b/clang/test/Parser/opencl-kernel.cl
@@ -1,9 +1,10 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
-__kernel void test() // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+__kernel void test()
{
}
-kernel void test1() // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+kernel void test1()
{
}
diff --git a/clang/test/Sema/block-return.c b/clang/test/Sema/block-return.c
index 3dcfe2dfea4ee..1ac050bfb4b29 100644
--- a/clang/test/Sema/block-return.c
+++ b/clang/test/Sema/block-return.c
@@ -100,7 +100,7 @@ bptr foo5(int j) {
int (*funcptr3[5])(long);
int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block cannot return array type}} expected-warning {{incompatible pointer to integer conversion}}
int sz9 = sizeof(^int(*())()[3]{ }); // expected-error {{function cannot return array type}}
- // expected-warning at -1 2 {{a function declaration without a prototype is deprecated in all versions of C}}
+ // expected-warning at -1 {{a function declaration without a prototype is deprecated in all versions of C}}
void foo6(void) {
int (^b)(int) __attribute__((noreturn));
diff --git a/clang/test/Sema/warn-strict-prototypes.m b/clang/test/Sema/warn-strict-prototypes.m
index edb8bc6ea388b..38e4ffaba767d 100644
--- a/clang/test/Sema/warn-strict-prototypes.m
+++ b/clang/test/Sema/warn-strict-prototypes.m
@@ -17,7 +17,7 @@ void foo() { // expected-warning {{a function declaration without a prototype is
// FIXME: this should say "a block declaration" instead, but block literal
// expressions do not track their full declarator information, so we don't
// know it's a block when diagnosing.
- void (^block2)(void) = ^void() { // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+ void (^block2)(void) = ^void() {
};
void (^block3)(void) = ^ { // no warning
};
diff --git a/clang/test/SemaOpenCL/address-spaces.cl b/clang/test/SemaOpenCL/address-spaces.cl
index 03f303575964b..41f5a33653254 100644
--- a/clang/test/SemaOpenCL/address-spaces.cl
+++ b/clang/test/SemaOpenCL/address-spaces.cl
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 %s -verify=expected,c -pedantic -fsyntax-only
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify=expected,c -pedantic -fsyntax-only
-// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify=expected,c -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -verify=expected -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify=expected -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify=expected -pedantic -fsyntax-only
// RUN: %clang_cc1 %s -cl-std=clc++1.0 -verify -pedantic -fsyntax-only
// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space -verify -pedantic -fsyntax-only
@@ -251,7 +251,7 @@ void func_multiple_addr(void) {
void func_with_array_param(const unsigned data[16]);
-__kernel void k() { // c-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+__kernel void k() {
unsigned data[16];
func_with_array_param(data);
}
diff --git a/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl b/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
index 7e3bcb5290f18..36b901fc5f29e 100644
--- a/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ b/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -223,22 +223,16 @@ kernel void work_group_size_tests(void) {
kernel void foo(global unsigned int *buf)
{
ndrange_t n;
- // FIXME: this should be diagnosed as a block instead of a function, but
- // block literals don't track the ^ as part of their declarator.
- buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+ buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){});
buf[0] = get_kernel_max_sub_group_size_for_ndrange(0, ^(){}); // expected-error{{illegal call to 'get_kernel_max_sub_group_size_for_ndrange', expected 'ndrange_t' argument type}}
- // expected-warning at -1 {{a function declaration without a prototype is deprecated in all versions of C}}
buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, 1); // expected-error{{illegal call to 'get_kernel_max_sub_group_size_for_ndrange', expected block argument type}}
}
kernel void bar(global unsigned int *buf)
{
__private ndrange_t n;
- // FIXME: this should be diagnosed as a block instead of a function, but
- // block literals don't track the ^ as part of their declarator.
- buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+ buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){});
buf[0] = get_kernel_sub_group_count_for_ndrange(0, ^(){}); // expected-error{{illegal call to 'get_kernel_sub_group_count_for_ndrange', expected 'ndrange_t' argument type}}
- // expected-warning at -1 {{a function declaration without a prototype is deprecated in all versions of C}}
buf[0] = get_kernel_sub_group_count_for_ndrange(n, 1); // expected-error{{illegal call to 'get_kernel_sub_group_count_for_ndrange', expected block argument type}}
}
@@ -247,18 +241,12 @@ kernel void bar(global unsigned int *buf)
kernel void foo1(global unsigned int *buf)
{
ndrange_t n;
- // FIXME: this should be diagnosed as a block instead of a function, but
- // block literals don't track the ^ as part of their declarator.
buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' requires cl_khr_subgroups or __opencl_c_subgroups support}}
- // expected-warning at -1 {{a function declaration without a prototype is deprecated in all versions of C}}
}
kernel void bar1(global unsigned int *buf)
{
ndrange_t n;
- // FIXME: this should be diagnosed as a block instead of a function, but
- // block literals don't track the ^ as part of their declarator.
buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires cl_khr_subgroups or __opencl_c_subgroups support}}
- // expected-warning at -1 {{a function declaration without a prototype is deprecated in all versions of C}}
}
#endif // ifdef cl_khr_subgroups
diff --git a/clang/test/SemaOpenCL/func.cl b/clang/test/SemaOpenCL/func.cl
index b11de505d73da..233e82f244975 100644
--- a/clang/test/SemaOpenCL/func.cl
+++ b/clang/test/SemaOpenCL/func.cl
@@ -43,9 +43,9 @@ void foo(void*);
#endif
// Expect no diagnostics for an empty parameter list.
-void bar(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+void bar();
-void bar() // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
+void bar()
{
// declaring a function pointer is an error
void (*fptr)(int);
More information about the cfe-commits
mailing list