[cfe-commits] r122744 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaLookup.cpp test/Sema/implicit-builtin-decl.c

Douglas Gregor dgregor at apple.com
Mon Jan 3 01:37:44 PST 2011


Author: dgregor
Date: Mon Jan  3 03:37:44 2011
New Revision: 122744

URL: http://llvm.org/viewvc/llvm-project?rev=122744&view=rev
Log:
When we attempt to create a built-in that involves a library type we
don't have access to (e.g., fprintf, which needs the library type
FILE), fail with a warning and forget about the builtin
entirely. Previously, we would actually provide an error, which breaks
autoconf's super-lame checks for fprintf, longjmp, etc. Fixes PR8316.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/Sema/implicit-builtin-decl.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=122744&r1=122743&r2=122744&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan  3 03:37:44 2011
@@ -223,10 +223,12 @@
   "please 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 err_implicit_decl_requires_stdio : Error<
-  "implicit declaration of '%0' requires inclusion of the header <stdio.h>">;
-def err_implicit_decl_requires_setjmp : Error<
-  "implicit declaration of '%0' requires inclusion of the header <setjmp.h>">;
+def warn_implicit_decl_requires_stdio : Warning<
+  "declaration of built-in function '%0' requires inclusion of the header "
+  "<stdio.h>">;
+def warn_implicit_decl_requires_setjmp : Warning<
+  "declaration of built-in function '%0' requires inclusion of the header "
+  "<setjmp.h>">;
 def warn_redecl_library_builtin : Warning<
   "incompatible redeclaration of library function %0">;
 def err_builtin_definition : Error<"definition of builtin function %0">;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=122744&r1=122743&r2=122744&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan  3 03:37:44 2011
@@ -793,13 +793,13 @@
 
   case ASTContext::GE_Missing_stdio:
     if (ForRedeclaration)
-      Diag(Loc, diag::err_implicit_decl_requires_stdio)
+      Diag(Loc, diag::warn_implicit_decl_requires_stdio)
         << Context.BuiltinInfo.GetName(BID);
     return 0;
 
   case ASTContext::GE_Missing_setjmp:
     if (ForRedeclaration)
-      Diag(Loc, diag::err_implicit_decl_requires_setjmp)
+      Diag(Loc, diag::warn_implicit_decl_requires_setjmp)
         << Context.BuiltinInfo.GetName(BID);
     return 0;
   }

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=122744&r1=122743&r2=122744&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Jan  3 03:37:44 2011
@@ -483,12 +483,21 @@
             S.Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
           return false;
         
-        NamedDecl *D = S.LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID,
-                                             S.TUScope, R.isForRedeclaration(),
-                                             R.getNameLoc());
-        if (D) 
+        if (NamedDecl *D = S.LazilyCreateBuiltin((IdentifierInfo *)II, 
+                                                 BuiltinID, S.TUScope, 
+                                                 R.isForRedeclaration(),
+                                                 R.getNameLoc())) {
           R.addDecl(D);
-        return (D != NULL);
+          return true;
+        }
+
+        if (R.isForRedeclaration()) {
+          // If we're redeclaring this function anyway, forget that
+          // this was a builtin at all.
+          S.Context.BuiltinInfo.ForgetBuiltin(BuiltinID, S.Context.Idents);
+        }
+
+        return false;
       }
     }
   }

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=122744&r1=122743&r2=122744&view=diff
==============================================================================
--- cfe/trunk/test/Sema/implicit-builtin-decl.c (original)
+++ cfe/trunk/test/Sema/implicit-builtin-decl.c Mon Jan  3 03:37:44 2011
@@ -22,7 +22,7 @@
 }
 
 void f2() {
-  fprintf(0, "foo"); // expected-error{{implicit declaration of 'fprintf' requires inclusion of the header <stdio.h>}} \
+  fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \
    expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}}
 }
 
@@ -52,3 +52,6 @@
 }
 
 void snprintf() { }
+
+// PR8316
+void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}}





More information about the cfe-commits mailing list