Skip to content

Commit 4be105c

Browse files
committed
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.
1 parent ed1cb01 commit 4be105c

File tree

7 files changed

+17
-26
lines changed

7 files changed

+17
-26
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5575,8 +5575,10 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
55755575
const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
55765576
// We suppress the warning when there's no LParen location, as this
55775577
// indicates the declaration was an implicit declaration, which gets
5578-
// warned about separately via -Wimplicit-function-declaration.
5579-
if (FTI.NumParams == 0 && !FTI.isVariadic && FTI.getLParenLoc().isValid())
5578+
// warned about separately via -Wimplicit-function-declaration. We also
5579+
// suppress the warning when we know the function has a prototype.
5580+
if (!FTI.hasPrototype && FTI.NumParams == 0 && !FTI.isVariadic &&
5581+
FTI.getLParenLoc().isValid())
55805582
S.Diag(DeclType.Loc, diag::warn_strict_prototypes)
55815583
<< IsBlock
55825584
<< FixItHint::CreateInsertion(FTI.getRParenLoc(), "void");

clang/test/Parser/opencl-kernel.cl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
2+
// expected-no-diagnostics
23

3-
__kernel void test() // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
4+
__kernel void test()
45
{
56
}
67

7-
kernel void test1() // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
8+
kernel void test1()
89
{
910
}

clang/test/Sema/block-return.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bptr foo5(int j) {
100100
int (*funcptr3[5])(long);
101101
int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block cannot return array type}} expected-warning {{incompatible pointer to integer conversion}}
102102
int sz9 = sizeof(^int(*())()[3]{ }); // expected-error {{function cannot return array type}}
103-
// expected-warning@-1 2 {{a function declaration without a prototype is deprecated in all versions of C}}
103+
// expected-warning@-1 {{a function declaration without a prototype is deprecated in all versions of C}}
104104

105105
void foo6(void) {
106106
int (^b)(int) __attribute__((noreturn));

clang/test/Sema/warn-strict-prototypes.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void foo() { // expected-warning {{a function declaration without a prototype is
1717
// FIXME: this should say "a block declaration" instead, but block literal
1818
// expressions do not track their full declarator information, so we don't
1919
// know it's a block when diagnosing.
20-
void (^block2)(void) = ^void() { // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
20+
void (^block2)(void) = ^void() {
2121
};
2222
void (^block3)(void) = ^ { // no warning
2323
};

clang/test/SemaOpenCL/address-spaces.cl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 %s -verify=expected,c -pedantic -fsyntax-only
2-
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify=expected,c -pedantic -fsyntax-only
3-
// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify=expected,c -pedantic -fsyntax-only
1+
// RUN: %clang_cc1 %s -verify=expected -pedantic -fsyntax-only
2+
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify=expected -pedantic -fsyntax-only
3+
// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify=expected -pedantic -fsyntax-only
44
// RUN: %clang_cc1 %s -cl-std=clc++1.0 -verify -pedantic -fsyntax-only
55
// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space -verify -pedantic -fsyntax-only
66

@@ -251,7 +251,7 @@ void func_multiple_addr(void) {
251251

252252
void func_with_array_param(const unsigned data[16]);
253253

254-
__kernel void k() { // c-warning {{a function declaration without a prototype is deprecated in all versions of C}}
254+
__kernel void k() {
255255
unsigned data[16];
256256
func_with_array_param(data);
257257
}

clang/test/SemaOpenCL/cl20-device-side-enqueue.cl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,16 @@ kernel void work_group_size_tests(void) {
223223
kernel void foo(global unsigned int *buf)
224224
{
225225
ndrange_t n;
226-
// FIXME: this should be diagnosed as a block instead of a function, but
227-
// block literals don't track the ^ as part of their declarator.
228-
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}}
226+
buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){});
229227
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}}
230-
// expected-warning@-1 {{a function declaration without a prototype is deprecated in all versions of C}}
231228
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}}
232229
}
233230

234231
kernel void bar(global unsigned int *buf)
235232
{
236233
__private ndrange_t n;
237-
// FIXME: this should be diagnosed as a block instead of a function, but
238-
// block literals don't track the ^ as part of their declarator.
239-
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}}
234+
buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){});
240235
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}}
241-
// expected-warning@-1 {{a function declaration without a prototype is deprecated in all versions of C}}
242236
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}}
243237
}
244238

@@ -247,18 +241,12 @@ kernel void bar(global unsigned int *buf)
247241
kernel void foo1(global unsigned int *buf)
248242
{
249243
ndrange_t n;
250-
// FIXME: this should be diagnosed as a block instead of a function, but
251-
// block literals don't track the ^ as part of their declarator.
252244
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}}
253-
// expected-warning@-1 {{a function declaration without a prototype is deprecated in all versions of C}}
254245
}
255246

256247
kernel void bar1(global unsigned int *buf)
257248
{
258249
ndrange_t n;
259-
// FIXME: this should be diagnosed as a block instead of a function, but
260-
// block literals don't track the ^ as part of their declarator.
261250
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}}
262-
// expected-warning@-1 {{a function declaration without a prototype is deprecated in all versions of C}}
263251
}
264252
#endif // ifdef cl_khr_subgroups

clang/test/SemaOpenCL/func.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void foo(void*);
4343
#endif
4444

4545
// Expect no diagnostics for an empty parameter list.
46-
void bar(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
46+
void bar();
4747

48-
void bar() // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
48+
void bar()
4949
{
5050
// declaring a function pointer is an error
5151
void (*fptr)(int);

0 commit comments

Comments
 (0)