[cfe-commits] r83014 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/builtins.c
Douglas Gregor
dgregor at apple.com
Mon Sep 28 14:14:20 PDT 2009
Author: dgregor
Date: Mon Sep 28 16:14:19 2009
New Revision: 83014
URL: http://llvm.org/viewvc/llvm-project?rev=83014&view=rev
Log:
Provide a custom diagnostic when code tries to use an unknown builtin
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/builtins.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=83014&r1=83013&r2=83014&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 28 16:14:19 2009
@@ -148,6 +148,7 @@
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++.
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=83014&r1=83013&r2=83014&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep 28 16:14:19 2009
@@ -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 @@
}
// 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;
Modified: cfe/trunk/test/Sema/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=83014&r1=83013&r2=83014&view=diff
==============================================================================
--- cfe/trunk/test/Sema/builtins.c (original)
+++ cfe/trunk/test/Sema/builtins.c Mon Sep 28 16:14:19 2009
@@ -67,3 +67,7 @@
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}}
+}
More information about the cfe-commits
mailing list