[clang] 258c048 - [clang][bytecode] Fix copy constructors for empty unions (#147050)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 4 07:10:15 PDT 2025
Author: Timm Baeder
Date: 2025-07-04T16:10:12+02:00
New Revision: 258c048f643fff59be15f43f126629a356ef60fa
URL: https://github.com/llvm/llvm-project/commit/258c048f643fff59be15f43f126629a356ef60fa
DIFF: https://github.com/llvm/llvm-project/commit/258c048f643fff59be15f43f126629a356ef60fa.diff
LOG: [clang][bytecode] Fix copy constructors for empty unions (#147050)
Nothing to do in that case.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/unions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 20580c8fe7be3..5ed65f21bb2c0 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5836,6 +5836,8 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
return false;
if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
+ if (R->getNumFields() == 0)
+ return this->emitRetVoid(Ctor);
// union copy and move ctors are special.
assert(cast<CompoundStmt>(Ctor->getBody())->body_empty());
if (!this->emitThis(Ctor))
diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp
index 36f4b72335af3..0e5f83b9572b3 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -600,6 +600,18 @@ namespace MoveOrAssignOp {
}
static_assert(foo());
}
+
+namespace CopyEmptyUnion {
+ struct A {
+ union {}; // both-warning {{declaration does not declare anything}}
+ };
+ constexpr int foo() {
+ A a;
+ A a2 = a;
+ return 1;
+ }
+ static_assert(foo() == 1);
+}
#endif
namespace AddressComparison {
More information about the cfe-commits
mailing list