]> granicus.if.org Git - clang/commitdiff
Provide a custom diagnostic when code tries to use an unknown builtin
authorDouglas Gregor <dgregor@apple.com>
Mon, 28 Sep 2009 21:14:19 +0000 (21:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 28 Sep 2009 21:14:19 +0000 (21:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83014 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Sema/builtins.c

index 44b582d43c469466bdd7ffeb9e99c245a34545a0..1d4e003e59e76d0120e0c7aff179ae2c6b880245 100644 (file)
@@ -148,6 +148,7 @@ def warn_redecl_library_builtin : Warning<
 def err_builtin_definition : Error<"definition of builtin function %0">;
 def err_types_compatible_p_in_cplusplus : Error<
   "__builtin_types_compatible_p is not valid in C++">;
+def warn_builtin_unknown : Warning<"use of unknown builtin %0">, DefaultError;
 
 /// main()
 // static/inline main() are not errors in C, just in C++.
index 7f3f24efeadcd085af0ff5473135da21ac371a65..5df4dca86023c5c519d49cfe5e6e566b21e601c4 100644 (file)
@@ -32,6 +32,7 @@
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include <algorithm>
+#include <cstring>
 #include <functional>
 #include <queue>
 using namespace clang;
@@ -3925,15 +3926,15 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
   }
 
   // Extension in C99.  Legal in C90, but warn about it.
-  if (getLangOptions().C99)
+  static const unsigned int BuiltinLen = strlen("__builtin_");
+  if (II.getLength() > BuiltinLen &&
+      std::equal(II.getName(), II.getName() + BuiltinLen, "__builtin_"))
+    Diag(Loc, diag::warn_builtin_unknown) << &II;
+  else if (getLangOptions().C99)
     Diag(Loc, diag::ext_implicit_function_decl) << &II;
   else
     Diag(Loc, diag::warn_implicit_function_decl) << &II;
 
-  // FIXME: handle stuff like:
-  // void foo() { extern float X(); }
-  // void bar() { X(); }  <-- implicit decl for X in another scope.
-
   // Set a Declarator for the implicit definition: int foo();
   const char *Dummy;
   DeclSpec DS;
index 912a6b385c47d19089ac2595d297c37c6a9cc227..e133d626ee52d5ddbee8c6769a68419513a8b38c 100644 (file)
@@ -67,3 +67,7 @@ void test12(void) __attribute__((__noreturn__));
 void test12(void) {
   __builtin_trap();  // no warning because trap is noreturn.
 }
+
+void test_unknown_builtin(int a, int b) {
+  __builtin_foo(a, b); // expected-error{{use of unknown builtin}}
+}