]> granicus.if.org Git - clang/commitdiff
Do not crash when we dynamic cast a final type to void*.
authorSean Hunt <scshunt@csclub.uwaterloo.ca>
Tue, 19 Jun 2012 23:44:55 +0000 (23:44 +0000)
committerSean Hunt <scshunt@csclub.uwaterloo.ca>
Tue, 19 Jun 2012 23:44:55 +0000 (23:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158763 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprCXX.cpp
test/CodeGenCXX/dynamic-cast-always-null.cpp

index e4545c152f18f6b42ec23324a26c5161756f78e7..072e2ecdb4373a1bc1afd4c3223c68381d5af1ea 100644 (file)
@@ -553,6 +553,9 @@ bool CXXDynamicCastExpr::isAlwaysNull() const
     DestType = DestType->castAs<PointerType>()->getPointeeType();
   }
 
+  if (DestType->isVoidType())
+    return false;
+
   const CXXRecordDecl *SrcRD = 
     cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
 
index 2c3ea13d195787cc41b2a046abbc6e4e475eb47b..836cb110da31a12a1188033061fcec204c81e86a 100644 (file)
@@ -17,3 +17,8 @@ C &f(B& b) {
   // CHECK: ret %struct.C* undef
   return dynamic_cast<C&>(b);
 }
+
+void dont_crash() {
+  (void) dynamic_cast<void*>((A*)0);
+  (void) dynamic_cast<void*>((B*)0);
+}