[clang] 10dc3a8 - [clang][Interp] Fix empty InitListExprs for unions
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu May 23 02:48:48 PDT 2024
Author: Timm Bäder
Date: 2024-05-23T11:48:33+02:00
New Revision: 10dc3a8e916d73291269e5e2b82dd22681489aa1
URL: https://github.com/llvm/llvm-project/commit/10dc3a8e916d73291269e5e2b82dd22681489aa1
DIFF: https://github.com/llvm/llvm-project/commit/10dc3a8e916d73291269e5e2b82dd22681489aa1.diff
LOG: [clang][Interp] Fix empty InitListExprs for unions
We still need to handle Inits.size() == 0, but we can do that earlier.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/unions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e64d3a94b5091..0c514236d4ca7 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1053,6 +1053,9 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
return this->visitInitializer(Inits[0]);
+ if (Inits.size() == 0)
+ return this->emitFinishInit(E);
+
auto initPrimitiveField = [=](const Record::Field *FieldToInit,
const Expr *Init, PrimType T) -> bool {
if (!this->visit(Init))
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 73e42d57a7b77..b0b1b19617408 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -42,4 +42,10 @@ namespace SimpleStore {
return a.b;
}
static_assert(foo() == 10, "");
+
+ constexpr int empty() {
+ A a{}; /// Just test that this works.
+ return 10;
+ }
+ static_assert(empty() == 10, "");
}
More information about the cfe-commits
mailing list