forked from OSchip/llvm-project
Provide a custom diagnostic when code tries to use an unknown builtin
llvm-svn: 83014
This commit is contained in:
parent
1709e8c084
commit
56fbc37bbb
|
@ -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++.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue