]> granicus.if.org Git - clang/commitdiff
Allow empty statements in naked functions in addition to ASM statements
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Tue, 9 Sep 2014 02:49:40 +0000 (02:49 +0000)
committerEhsan Akhgari <ehsan.akhgari@gmail.com>
Tue, 9 Sep 2014 02:49:40 +0000 (02:49 +0000)
Summary: This fixes PR20883.

Test Plan: The patch includes an automated test.

Reviewers: hansw

Differential Revision: http://reviews.llvm.org/D5256

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217413 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/attr-naked.c

index 27f69adff56b6a3fd8e82b84fd9c5a2bb7a7db72..1f2cf7bc9f18d0f500f0020b5f7ac86b5acd0410 100644 (file)
@@ -10426,7 +10426,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
 
     if (FD && FD->hasAttr<NakedAttr>()) {
       for (const Stmt *S : Body->children()) {
-        if (!isa<AsmStmt>(S)) {
+        if (!isa<AsmStmt>(S) && !isa<NullStmt>(S)) {
           Diag(S->getLocStart(), diag::err_non_asm_stmt_in_naked_function);
           Diag(FD->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
           FD->setInvalidDecl();
index f6c26b29fc3a2ce74bba65929f8f03cd69d15f30..fcae842775e0db245402edfefae90618db514c25 100644 (file)
@@ -23,3 +23,12 @@ __attribute__((naked)) int t5(int x) {
   asm("movl x, %eax");
   asm("retl");
 }
+
+__attribute__((naked)) void t6() {
+  ;
+}
+
+__attribute__((naked)) void t7() {
+  asm("movl $42, %eax");
+  ;
+}