[clang] d4a2c7f - [clang][Interp] Fix record initialization from temporary in initlist
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 7 07:27:02 PST 2024
Author: Timm Bäder
Date: 2024-02-07T16:09:49+01:00
New Revision: d4a2c7f95297d1865a457955dcf7b679dabb5e0e
URL: https://github.com/llvm/llvm-project/commit/d4a2c7f95297d1865a457955dcf7b679dabb5e0e
DIFF: https://github.com/llvm/llvm-project/commit/d4a2c7f95297d1865a457955dcf7b679dabb5e0e.diff
LOG: [clang][Interp] Fix record initialization from temporary in initlist
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/records.cpp
clang/test/SemaCXX/cxx1z-copy-omission.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b95126ee20fe2..59fddfc2da195 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -863,6 +863,10 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
assert(E->getType()->isRecordType());
const Record *R = getRecord(E->getType());
+ if (Inits.size() == 1 && E->getType() == Inits[0]->getType()) {
+ return this->visitInitializer(Inits[0]);
+ }
+
unsigned InitIndex = 0;
for (const Expr *Init : Inits) {
if (!this->emitDupPtr(E))
diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index c6aac7938a297..5ce1e6e09a0b7 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -7,6 +7,10 @@
// RUN: %clang_cc1 -verify=ref -std=c++20 %s
// RUN: %clang_cc1 -verify=ref -triple i686 %s
+/// Used to crash.
+struct Empty {};
+constexpr Empty e = {Empty()};
+
struct BoolPair {
bool first;
bool second;
diff --git a/clang/test/SemaCXX/cxx1z-copy-omission.cpp b/clang/test/SemaCXX/cxx1z-copy-omission.cpp
index f46a17af83386..92ebfdd8e4c73 100644
--- a/clang/test/SemaCXX/cxx1z-copy-omission.cpp
+++ b/clang/test/SemaCXX/cxx1z-copy-omission.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c++1z -verify -Wno-unused %s
+// RUN: %clang_cc1 -std=c++1z -verify -Wno-unused %s -fexperimental-new-constant-interpreter
struct Noncopyable {
Noncopyable();
More information about the cfe-commits
mailing list