diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-28 21:14:19 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-28 21:14:19 +0000 |
commit | 9a8c9a2eacd80437f18edb339a37516ab7e773cd (patch) | |
tree | c4cf54d907a9538c7d0eca3007e9495d6c3b9eaa | |
parent | 99d6c445cc968bdf08c53a6bd4e9044bde43bdd1 (diff) |
Provide a custom diagnostic when code tries to use an unknown builtin
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83014 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 1 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 11 | ||||
-rw-r--r-- | test/Sema/builtins.c | 4 |
3 files changed, 11 insertions, 5 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 44b582d43c..1d4e003e59 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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++. diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7f3f24efea..5df4dca860 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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; diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index 912a6b385c..e133d626ee 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -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}} +} |