diff options
author | Sean Hunt <scshunt@csclub.uwaterloo.ca> | 2012-06-19 23:44:55 +0000 |
---|---|---|
committer | Sean Hunt <scshunt@csclub.uwaterloo.ca> | 2012-06-19 23:44:55 +0000 |
commit | 5ca8639f97663255880f0da81f1026a06a14d003 (patch) | |
tree | fbf1d1324e77664f847ad65889a273bb41750a5f | |
parent | 0aa52aa11e04d957f1c93c7d911e4c3dd7d5d54f (diff) |
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
-rw-r--r-- | lib/AST/ExprCXX.cpp | 3 | ||||
-rw-r--r-- | test/CodeGenCXX/dynamic-cast-always-null.cpp | 5 |
2 files changed, 8 insertions, 0 deletions
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<PointerType>()->getPointeeType(); } + if (DestType->isVoidType()) + return false; + const CXXRecordDecl *SrcRD = cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->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<C&>(b); } + +void dont_crash() { + (void) dynamic_cast<void*>((A*)0); + (void) dynamic_cast<void*>((B*)0); +} |