https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/231886

Create a local variable and initialize it from the `APValue`.

>From 0b1d475d8b2f74fd31f9a6fb68a44dbe46986703 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Wed, 14 Oct 2026 13:12:46 +0200
Subject: [PATCH] asdf

---
 clang/lib/AST/ByteCode/Compiler.cpp           | 49 +++++++++++++++++--
 .../AST/static-compound-literals-reeval.cpp   |  1 +
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 6ba5099a78b877..a37c606bec8b6f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2795,8 +2795,15 @@ bool Compiler<Emitter>::VisitConstantExpr(const 
ConstantExpr *E) {
     return this->visitAPValue(E->getAPValueResult(), *T, E);
   }
 
-  // Fall back to the subexpr for non-primitive APValues.
-  return this->delegate(E->getSubExpr());
+  assert(!DiscardResult);
+  if (!Initializing) {
+    UnsignedOrNone LocalIndex = allocateLocal(E);
+    if (!LocalIndex)
+      return false;
+    if (!this->emitGetPtrLocal(*LocalIndex, E))
+      return false;
+  }
+  return this->visitAPValueInitializer(E->getAPValueResult(), E, E->getType());
 }
 
 template <class Emitter>
@@ -6234,8 +6241,44 @@ bool Compiler<Emitter>::visitAPValueInitializer(const 
APValue &Val,
     }
     return true;
   }
-  // TODO: Other types.
+  if (Val.isComplexFloat()) {
+    assert(T->isComplexType());
+    if (!this->emitFloat(Val.getComplexFloatReal(), Info))
+      return false;
+    if (!this->emitInitElemFloat(0, Info))
+      return false;
+    if (!this->emitFloat(Val.getComplexFloatImag(), Info))
+      return false;
+    if (!this->emitInitElemFloat(1, Info))
+      return false;
+    return true;
+  }
+  if (Val.isComplexInt()) {
+    assert(T->isComplexIntegerType());
+    PrimType IntT = classifyPrim(T->getAs<ComplexType>()->getElementType());
+    if (!this->emitConst(Val.getComplexIntReal(), IntT, Info))
+      return false;
+    if (!this->emitInitElem(IntT, 0, Info))
+      return false;
+    if (!this->emitConst(Val.getComplexIntImag(), IntT, Info))
+      return false;
+    if (!this->emitInitElem(IntT, 1, Info))
+      return false;
+    return true;
+  }
+  if (Val.isVector()) {
+    assert(T->isVectorType());
+    PrimType IntT = classifyPrim(T->getAs<VectorType>()->getElementType());
+    for (unsigned I = 0, N = Val.getVectorLength(); I != N; ++I) {
+      if (!this->visitAPValue(Val.getVectorElt(I), IntT, Info))
+        return false;
+      if (!this->emitInitElem(IntT, I, Info))
+        return false;
+    }
+    return true;
+  }
 
+  // TODO: Other types.
   return false;
 }
 
diff --git a/clang/test/AST/static-compound-literals-reeval.cpp 
b/clang/test/AST/static-compound-literals-reeval.cpp
index 29e21798b9295c..07c92a785264b6 100644
--- a/clang/test/AST/static-compound-literals-reeval.cpp
+++ b/clang/test/AST/static-compound-literals-reeval.cpp
@@ -1,5 +1,6 @@
 // Test that we can successfully compile this code, especially under ASAN.
 // RUN: %clang_cc1 -emit-llvm -std=c++20 %s -o- | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -std=c++20 %s -o- 
-fexperimental-new-constant-interpreter | FileCheck %s
 struct RR { int r; };
 struct Z { int x; const RR* y; int z; };
 constinit Z z = { 10, (const RR[1]){__builtin_constant_p(z.x)}, z.y->r };

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to