From ae8a5cdd4ec22023da0f0f1ca5764d18b0eec6d4 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 2 Oct 2019 01:13:57 +0000 Subject: [PATCH] Fix crash on constant-evaluation of pseudo-destruction of a pointer. We got confused and thought we might be pseudo-destroying the pointee instead. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373418 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 2 +- test/SemaCXX/constant-expression-cxx2a.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index cf28ecbe5f..92ea1c9300 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -3997,7 +3997,7 @@ static bool handleIncDec(EvalInfo &Info, const Expr *E, const LValue &LVal, /// Build an lvalue for the object argument of a member function call. static bool EvaluateObjectArgument(EvalInfo &Info, const Expr *Object, LValue &This) { - if (Object->getType()->isPointerType()) + if (Object->getType()->isPointerType() && Object->isRValue()) return EvaluatePointer(Object, This, Info); if (Object->isGLValue()) diff --git a/test/SemaCXX/constant-expression-cxx2a.cpp b/test/SemaCXX/constant-expression-cxx2a.cpp index ef3ce5c0cc..cb8f16a8b0 100644 --- a/test/SemaCXX/constant-expression-cxx2a.cpp +++ b/test/SemaCXX/constant-expression-cxx2a.cpp @@ -1283,6 +1283,15 @@ namespace dtor_call { // FIXME: This diagnostic is wrong; the union has no active member now. as.b.~A(); // expected-note {{destruction of member 'b' of union with active member 'a'}} } + + constexpr void destroy_pointer() { + using T = int*; + T p; + // We used to think this was an -> member access because its left-hand side + // is a pointer. Ensure we don't crash. + p.~T(); + } + static_assert((destroy_pointer(), true)); } namespace temp_dtor { -- 2.40.0