[cfe-commits] r145918 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/condition.cpp

Richard Trieu rtrieu at google.com
Mon Dec 5 20:48:01 PST 2011


Author: rtrieu
Date: Mon Dec  5 22:48:01 2011
New Revision: 145918

URL: http://llvm.org/viewvc/llvm-project?rev=145918&view=rev
Log:
Switch a cast to a dyn_cast and check the pointer before using.  Fixes a crash
in the following code:

void test4(bool (&x)(void)) {
  while (x);
}


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaCXX/condition.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=145918&r1=145917&r2=145918&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Dec  5 22:48:01 2011
@@ -3771,10 +3771,11 @@
       }
 
       if (D && !D->isWeak()) {
-        FunctionDecl* F = cast<FunctionDecl>(D);
-        S.Diag(E->getExprLoc(), diag::warn_impcast_function_to_bool)
-          << F << E->getSourceRange() << SourceRange(CC);
-        return;
+        if (FunctionDecl* F = dyn_cast<FunctionDecl>(D)) {
+          S.Diag(E->getExprLoc(), diag::warn_impcast_function_to_bool)
+            << F << E->getSourceRange() << SourceRange(CC);
+          return;
+        }
       }
     }
     return; // Other casts to bool are not checked.

Modified: cfe/trunk/test/SemaCXX/condition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/condition.cpp?rev=145918&r1=145917&r2=145918&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/condition.cpp (original)
+++ cfe/trunk/test/SemaCXX/condition.cpp Mon Dec  5 22:48:01 2011
@@ -52,3 +52,7 @@
   if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}}
     (void) 0;
 }
+
+void test4(bool (&x)(void)) {
+  while (x);
+}





More information about the cfe-commits mailing list