delcypher created this revision. delcypher added reviewers: arphaman, rapidsna, fcloutier, NoQ. delcypher requested review of this revision. Herald added a project: clang.
This patch enables the `-Wstrict-calls-without-prototype` warning by default and fixes the existing clang test suite to pass. This patch is considered work-in-progress because the patch it is based on is not finalized. It is also unclear at this point whether this warning should actually be enabled by default. So this patch serves to illustrate the changes that would need to be made to have the warning on by default. rdar://87118271 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D116636 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/test/Analysis/casts.c clang/test/Analysis/inline.c clang/test/Analysis/misc-ps-region-store.m clang/test/Analysis/misc-ps.m clang/test/Analysis/null-deref-ps.c clang/test/Analysis/solver-sym-simplification-adjustment.c clang/test/Analysis/solver-sym-simplification-concreteint.c clang/test/CodeGen/functions.c clang/test/Sema/arg-duplicate.c clang/test/Sema/block-misc.c clang/test/Sema/extern-redecl.c clang/test/Sema/function-redecl.c clang/test/Sema/function.c clang/test/Sema/knr-def-call.c clang/test/Sema/knr-variadic-def.c clang/test/Sema/merge-decls.c clang/test/Sema/sizeless-1.c clang/test/Sema/unused-expr.c clang/test/SemaObjC/nonnull.m clang/test/SemaObjC/protocol-archane.m
Index: clang/test/SemaObjC/protocol-archane.m =================================================================== --- clang/test/SemaObjC/protocol-archane.m +++ clang/test/SemaObjC/protocol-archane.m @@ -5,6 +5,8 @@ - (void) bar; @end +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wstrict-calls-without-prototype" void bar(); void foo(id x) { bar((short<SomeProtocol>)x); // expected-error {{expected ')'}} expected-note {{to match this '('}} @@ -12,6 +14,7 @@ [(<SomeProtocol>)x bar]; // expected-warning {{protocol has no object type specified; defaults to qualified 'id'}} } +#pragma clang diagnostic pop @protocol MyProtocol - (void)doSomething; Index: clang/test/SemaObjC/nonnull.m =================================================================== --- clang/test/SemaObjC/nonnull.m +++ clang/test/SemaObjC/nonnull.m @@ -23,8 +23,8 @@ extern void func4 (void (^block1)(), void (^block2)()) __attribute__((nonnull(1))) __attribute__((nonnull(2))); -void func6(); -void func7(); +void func6(NSObject *); +void func7(NSObject *); void foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)()) @@ -63,7 +63,7 @@ __attribute__((nonnull)) void _dispatch_queue_push_list(dispatch_object_t _head); // no warning -void func6(dispatch_object_t _head) { +void func8(dispatch_object_t _head) { _dispatch_queue_push_list(0); // expected-warning {{null passed to a callee that requires a non-null argument}} _dispatch_queue_push_list(_head._do); // no warning } Index: clang/test/Sema/unused-expr.c =================================================================== --- clang/test/Sema/unused-expr.c +++ clang/test/Sema/unused-expr.c @@ -79,10 +79,9 @@ t5f(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} } - int fn1() __attribute__ ((warn_unused_result)); -int fn2() __attribute__ ((pure)); -int fn3() __attribute__ ((__const)); +int fn2(int, int) __attribute__((pure)); +int fn3(int) __attribute__((__const)); // rdar://6587766 int t6() { if (fn1() < 0 || fn2(2,1) < 0 || fn3(2) < 0) // no warnings @@ -129,18 +128,18 @@ #define NOP(a) (a) #define M1(a, b) (long)foo((a), (b)) #define M2 (long)0; -#define M3(a) (t3(a), fn2()) +#define M3(a) (t3(a), fn2(0, 1)) #define M4(a, b) (foo((a), (b)) ? 0 : t3(a), 1) #define M5(a, b) (foo((a), (b)), 1) #define M6() fn1() -#define M7() fn2() +#define M7() fn2(0, 1) void t11(int i, int j) { M1(i, j); // no warning NOP((long)foo(i, j)); // expected-warning {{expression result unused}} M2; // no warning NOP((long)0); // expected-warning {{expression result unused}} M3(i); // no warning - NOP((t3(i), fn2())); // expected-warning {{ignoring return value}} + NOP((t3(i), fn2(0, 0))); // expected-warning {{ignoring return value}} M4(i, j); // no warning NOP((foo(i, j) ? 0 : t3(i), 1)); // expected-warning {{expression result unused}} M5(i, j); // no warning Index: clang/test/Sema/sizeless-1.c =================================================================== --- clang/test/Sema/sizeless-1.c +++ clang/test/Sema/sizeless-1.c @@ -42,7 +42,7 @@ void __attribute__((overloadable)) overf16(svint16_t); // expected-note + {{not viable}} void __attribute__((overloadable)) overf16(int); // expected-note + {{not viable}} -void noproto(); +void noproto(); // expected-note{{'noproto' declared here}} void varargs(int, ...); void unused() { @@ -174,7 +174,7 @@ overf16(local_int8); // expected-error {{no matching function}} overf16(local_int16); - noproto(local_int8); + noproto(local_int8); // expected-warning{{calling function 'noproto' with arguments when function has no prototype}} varargs(1, local_int8, local_int16); global_int8_ptr++; // expected-error {{arithmetic on a pointer to sizeless type}} Index: clang/test/Sema/merge-decls.c =================================================================== --- clang/test/Sema/merge-decls.c +++ clang/test/Sema/merge-decls.c @@ -76,6 +76,9 @@ return sizeof(*x); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}} } +// FIXME(dliew): shouldn't warn here +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wstrict-calls-without-prototype" void test6_f(int (*a)[11]); void test6_f(a) int (*a)[]; @@ -84,6 +87,7 @@ int arr[10]; test6_f(&arr); // expected-warning {{incompatible pointer types passing 'int (*)[10]' to parameter of type 'int (*)[11]}} } +#pragma clang diagnostic pop void test7_f(int (*)[10]); void test7_f(int (*)[]); // expected-note {{passing argument to parameter here}} Index: clang/test/Sema/knr-variadic-def.c =================================================================== --- clang/test/Sema/knr-variadic-def.c +++ clang/test/Sema/knr-variadic-def.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-strict-calls-without-prototype %s // expected-no-diagnostics // PR4287 Index: clang/test/Sema/knr-def-call.c =================================================================== --- clang/test/Sema/knr-def-call.c +++ clang/test/Sema/knr-def-call.c @@ -3,11 +3,15 @@ // C DR #316, PR 3626. void f0(a, b, c, d) int a,b,c,d; {} void t0(void) { + // expected-warning@+2{{calling function 'f0' with arguments when function has no prototype}} + // expected-note@-3{{'f0' declared here}} f0(1); // expected-warning{{too few arguments}} } void f1(a, b) int a, b; {} void t1(void) { + // expected-warning@+2{{calling function 'f1' with arguments when function has no prototype}} + // expected-note@-3{{'f1' declared here}} f1(1, 2, 3); // expected-warning{{too many arguments}} } @@ -36,6 +40,9 @@ } void use_proto() { + // FIXME(dliew): Perhaps we shouldn't warn about this? + // expected-warning@+2{{calling function 'proto' with arguments when function has no prototype}} + // expected-note@-8{{'proto' declared here}} proto(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}} (&proto)(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}} } Index: clang/test/Sema/function.c =================================================================== --- clang/test/Sema/function.c +++ clang/test/Sema/function.c @@ -27,8 +27,11 @@ // PR2042 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wstrict-calls-without-prototype" void t10(){} void t11(){t10(1);} // expected-warning{{too many arguments}} +#pragma clang diagnostic pop // PR3208 void t12(int) {} // c2x-warning{{omitting the parameter name in a function definition is a C2x extension}} Index: clang/test/Sema/function-redecl.c =================================================================== --- clang/test/Sema/function-redecl.c +++ clang/test/Sema/function-redecl.c @@ -120,7 +120,8 @@ a x; a2 x2; // expected-note{{passing argument to parameter here}} void test_x() { - x(5); + x(5); // expected-warning{{calling function 'x' with arguments when function has no prototype}} + // expected-note@-4{{'x' declared here}} x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'}} } Index: clang/test/Sema/extern-redecl.c =================================================================== --- clang/test/Sema/extern-redecl.c +++ clang/test/Sema/extern-redecl.c @@ -81,8 +81,8 @@ void test6_fn1(); void test6_fn2(); test6_fn1(1.2); // expected-error {{passing 'double' to parameter of incompatible type 'int *'}} - // FIXME: This is valid, but we should warn on it. - test6_fn2(1.2); + test6_fn2(1.2); // expected-warning{{calling function 'test6_fn2' with arguments when function has no prototype}} + // expected-note@-3{{'test6_fn2' declared here}} } } } Index: clang/test/Sema/block-misc.c =================================================================== --- clang/test/Sema/block-misc.c +++ clang/test/Sema/block-misc.c @@ -157,7 +157,8 @@ __block int (*ap)[size]; // expected-error {{__block attribute not allowed on declaration with a variably modified type}} } -void f(); +void f(void (*)(int)); +void f2(void (^)(int)); void test17() { void (^bp)(int); @@ -167,7 +168,7 @@ f(1 ? bp : vp); f(1 ? vp : bp); - f(1 ? bp : bp1); + f2(1 ? bp : bp1); (void)(bp > rp); // expected-error {{invalid operands}} (void)(bp > 0); // expected-error {{invalid operands}} (void)(bp > bp); // expected-error {{invalid operands}} Index: clang/test/Sema/arg-duplicate.c =================================================================== --- clang/test/Sema/arg-duplicate.c +++ clang/test/Sema/arg-duplicate.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-strict-calls-without-prototype %s int f3(y, x, x) // expected-error {{redefinition of parameter}} Index: clang/test/CodeGen/functions.c =================================================================== --- clang/test/CodeGen/functions.c +++ clang/test/CodeGen/functions.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -triple i386-unknown-unknown -emit-llvm -o - -verify | FileCheck %s +// RUN: %clang_cc1 %s -triple i386-unknown-unknown -emit-llvm -o - -verify -Wno-strict-calls-without-prototype | FileCheck %s int g(); Index: clang/test/Analysis/solver-sym-simplification-concreteint.c =================================================================== --- clang/test/Analysis/solver-sym-simplification-concreteint.c +++ clang/test/Analysis/solver-sym-simplification-concreteint.c @@ -5,7 +5,7 @@ // RUN: -verify void clang_analyzer_warnIfReached(); -void clang_analyzer_eval(); +void clang_analyzer_eval(int); void test_simplification_to_concrete_int_infeasible(int b, int c) { if (c + b != 0) // c + b == 0 Index: clang/test/Analysis/solver-sym-simplification-adjustment.c =================================================================== --- clang/test/Analysis/solver-sym-simplification-adjustment.c +++ clang/test/Analysis/solver-sym-simplification-adjustment.c @@ -5,7 +5,7 @@ // RUN: -verify void clang_analyzer_warnIfReached(); -void clang_analyzer_eval(); +void clang_analyzer_eval(int); void test_simplification_adjustment_concrete_int(int b, int c) { if (b < 0 || b > 1) // b: [0,1] Index: clang/test/Analysis/null-deref-ps.c =================================================================== --- clang/test/Analysis/null-deref-ps.c +++ clang/test/Analysis/null-deref-ps.c @@ -188,7 +188,7 @@ *q = 1; // no-warning } -int* qux(); +int *qux(unsigned); int f9(unsigned len) { assert (len != 0); Index: clang/test/Analysis/misc-ps.m =================================================================== --- clang/test/Analysis/misc-ps.m +++ clang/test/Analysis/misc-ps.m @@ -461,7 +461,7 @@ (void (^)(void *))test_block_cast_aux(); // expected-warning{{expression result unused}} } -int OSAtomicCompareAndSwap32Barrier(); +int OSAtomicCompareAndSwap32Barrier(int, int, int *); // Test comparison of 'id' instance variable to a null void* constant after // performing an OSAtomicCompareAndSwap32Barrier. @@ -507,7 +507,7 @@ return; } -int ivar_getOffset(); +int ivar_getOffset(Ivar); // Reduced from a crash involving the cast of an Objective-C symbolic region to // 'char *' Index: clang/test/Analysis/misc-ps-region-store.m =================================================================== --- clang/test/Analysis/misc-ps-region-store.m +++ clang/test/Analysis/misc-ps-region-store.m @@ -294,7 +294,7 @@ struct ArrayWrapper { unsigned char y[16]; }; struct WrappedStruct { unsigned z; }; -void test_handle_array_wrapper_helper(); +void test_handle_array_wrapper_helper(struct ArrayWrapper *); int test_handle_array_wrapper() { struct ArrayWrapper x; Index: clang/test/Analysis/inline.c =================================================================== --- clang/test/Analysis/inline.c +++ clang/test/Analysis/inline.c @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -Wno-strict-calls-without-prototype %s void clang_analyzer_eval(int); void clang_analyzer_checkInlined(int); Index: clang/test/Analysis/casts.c =================================================================== --- clang/test/Analysis/casts.c +++ clang/test/Analysis/casts.c @@ -16,7 +16,7 @@ struct sockaddr { sa_family_t sa_family; }; struct sockaddr_storage {}; -void getsockname(); +void getsockname(int, struct sockaddr *, socklen_t *); #ifndef EAGERLY_ASSUME Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5527,7 +5527,7 @@ InGroup<DiagGroup<"strict-prototypes">>, DefaultIgnore; def warn_call_function_without_prototype : Warning< "calling function %0 with arguments when function has no prototype">, InGroup< - DiagGroup<"strict-calls-without-prototype">>, DefaultIgnore; + DiagGroup<"strict-calls-without-prototype">>; def warn_missing_variable_declarations : Warning< "no previous extern declaration for non-static variable %0">, InGroup<DiagGroup<"missing-variable-declarations">>, DefaultIgnore;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits