r212845 - Consolidate header inclusion diagnostics

Alp Toker alp at nuanti.com
Fri Jul 11 13:53:51 PDT 2014


Author: alp
Date: Fri Jul 11 15:53:51 2014
New Revision: 212845

URL: http://llvm.org/viewvc/llvm-project?rev=212845&view=rev
Log:
Consolidate header inclusion diagnostics

Make argument orders match, unify diagnostic IDs and reword the message to be a
little less saccharine.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 11 15:53:51 2014
@@ -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">,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Jul 11 15:53:51 2014
@@ -3867,7 +3867,8 @@ static void emitReplacement(Sema &S, Sou
   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(co
   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);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jul 11 15:53:51 2014
@@ -1602,6 +1602,20 @@ static void LookupPredefedObjCSuperType(
       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(Ide
 
   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(Ide
       << 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();

Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Fri Jul 11 15:53:51 2014
@@ -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();

Modified: cfe/trunk/test/Analysis/exercise-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exercise-ps.c?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exercise-ps.c (original)
+++ cfe/trunk/test/Analysis/exercise-ps.c Fri Jul 11 15:53:51 2014
@@ -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'}}
 }

Modified: cfe/trunk/test/Rewriter/finally.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/finally.m?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/finally.m (original)
+++ cfe/trunk/test/Rewriter/finally.m Fri Jul 11 15:53:51 2014
@@ -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");

Modified: cfe/trunk/test/Sema/block-return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-return.c?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-return.c (original)
+++ cfe/trunk/test/Sema/block-return.c Fri Jul 11 15:53:51 2014
@@ -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);

Modified: cfe/trunk/test/Sema/implicit-builtin-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-builtin-decl.c?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/Sema/implicit-builtin-decl.c (original)
+++ cfe/trunk/test/Sema/implicit-builtin-decl.c Fri Jul 11 15:53:51 2014
@@ -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 *}}
 }
 

Modified: cfe/trunk/test/Sema/warn-absolute-value-header.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-absolute-value-header.c?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-absolute-value-header.c (original)
+++ cfe/trunk/test/Sema/warn-absolute-value-header.c Fri Jul 11 15:53:51 2014
@@ -31,6 +31,6 @@ void test_int(int i, unsigned u, long lo
   (void)abs(d);
   // expected-warning at -1{{using integer absolute value function 'abs' when argument is of floating point type}}
   // expected-note at -2{{use function 'fabs' instead}}
-  // expected-note at -3{{please include the header <math.h> or explicitly provide a declaration for 'fabs'}}
+  // expected-note at -3{{include the header <math.h> or explicitly provide a declaration for 'fabs'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs"
 }

Modified: cfe/trunk/test/SemaCXX/warn-absolute-value-header.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-absolute-value-header.cpp?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-absolute-value-header.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-absolute-value-header.cpp Fri Jul 11 15:53:51 2014
@@ -16,25 +16,25 @@ void test(long long ll, double d, int i,
   (void)abs(d);
   // expected-warning at -1{{using integer absolute value function 'abs' when argument is of floating point type}}
   // expected-note at -2{{use function 'std::abs' instead}}
-  // expected-note at -3{{please include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note at -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 at -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 at -2{{use function 'std::abs' instead}}
-  // expected-note at -3{{please include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note at -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 at -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 at -2{{use function 'std::abs' instead}}
-  // expected-note at -3{{please include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note at -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 at -1{{using floating point absolute value function 'fabsf' when argument is of integer type}}
   // expected-note at -2{{use function 'std::abs' instead}}
-  // expected-note at -3{{please include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
+  // expected-note at -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.

Modified: cfe/trunk/test/SemaObjC/builtin_objc_lib_functions.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/builtin_objc_lib_functions.m?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/builtin_objc_lib_functions.m (original)
+++ cfe/trunk/test/SemaObjC/builtin_objc_lib_functions.m Fri Jul 11 15:53:51 2014
@@ -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'}}
 }

Modified: cfe/trunk/test/SemaObjC/builtin_objc_nslog.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/builtin_objc_nslog.m?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/builtin_objc_nslog.m (original)
+++ cfe/trunk/test/SemaObjC/builtin_objc_nslog.m Fri Jul 11 15:53:51 2014
@@ -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'}}
 }

Modified: cfe/trunk/test/SemaObjC/ivar-lookup-resolution-builtin.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-lookup-resolution-builtin.m?rev=212845&r1=212844&r2=212845&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-lookup-resolution-builtin.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-lookup-resolution-builtin.m Fri Jul 11 15:53:51 2014
@@ -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





More information about the cfe-commits mailing list