Author: rsmith Date: Thu Oct 10 15:31:17 2019 New Revision: 374465 URL: http://llvm.org/viewvc/llvm-project?rev=374465&view=rev Log: PR43629: Fix crash evaluating constexpr placement new on a subobject of an out-of-lifetime object.
Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=374465&r1=374464&r2=374465&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Thu Oct 10 15:31:17 2019 @@ -126,7 +126,8 @@ def note_constexpr_lifetime_ended : Note "%plural{8:storage duration|:lifetime}0 has ended">; def note_constexpr_access_uninit : Note< "%select{read of|read of|assignment to|increment of|decrement of|" - "member call on|dynamic_cast of|typeid applied to|<ERRPR>|destruction of}0 " + "member call on|dynamic_cast of|typeid applied to|" + "construction of subobject of|destruction of}0 " "%select{object outside its lifetime|uninitialized object}1 " "is not allowed in a constant expression">; def note_constexpr_use_uninit_reference : Note< Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=374465&r1=374464&r2=374465&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Oct 10 15:31:17 2019 @@ -3178,7 +3178,7 @@ findSubobject(EvalInfo &Info, const Expr // Walk the designator's path to find the subobject. for (unsigned I = 0, N = Sub.Entries.size(); /**/; ++I) { // Reading an indeterminate value is undefined, but assigning over one is OK. - if ((O->isAbsent() && handler.AccessKind != AK_Construct) || + if ((O->isAbsent() && !(handler.AccessKind == AK_Construct && I == N)) || (O->isIndeterminate() && handler.AccessKind != AK_Construct && handler.AccessKind != AK_Assign && handler.AccessKind != AK_ReadObjectRepresentation)) { Modified: cfe/trunk/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp?rev=374465&r1=374464&r2=374465&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp (original) +++ cfe/trunk/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp Thu Oct 10 15:31:17 2019 @@ -166,3 +166,13 @@ constexpr bool construct_after_lifetime( return true; } static_assert(construct_after_lifetime()); // expected-error {{}} expected-note {{in call}} + +constexpr bool construct_after_lifetime_2() { + struct A { struct B {} b; }; + A a; + a.~A(); + std::construct_at<A::B>(&a.b); // expected-note {{in call}} + // expected-note@#new {{construction of subobject of object outside its lifetime is not allowed in a constant expression}} + return true; +} +static_assert(construct_after_lifetime_2()); // expected-error {{}} expected-note {{in call}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits