]> granicus.if.org Git - clang/commitdiff
Consolidate header inclusion diagnostics
authorAlp Toker <alp@nuanti.com>
Fri, 11 Jul 2014 20:53:51 +0000 (20:53 +0000)
committerAlp Toker <alp@nuanti.com>
Fri, 11 Jul 2014 20:53:51 +0000 (20:53 +0000)
Make argument orders match, unify diagnostic IDs and reword the message to be a
little less saccharine.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212845 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaChecking.cpp
lib/Sema/SemaDecl.cpp
test/Analysis/dead-stores.c
test/Analysis/exercise-ps.c
test/Rewriter/finally.m
test/Sema/block-return.c
test/Sema/implicit-builtin-decl.c
test/Sema/warn-absolute-value-header.c
test/SemaCXX/warn-absolute-value-header.cpp
test/SemaObjC/builtin_objc_lib_functions.m
test/SemaObjC/builtin_objc_nslog.m
test/SemaObjC/ivar-lookup-resolution-builtin.m

index 5a77459d797abed6ee829b4eca1651cb714abd53..218b968579a6b38cd5ee07238bbe0023b133f2f1 100644 (file)
@@ -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 "
-  "<stdio.h>">,
-  InGroup<BuiltinRequiresHeader>;
-def warn_implicit_decl_requires_setjmp : Warning<
-  "declaration of built-in function '%0' requires inclusion of the header "
-  "<setjmp.h>">,
-  InGroup<BuiltinRequiresHeader>;
-def warn_implicit_decl_requires_ucontext : Warning<
-  "declaration of built-in function '%0' requires inclusion of the header "
-  "<ucontext.h>">,
+def warn_implicit_decl_requires_sysheader : Warning<
+  "declaration of built-in function '%1' requires inclusion of the header <%0>">,
   InGroup<BuiltinRequiresHeader>;
 def warn_redecl_library_builtin : Warning<
   "incompatible redeclaration of library function %0">,
index f7d562318850230a8db6214e53c47777eb407882..976f3a696dfb3b2d89febcb9f8ace1b73fce075a 100644 (file)
@@ -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);
index 253ec39a8443ad76b1f3443e9eb2855736f03cac..042fe2645262453c9e7e0cb95196395250502093 100644 (file)
@@ -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();
index 5b2c2a101bc1b766c31fb5cf0d8eb35c2bb5c068..da8e8bdb70344529c0cfae27a9522a6c4c23faf4 100644 (file)
@@ -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 <stdio.h> or explicitly provide a declaration for 'printf'}}
+ // expected-note{{include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
 }
 
 int f();
index 675dd4ebf61227c88b0f105c64fe0d81ae01cb7f..03b6874b68ee37d051dd8bb72142bb52eeb3b8c5 100644 (file)
@@ -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 <string.h> or explicitly provide a declaration for 'memcpy'}}
+  // expected-note{{include the header <string.h> or explicitly provide a declaration for 'memcpy'}}
 }
index f46b4b01a5ff74a6a04970e3682d90ca2835f166..e60ba9ec852633ff0afaa1dec45d2bd235bd59f1 100644 (file)
@@ -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 <stdio.h> or explicitly provide a declaration for 'printf'}}
+        // expected-note{{include the header <stdio.h> 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");
index 6b4d99830c6d68d148ffe8528eefdec09ee09412..08e9249847cba97b3520f342624aa5fcfdead9d9 100644 (file)
@@ -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 <stdio.h> or explicitly provide a declaration for 'printf'}}
+  // expected-note{{include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
 }
 
 typedef void (^bptr)(void);
index bfc1907e39a69edecdda46aff6f86039a7119163..3c2ff94984c0ff553ecebbd22fad7ce2cb6ff3c8 100644 (file)
@@ -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 <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
+  // expected-note{{include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
   // expected-note{{'malloc' is a builtin with type 'void *}}
 }
 
index e3bf9ee1e65dbf98b7742ae0b1a756b69f623839..0c7c3a8b9003ba366ce2ba7a60877a23ee4a8c89 100644 (file)
@@ -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 <math.h> or explicitly provide a declaration for 'fabs'}}
+  // expected-note@-3{{include the header <math.h> or explicitly provide a declaration for 'fabs'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs"
 }
index 96e6a315402153b00ceebfed1c270daacb02fd58..925be38ace08783db605511ee07965cb9c34a38f 100644 (file)
@@ -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 <cmath> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note@-3{{include the header <cmath> 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 <cmath> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note@-3{{include the header <cmath> 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 <cstdlib> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note@-3{{include the header <cstdlib> 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 <cstdlib> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note@-3{{include the header <cstdlib> 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.
index d8713ddfb416e3abdb633168137de1a2a9703e4d..2496bf2b1cf7f131e2fd4d93cafaac572494c353 100644 (file)
@@ -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 <objc/runtime.h> or explicitly provide a declaration for 'objc_getClass'}}
+                                         // expected-note {{include the header <objc/runtime.h> 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 <objc/runtime.h> or explicitly provide a declaration for 'objc_getMetaClass'}}
+                                         // expected-note {{include the header <objc/runtime.h> 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 <objc/runtime.h> or explicitly provide a declaration for 'objc_enumerationMutation'}}
+                                                  // expected-note {{include the header <objc/runtime.h> 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 <objc/message.h> or explicitly provide a declaration for 'objc_msgSend_fpret'}}
+    // expected-note {{include the header <objc/message.h> 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 <objc/message.h> or explicitly provide a declaration for 'objc_msgSendSuper'}}
+                                       // expected-note {{include the header <objc/message.h> 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 <objc/objc-auto.h> or explicitly provide a declaration for 'objc_assign_strongCast'}}
+                                           // expected-note {{include the header <objc/objc-auto.h> 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 <objc/objc-exception.h> or explicitly provide a declaration for 'objc_exception_match'}}
+                                                         // expected-note {{include the header <objc/objc-exception.h> or explicitly provide a declaration for 'objc_exception_match'}}
 }
index c940b16cdc3a0bfa2d0476e90c903040ea85a574..cc6f194c898de68b89c85a3bfb7b0c15f40d2808 100644 (file)
@@ -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 <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLog'}}
+  // expected-note {{include the header <Foundation/NSObjCRuntime.h> 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 <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLogv'}}
+  // expected-note {{include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLogv'}}
 }
index dd11b51459d7adeb93919fe68df7605da84f4d2b..94ed3256e8dff01ed8d71cc9997d63f95b077d0d 100644 (file)
@@ -29,7 +29,7 @@
 - (int) InstMethod
 {
   return index;        // expected-warning {{implicitly declaring library function 'index'}}   \
-                // expected-note {{please include the header <strings.h> or explicitly provide a declaration for 'index'}} \
+                // expected-note {{include the header <strings.h> or explicitly provide a declaration for 'index'}} \
                 // expected-warning {{incompatible pointer to integer conversion returning}}
 }
 + (int) ClassMethod