From: Sean Hunt Date: Tue, 19 Jun 2012 23:44:55 +0000 (+0000) Subject: Do not crash when we dynamic cast a final type to void*. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ca8639f97663255880f0da81f1026a06a14d003;p=clang Do not crash when we dynamic cast a final type to void*. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158763 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index e4545c152f..072e2ecdb4 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -553,6 +553,9 @@ bool CXXDynamicCastExpr::isAlwaysNull() const DestType = DestType->castAs()->getPointeeType(); } + if (DestType->isVoidType()) + return false; + const CXXRecordDecl *SrcRD = cast(SrcType->castAs()->getDecl()); diff --git a/test/CodeGenCXX/dynamic-cast-always-null.cpp b/test/CodeGenCXX/dynamic-cast-always-null.cpp index 2c3ea13d19..836cb110da 100644 --- a/test/CodeGenCXX/dynamic-cast-always-null.cpp +++ b/test/CodeGenCXX/dynamic-cast-always-null.cpp @@ -17,3 +17,8 @@ C &f(B& b) { // CHECK: ret %struct.C* undef return dynamic_cast(b); } + +void dont_crash() { + (void) dynamic_cast((A*)0); + (void) dynamic_cast((B*)0); +}