Skip to content

[clang][bytecode] Handle union move assignment operators as well #125516

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 1 commit into from
Feb 3, 2025
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
7 changes: 4 additions & 3 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5665,7 +5665,7 @@ bool Compiler<Emitter>::compileDestructor(const CXXDestructorDecl *Dtor) {
}

template <class Emitter>
bool Compiler<Emitter>::compileUnionCopyAssignmentOperator(
bool Compiler<Emitter>::compileUnionAssignmentOperator(
const CXXMethodDecl *MD) {
if (!this->emitThis(MD))
return false;
Expand Down Expand Up @@ -5693,8 +5693,9 @@ bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
const RecordDecl *RD = MD->getParent();

if (RD->isUnion() && MD->isCopyAssignmentOperator())
return this->compileUnionCopyAssignmentOperator(MD);
if (RD->isUnion() &&
(MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()))
return this->compileUnionAssignmentOperator(MD);

if (MD->isLambdaStaticInvoker())
return this->emitLambdaStaticInvokerBody(MD);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
bool emitBuiltinBitCast(const CastExpr *E);
bool compileConstructor(const CXXConstructorDecl *Ctor);
bool compileDestructor(const CXXDestructorDecl *Dtor);
bool compileUnionCopyAssignmentOperator(const CXXMethodDecl *MD);
bool compileUnionAssignmentOperator(const CXXMethodDecl *MD);

bool checkLiteralType(const Expr *E);

Expand Down
14 changes: 14 additions & 0 deletions clang/test/AST/ByteCode/unions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,20 @@ namespace CopyAssign {
}
static_assert(f2() == 12); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
}

namespace MoveAssign {
union A {
int a;
int b;
};

constexpr int f() {
A b{13};

b = A{12} ;
return b.a;
}
static_assert(f()== 12);
}
#endif