]> granicus.if.org Git - clang/commitdiff
This patch should fix PR2461. It allows clang to apply the noreturn
authorMike Stump <mrs@apple.com>
Tue, 15 Dec 2009 03:11:10 +0000 (03:11 +0000)
committerMike Stump <mrs@apple.com>
Tue, 15 Dec 2009 03:11:10 +0000 (03:11 +0000)
attribute to function pointers. It also fixes Sema to check function
pointers for the noreturn attribute when checking for fallthrough.

Patch by Chip Davis, with a slight fix to pass the testsuite.

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

lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclAttr.cpp

index 64305b443ec5c152b6d1aad17f003a4c8a3a517e..14d2377784d5d34adde2dc1e6d44942e436e0896 100644 (file)
@@ -1265,11 +1265,10 @@ Sema::ControlFlowKind Sema::CheckFallThrough(Stmt *Root) {
         NoReturnEdge = true;
         HasFakeEdge = true;
       } else if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
-        if (FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
-          if (FD->hasAttr<NoReturnAttr>()) {
-            NoReturnEdge = true;
-            HasFakeEdge = true;
-          }
+        ValueDecl *VD = DRE->getDecl();
+        if (VD->hasAttr<NoReturnAttr>()) {
+          NoReturnEdge = true;
+          HasFakeEdge = true;
         }
       }
     }
index e219923f6dae207de163499e7a4cc6aae1411c50..84ee2073382f93336e5bad1cc6166d76c62af4a5 100644 (file)
@@ -376,7 +376,8 @@ static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
 
   if (!isFunctionOrMethod(d) && !isa<BlockDecl>(d)) {
     ValueDecl *VD = dyn_cast<ValueDecl>(d);
-    if (VD == 0 || !VD->getType()->isBlockPointerType()) {
+    if (VD == 0 || (!VD->getType()->isBlockPointerType()
+                    && !VD->getType()->isFunctionPointerType())) {
       S.Diag(Attr.getLoc(),
              Attr.isCXX0XAttribute() ? diag::err_attribute_wrong_decl_type
                                      : diag::warn_attribute_wrong_decl_type)