r217413 - Allow empty statements in naked functions in addition to ASM statements

Ehsan Akhgari ehsan.akhgari at gmail.com
Mon Sep 8 19:49:40 PDT 2014


Author: ehsan
Date: Mon Sep  8 21:49:40 2014
New Revision: 217413

URL: http://llvm.org/viewvc/llvm-project?rev=217413&view=rev
Log:
Allow empty statements in naked functions in addition to ASM statements

Summary: This fixes PR20883.

Test Plan: The patch includes an automated test.

Reviewers: hansw

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

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/attr-naked.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=217413&r1=217412&r2=217413&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep  8 21:49:40 2014
@@ -10426,7 +10426,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
 
     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();

Modified: cfe/trunk/test/Sema/attr-naked.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-naked.c?rev=217413&r1=217412&r2=217413&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-naked.c (original)
+++ cfe/trunk/test/Sema/attr-naked.c Mon Sep  8 21:49:40 2014
@@ -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");
+  ;
+}





More information about the cfe-commits mailing list