r174477 - Use a dyn_cast to avoid a crash when the TypeLoc is not a ConstantArrayTypeLoc.

Chad Rosier mcrosier at apple.com
Tue Feb 5 16:58:34 PST 2013


Author: mcrosier
Date: Tue Feb  5 18:58:34 2013
New Revision: 174477

URL: http://llvm.org/viewvc/llvm-project?rev=174477&view=rev
Log:
Use a dyn_cast to avoid a crash when the TypeLoc is not a ConstantArrayTypeLoc.
rdar://13153516

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=174477&r1=174476&r2=174477&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Feb  5 18:58:34 2013
@@ -5777,10 +5777,11 @@ static bool IsTailPaddedMemberArray(Sema
       TInfo = TDL->getTypeSourceInfo();
       continue;
     }
-    ConstantArrayTypeLoc CTL = cast<ConstantArrayTypeLoc>(TL);
-    const Expr *SizeExpr = dyn_cast<IntegerLiteral>(CTL.getSizeExpr());
-    if (!SizeExpr || SizeExpr->getExprLoc().isMacroID())
-      return false;
+    if (const ConstantArrayTypeLoc *CTL = dyn_cast<ConstantArrayTypeLoc>(&TL)) {
+      const Expr *SizeExpr = dyn_cast<IntegerLiteral>(CTL->getSizeExpr());
+      if (!SizeExpr || SizeExpr->getExprLoc().isMacroID())
+        return false;
+    }
     break;
   }
 





More information about the cfe-commits mailing list