[cfe-commits] r51307 - in /cfe/trunk: include/clang/AST/Builtins.def include/clang/Basic/DiagnosticKinds.def lib/Sema/Sema.h lib/Sema/SemaChecking.cpp test/Sema/builtin-stackaddress.c
Eli Friedman
eli.friedman at gmail.com
Tue May 20 01:23:37 PDT 2008
Author: efriedma
Date: Tue May 20 03:23:37 2008
New Revision: 51307
URL: http://llvm.org/viewvc/llvm-project?rev=51307&view=rev
Log:
Add __builtin_frame_address and __builtin_return_address gcc builtins to
Sema. No codegen yet.
Added:
cfe/trunk/test/Sema/builtin-stackaddress.c
Modified:
cfe/trunk/include/clang/AST/Builtins.def
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/include/clang/AST/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Builtins.def?rev=51307&r1=51306&r2=51307&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Builtins.def (original)
+++ cfe/trunk/include/clang/AST/Builtins.def Tue May 20 03:23:37 2008
@@ -94,6 +94,8 @@
BUILTIN(__builtin_va_end, "va&", "n")
BUILTIN(__builtin_va_copy, "va&a", "n")
BUILTIN(__builtin_memcpy, "v*v*vC*z", "n")
+BUILTIN(__builtin_return_address, "v*Ui", "n")
+BUILTIN(__builtin_frame_address, "v*Ui", "n")
// GCC Object size checking builtins
BUILTIN(__builtin___memcpy_chk, "v*v*vC*zz", "n")
BUILTIN(__builtin___memmove_chk, "v*v*vC*zz", "n")
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=51307&r1=51306&r2=51307&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue May 20 03:23:37 2008
@@ -1069,4 +1069,7 @@
DIAG(err_shufflevector_argument_too_large, ERROR,
"indexes for __builtin_shufflevector must be less than the total number of vector elements")
+DIAG(err_stack_const_level, ERROR,
+ "the level argument for a stack address builtin must be constant")
+
#undef DIAG
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=51307&r1=51306&r2=51307&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue May 20 03:23:37 2008
@@ -891,6 +891,7 @@
bool CheckBuiltinCFStringArgument(Expr* Arg);
bool SemaBuiltinVAStart(CallExpr *TheCall);
bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
+ bool SemaBuiltinStackAddress(CallExpr *TheCall);
Action::ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
void CheckPrintfArguments(CallExpr *TheCall,
bool HasVAListArg, unsigned format_idx);
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=51307&r1=51306&r2=51307&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue May 20 03:23:37 2008
@@ -58,6 +58,11 @@
if (SemaBuiltinUnorderedCompare(TheCall.get()))
return true;
return TheCall.take();
+ case Builtin::BI__builtin_return_address:
+ case Builtin::BI__builtin_frame_address:
+ if (SemaBuiltinStackAddress(TheCall.get()))
+ return true;
+ return TheCall.take();
case Builtin::BI__builtin_shufflevector:
return SemaBuiltinShuffleVector(TheCall.get());
}
@@ -177,7 +182,7 @@
Diag(TheCall->getArg(1)->getLocStart(),
diag::warn_second_parameter_of_va_start_not_last_named_argument);
return false;
-}
+}
/// SemaBuiltinUnorderedCompare - Handle functions like __builtin_isgreater and
/// friends. This is declared to take (...), so we have to check everything.
@@ -209,6 +214,16 @@
return false;
}
+bool Sema::SemaBuiltinStackAddress(CallExpr *TheCall) {
+ // The signature for these builtins is exact; the only thing we need
+ // to check is that the argument is a constant.
+ SourceLocation Loc;
+ if (!TheCall->getArg(0)->isIntegerConstantExpr(Context, &Loc)) {
+ return Diag(Loc, diag::err_stack_const_level, TheCall->getSourceRange());
+ }
+ return false;
+}
+
/// SemaBuiltinShuffleVector - Handle __builtin_shufflevector.
// This is declared to take (...), so we have to check everything.
Action::ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
Added: cfe/trunk/test/Sema/builtin-stackaddress.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtin-stackaddress.c?rev=51307&view=auto
==============================================================================
--- cfe/trunk/test/Sema/builtin-stackaddress.c (added)
+++ cfe/trunk/test/Sema/builtin-stackaddress.c Tue May 20 03:23:37 2008
@@ -0,0 +1,16 @@
+// RUN: clang -fsyntax-only -verify %s
+void* a(unsigned x) {
+return __builtin_return_address(0);
+}
+
+void b(unsigned x) {
+return __builtin_return_address(x); // expected-error{{the level argument for a stack address builtin must be constant}}
+}
+
+void* a(unsigned x) {
+return __builtin_frame_address(0);
+}
+
+void b(unsigned x) {
+return __builtin_frame_address(x); // expected-error{{the level argument for a stack address builtin must be constant}}
+}
More information about the cfe-commits
mailing list