From 5d96e0a3a79534f4ab6fb91f4cfa3e01e199f26e Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Fri, 11 Jul 2014 20:53:51 +0000 Subject: [PATCH] Consolidate header inclusion diagnostics Make argument orders match, unify diagnostic IDs and reword the message to be a little less saccharine. llvm-svn: 212845 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 18 ++------- clang/lib/Sema/SemaChecking.cpp | 7 ++-- clang/lib/Sema/SemaDecl.cpp | 44 +++++++++++----------- clang/test/Analysis/dead-stores.c | 2 +- clang/test/Analysis/exercise-ps.c | 2 +- clang/test/Rewriter/finally.m | 2 +- clang/test/Sema/block-return.c | 2 +- clang/test/Sema/implicit-builtin-decl.c | 2 +- clang/test/Sema/warn-absolute-value-header.c | 2 +- clang/test/SemaCXX/warn-absolute-value-header.cpp | 8 ++-- clang/test/SemaObjC/builtin_objc_lib_functions.m | 14 +++---- clang/test/SemaObjC/builtin_objc_nslog.m | 4 +- .../test/SemaObjC/ivar-lookup-resolution-builtin.m | 2 +- 13 files changed, 49 insertions(+), 60 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 5a77459..218b968 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -387,21 +387,11 @@ def note_unreachable_silence : Note< /// Built-in functions. def ext_implicit_lib_function_decl : ExtWarn< "implicitly declaring library function '%0' with type %1">; -def note_please_include_header : Note< - "please include the header <%0> or explicitly provide a " - "declaration for '%1'">; +def note_include_header_or_declare : Note< + "include the header <%0> or explicitly provide a declaration for '%1'">; def note_previous_builtin_declaration : Note<"%0 is a builtin with type %1">; -def warn_implicit_decl_requires_stdio : Warning< - "declaration of built-in function '%0' requires inclusion of the header " - "">, - InGroup; -def warn_implicit_decl_requires_setjmp : Warning< - "declaration of built-in function '%0' requires inclusion of the header " - "">, - InGroup; -def warn_implicit_decl_requires_ucontext : Warning< - "declaration of built-in function '%0' requires inclusion of the header " - "">, +def warn_implicit_decl_requires_sysheader : Warning< + "declaration of built-in function '%1' requires inclusion of the header <%0>">, InGroup; def warn_redecl_library_builtin : Warning< "incompatible redeclaration of library function %0">, diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index f7d5623..976f3a6 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3867,7 +3867,8 @@ static void emitReplacement(Sema &S, SourceLocation Loc, SourceRange Range, if (!EmitHeaderHint) return; - S.Diag(Loc, diag::note_please_include_header) << HeaderName << FunctionName; + S.Diag(Loc, diag::note_include_header_or_declare) << HeaderName + << FunctionName; } static bool IsFunctionStdAbs(const FunctionDecl *FDecl) { @@ -3907,8 +3908,8 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, QualType ArgType = Call->getArg(0)->IgnoreParenImpCasts()->getType(); QualType ParamType = Call->getArg(0)->getType(); - // Unsigned types can not be negative. Suggest to drop the absolute value - // function. + // Unsigned types cannot be negative. Suggest removing the absolute value + // function call. if (ArgType->isUnsignedIntegerType()) { const char *FunctionName = IsStdAbs ? "std::abs" : Context.BuiltinInfo.GetName(AbsKind); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 253ec39..042fe26 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1602,6 +1602,20 @@ static void LookupPredefedObjCSuperType(Sema &ThisSema, Scope *S, Context.setObjCSuperType(Context.getTagDeclType(TD)); } +static StringRef getHeaderName(ASTContext::GetBuiltinTypeError Error) { + switch (Error) { + case ASTContext::GE_None: + return ""; + case ASTContext::GE_Missing_stdio: + return "stdio.h"; + case ASTContext::GE_Missing_setjmp: + return "setjmp.h"; + case ASTContext::GE_Missing_ucontext: + return "ucontext.h"; + } + llvm_unreachable("unhandled error kind"); +} + /// LazilyCreateBuiltin - The specified Builtin-ID was first used at /// file scope. lazily create a decl for it. ForRedeclaration is true /// if we're creating this built-in in anticipation of redeclaring the @@ -1615,27 +1629,11 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid, ASTContext::GetBuiltinTypeError Error; QualType R = Context.GetBuiltinType(BID, Error); - switch (Error) { - case ASTContext::GE_None: - // Okay - break; - - case ASTContext::GE_Missing_stdio: - if (ForRedeclaration) - Diag(Loc, diag::warn_implicit_decl_requires_stdio) - << Context.BuiltinInfo.GetName(BID); - return nullptr; - - case ASTContext::GE_Missing_setjmp: - if (ForRedeclaration) - Diag(Loc, diag::warn_implicit_decl_requires_setjmp) - << Context.BuiltinInfo.GetName(BID); - return nullptr; - - case ASTContext::GE_Missing_ucontext: + if (Error) { if (ForRedeclaration) - Diag(Loc, diag::warn_implicit_decl_requires_ucontext) - << Context.BuiltinInfo.GetName(BID); + Diag(Loc, diag::warn_implicit_decl_requires_sysheader) + << getHeaderName(Error) + << Context.BuiltinInfo.GetName(BID); return nullptr; } @@ -1645,9 +1643,9 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid, << R; if (Context.BuiltinInfo.getHeaderName(BID) && !Diags.isIgnored(diag::ext_implicit_lib_function_decl, Loc)) - Diag(Loc, diag::note_please_include_header) - << Context.BuiltinInfo.getHeaderName(BID) - << Context.BuiltinInfo.GetName(BID); + Diag(Loc, diag::note_include_header_or_declare) + << Context.BuiltinInfo.getHeaderName(BID) + << Context.BuiltinInfo.GetName(BID); } DeclContext *Parent = Context.getTranslationUnitDecl(); diff --git a/clang/test/Analysis/dead-stores.c b/clang/test/Analysis/dead-stores.c index 5b2c2a1..da8e8bd 100644 --- a/clang/test/Analysis/dead-stores.c +++ b/clang/test/Analysis/dead-stores.c @@ -11,7 +11,7 @@ void f2(void *b) { char *c = (char*)b; // no-warning char *d = b+1; // expected-warning {{never read}} expected-warning{{unused variable 'd'}} printf("%s", c); // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \ - // expected-note{{please include the header or explicitly provide a declaration for 'printf'}} + // expected-note{{include the header or explicitly provide a declaration for 'printf'}} } int f(); diff --git a/clang/test/Analysis/exercise-ps.c b/clang/test/Analysis/exercise-ps.c index 675dd4e..03b6874 100644 --- a/clang/test/Analysis/exercise-ps.c +++ b/clang/test/Analysis/exercise-ps.c @@ -19,5 +19,5 @@ static void f2(void *buf) { F12_typedef* x; x = f2_helper(); memcpy((&x[1]), (buf), 1); // expected-warning{{implicitly declaring library function 'memcpy' with type 'void *(void *, const void *}} \ - // expected-note{{please include the header or explicitly provide a declaration for 'memcpy'}} + // expected-note{{include the header or explicitly provide a declaration for 'memcpy'}} } diff --git a/clang/test/Rewriter/finally.m b/clang/test/Rewriter/finally.m index f46b4b0..e60ba9e 100644 --- a/clang/test/Rewriter/finally.m +++ b/clang/test/Rewriter/finally.m @@ -3,7 +3,7 @@ int main() { @try { printf("executing try"); // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \ - // expected-note{{please include the header or explicitly provide a declaration for 'printf'}} + // expected-note{{include the header or explicitly provide a declaration for 'printf'}} return(0); // expected-warning{{rewriter doesn't support user-specified control flow semantics for @try/@finally (code may not execute properly)}} } @finally { printf("executing finally"); diff --git a/clang/test/Sema/block-return.c b/clang/test/Sema/block-return.c index 6b4d998..08e9249 100644 --- a/clang/test/Sema/block-return.c +++ b/clang/test/Sema/block-return.c @@ -82,7 +82,7 @@ void foo4() { int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (*)(const char *)' with an expression of type 'int (char *)'}} int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \ - // expected-note{{please include the header or explicitly provide a declaration for 'printf'}} + // expected-note{{include the header or explicitly provide a declaration for 'printf'}} } typedef void (^bptr)(void); diff --git a/clang/test/Sema/implicit-builtin-decl.c b/clang/test/Sema/implicit-builtin-decl.c index bfc1907..3c2ff94 100644 --- a/clang/test/Sema/implicit-builtin-decl.c +++ b/clang/test/Sema/implicit-builtin-decl.c @@ -3,7 +3,7 @@ void f() { int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \ - // expected-note{{please include the header or explicitly provide a declaration for 'malloc'}} \ + // expected-note{{include the header or explicitly provide a declaration for 'malloc'}} \ // expected-note{{'malloc' is a builtin with type 'void *}} } diff --git a/clang/test/Sema/warn-absolute-value-header.c b/clang/test/Sema/warn-absolute-value-header.c index e3bf9ee..0c7c3a8 100644 --- a/clang/test/Sema/warn-absolute-value-header.c +++ b/clang/test/Sema/warn-absolute-value-header.c @@ -31,6 +31,6 @@ void test_int(int i, unsigned u, long long ll, float f, double d) { (void)abs(d); // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} // expected-note@-2{{use function 'fabs' instead}} - // expected-note@-3{{please include the header or explicitly provide a declaration for 'fabs'}} + // expected-note@-3{{include the header or explicitly provide a declaration for 'fabs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs" } diff --git a/clang/test/SemaCXX/warn-absolute-value-header.cpp b/clang/test/SemaCXX/warn-absolute-value-header.cpp index 96e6a31..925be38 100644 --- a/clang/test/SemaCXX/warn-absolute-value-header.cpp +++ b/clang/test/SemaCXX/warn-absolute-value-header.cpp @@ -16,25 +16,25 @@ void test(long long ll, double d, int i, float f) { (void)abs(d); // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} // expected-note@-2{{use function 'std::abs' instead}} - // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // expected-note@-3{{include the header or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs" (void)fabsf(d); // expected-warning@-1{{absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value}} // expected-note@-2{{use function 'std::abs' instead}} - // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // expected-note@-3{{include the header or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs" // Suggest including cstdlib (void)abs(ll); // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}} // expected-note@-2{{use function 'std::abs' instead}} - // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // expected-note@-3{{include the header or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs" (void)fabsf(ll); // expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}} // expected-note@-2{{use function 'std::abs' instead}} - // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // expected-note@-3{{include the header or explicitly provide a declaration for 'std::abs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs" // Proper function already called, no warnings. diff --git a/clang/test/SemaObjC/builtin_objc_lib_functions.m b/clang/test/SemaObjC/builtin_objc_lib_functions.m index d8713dd..2496bf2 100644 --- a/clang/test/SemaObjC/builtin_objc_lib_functions.m +++ b/clang/test/SemaObjC/builtin_objc_lib_functions.m @@ -1,29 +1,29 @@ // RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify // rdar://8592641 Class f0() { return objc_getClass("a"); } // expected-warning {{implicitly declaring library function 'objc_getClass' with type 'id (const char *)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'objc_getClass'}} + // expected-note {{include the header or explicitly provide a declaration for 'objc_getClass'}} // rdar://8735023 Class f1() { return objc_getMetaClass("a"); } // expected-warning {{implicitly declaring library function 'objc_getMetaClass' with type 'id (const char *)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'objc_getMetaClass'}} + // expected-note {{include the header or explicitly provide a declaration for 'objc_getMetaClass'}} void f2(id val) { objc_enumerationMutation(val); } // expected-warning {{implicitly declaring library function 'objc_enumerationMutation' with type 'void (id)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'objc_enumerationMutation'}} + // expected-note {{include the header or explicitly provide a declaration for 'objc_enumerationMutation'}} long double f3(id self, SEL op) { return objc_msgSend_fpret(self, op); } // expected-warning {{implicitly declaring library function 'objc_msgSend_fpret' with type 'long double (id, SEL, ...)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'objc_msgSend_fpret'}} + // expected-note {{include the header or explicitly provide a declaration for 'objc_msgSend_fpret'}} id f4(struct objc_super *super, SEL op) { // expected-warning {{declaration of 'struct objc_super' will not be visible outside of this function}} return objc_msgSendSuper(super, op); // expected-warning {{implicitly declaring library function 'objc_msgSendSuper' with type 'id (struct objc_super *, SEL, ...)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'objc_msgSendSuper'}} + // expected-note {{include the header or explicitly provide a declaration for 'objc_msgSendSuper'}} } id f5(id val, id *dest) { return objc_assign_strongCast(val, dest); // expected-warning {{implicitly declaring library function 'objc_assign_strongCast' with type 'id (id, id *)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'objc_assign_strongCast'}} + // expected-note {{include the header or explicitly provide a declaration for 'objc_assign_strongCast'}} } int f6(Class exceptionClass, id exception) { return objc_exception_match(exceptionClass, exception); // expected-warning {{implicitly declaring library function 'objc_exception_match' with type 'int (id, id)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'objc_exception_match'}} + // expected-note {{include the header or explicitly provide a declaration for 'objc_exception_match'}} } diff --git a/clang/test/SemaObjC/builtin_objc_nslog.m b/clang/test/SemaObjC/builtin_objc_nslog.m index c940b16..cc6f194 100644 --- a/clang/test/SemaObjC/builtin_objc_nslog.m +++ b/clang/test/SemaObjC/builtin_objc_nslog.m @@ -4,10 +4,10 @@ void f1(id arg) { NSLog(@"%@", arg); // expected-warning {{implicitly declaring library function 'NSLog' with type 'void (id, ...)'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'NSLog'}} + // expected-note {{include the header or explicitly provide a declaration for 'NSLog'}} } void f2(id str, va_list args) { NSLogv(@"%@", args); // expected-warning {{implicitly declaring library function 'NSLogv' with type }} \ - // expected-note {{please include the header or explicitly provide a declaration for 'NSLogv'}} + // expected-note {{include the header or explicitly provide a declaration for 'NSLogv'}} } diff --git a/clang/test/SemaObjC/ivar-lookup-resolution-builtin.m b/clang/test/SemaObjC/ivar-lookup-resolution-builtin.m index dd11b51..94ed325 100644 --- a/clang/test/SemaObjC/ivar-lookup-resolution-builtin.m +++ b/clang/test/SemaObjC/ivar-lookup-resolution-builtin.m @@ -29,7 +29,7 @@ - (int) InstMethod { return index; // expected-warning {{implicitly declaring library function 'index'}} \ - // expected-note {{please include the header or explicitly provide a declaration for 'index'}} \ + // expected-note {{include the header or explicitly provide a declaration for 'index'}} \ // expected-warning {{incompatible pointer to integer conversion returning}} } + (int) ClassMethod -- 2.7.4