From a262c9464b7765b4583c3226fe4d8c33a96b163e Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Wed, 2 Jul 2014 04:39:38 +0000 Subject: [PATCH] Prevent Clang from crashing on template code. Fixes PR20110, where Clang hits an assertion failure when it expects that the sub-expression of a bit cast to pointer to also be a pointer, but gets a value instead. Differential Revision: http://reviews.llvm.org/D4280 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212160 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 9 ++++++++- test/SemaCXX/PR20110.cpp | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/SemaCXX/PR20110.cpp diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 1a49b4ac4f..cd31f72c65 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4613,7 +4613,6 @@ static Expr *EvalAddr(Expr *E, SmallVectorImpl &refVars, case Stmt::CXXReinterpretCastExprClass: { Expr* SubExpr = cast(E)->getSubExpr(); switch (cast(E)->getCastKind()) { - case CK_BitCast: case CK_LValueToRValue: case CK_NoOp: case CK_BaseToDerived: @@ -4628,6 +4627,14 @@ static Expr *EvalAddr(Expr *E, SmallVectorImpl &refVars, case CK_ArrayToPointerDecay: return EvalVal(SubExpr, refVars, ParentDecl); + case CK_BitCast: + if (SubExpr->getType()->isAnyPointerType() || + SubExpr->getType()->isBlockPointerType() || + SubExpr->getType()->isObjCQualifiedIdType()) + return EvalAddr(SubExpr, refVars, ParentDecl); + else + return nullptr; + default: return nullptr; } diff --git a/test/SemaCXX/PR20110.cpp b/test/SemaCXX/PR20110.cpp new file mode 100644 index 0000000000..e540a738b8 --- /dev/null +++ b/test/SemaCXX/PR20110.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// expected-no-diagnostics + +// FIXME: These templates should trigger errors in C++11 mode. + +template +class A { + char const *get_p() { return *p; } +}; +template +class B { + char const *get_p() { return p; } +}; + -- 2.40.0