r217199 - Don't allow non-ASM statements in naked functions
Hans Wennborg
hans at hanshq.net
Thu Sep 4 15:16:41 PDT 2014
Author: hans
Date: Thu Sep 4 17:16:40 2014
New Revision: 217199
URL: http://llvm.org/viewvc/llvm-project?rev=217199&view=rev
Log:
Don't allow non-ASM statements in naked functions
Naked functions don't have prologues or epilogues, so doing
codegen for anything other than inline assembly would be completely
hit or miss.
Differential Revision: http://reviews.llvm.org/D5183
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/attr-naked.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=217199&r1=217198&r2=217199&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep 4 17:16:40 2014
@@ -6991,6 +6991,9 @@ def err_unknown_any_function : Error<
def err_filter_expression_integral : Error<
"filter expression type should be an integral value not %0">;
+def err_non_asm_stmt_in_naked_function : Error<
+ "non-ASM statement in naked function is not supported">;
+
// OpenCL warnings and errors.
def err_invalid_astype_of_different_size : Error<
"invalid reinterpretation: sizes of %0 and %1 must match">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=217199&r1=217198&r2=217199&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep 4 17:16:40 2014
@@ -10376,6 +10376,17 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
!CheckConstexprFunctionBody(FD, Body)))
FD->setInvalidDecl();
+ if (FD && FD->hasAttr<NakedAttr>()) {
+ for (const Stmt *S : Body->children()) {
+ if (!isa<AsmStmt>(S)) {
+ Diag(S->getLocStart(), diag::err_non_asm_stmt_in_naked_function);
+ Diag(FD->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
+ FD->setInvalidDecl();
+ break;
+ }
+ }
+ }
+
assert(ExprCleanupObjects.empty() && "Leftover temporaries in function");
assert(!ExprNeedsCleanups && "Unaccounted cleanups in function");
assert(MaybeODRUseExprs.empty() &&
Modified: cfe/trunk/test/Sema/attr-naked.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-naked.c?rev=217199&r1=217198&r2=217199&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-naked.c (original)
+++ cfe/trunk/test/Sema/attr-naked.c Thu Sep 4 17:16:40 2014
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -triple i686-pc-linux
int a __attribute__((naked)); // expected-warning {{'naked' attribute only applies to functions}}
@@ -10,3 +10,11 @@ void t1() __attribute__((naked));
void t2() __attribute__((naked(2))); // expected-error {{'naked' attribute takes no arguments}}
+__attribute__((naked)) int t3() { // expected-note{{attribute is here}}
+ return 42; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) int t4() {
+ asm("movl $42, %eax");
+ asm("retl");
+}
More information about the cfe-commits
mailing list