Skip to content

PR for llvm/llvm-project#65982 #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6013,8 +6013,9 @@ const AccessKinds StartLifetimeOfUnionMemberHandler::AccessKind;
/// operator whose left-hand side might involve a union member access. If it
/// does, implicitly start the lifetime of any accessed union elements per
/// C++20 [class.union]5.
static bool HandleUnionActiveMemberChange(EvalInfo &Info, const Expr *LHSExpr,
const LValue &LHS) {
static bool MaybeHandleUnionActiveMemberChange(EvalInfo &Info,
const Expr *LHSExpr,
const LValue &LHS) {
if (LHS.InvalidBase || LHS.Designator.Invalid)
return false;

Expand Down Expand Up @@ -6069,8 +6070,14 @@ static bool HandleUnionActiveMemberChange(EvalInfo &Info, const Expr *LHSExpr,
break;
// Walk path backwards as we walk up from the base to the derived class.
for (const CXXBaseSpecifier *Elt : llvm::reverse(ICE->path())) {
if (Elt->isVirtual()) {
// A class with virtual base classes never has a trivial default
// constructor, so S(E) is empty in this case.
E = nullptr;
break;
}

--PathLength;
(void)Elt;
assert(declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(),
LHS.Designator.Entries[PathLength]
.getAsBaseOrMember().getPointer()));
Expand Down Expand Up @@ -7748,7 +7755,7 @@ class ExprEvaluatorBase
// per C++20 [class.union]5.
if (Info.getLangOpts().CPlusPlus20 && OCE &&
OCE->getOperator() == OO_Equal && MD->isTrivial() &&
!HandleUnionActiveMemberChange(Info, Args[0], ThisVal))
!MaybeHandleUnionActiveMemberChange(Info, Args[0], ThisVal))
return false;

Args = Args.slice(1);
Expand Down Expand Up @@ -8621,7 +8628,7 @@ bool LValueExprEvaluator::VisitBinAssign(const BinaryOperator *E) {
return false;

if (Info.getLangOpts().CPlusPlus20 &&
!HandleUnionActiveMemberChange(Info, E->getLHS(), Result))
!MaybeHandleUnionActiveMemberChange(Info, E->getLHS(), Result))
return false;

return handleAssignment(this->Info, E, Result, E->getLHS()->getType(),
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaCXX/cxx2a-virtual-base-used.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -std=c++2a -verify -triple=x86_64-linux-gnu %s
// expected-no-diagnostics

// Fixes assertion triggered by https://github.com/llvm/llvm-project/issues/65982

struct A { int y; };
struct B : virtual public A {};
struct X : public B {};

void member_with_virtual_inheritance() {
X x;
x.B::y = 1;
}