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

We shouldn't try to do the memcpy if the semantics don't match.

>From 109c54f8e58238b79987c32ce55e6ccf20335fd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sun, 7 Jun 2026 15:16:26 +0200
Subject: [PATCH] asdf

---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 16 +++++++++++-----
 clang/test/AST/ByteCode/codegen.cpp      |  2 ++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 501c7f76a0376..95e2d91a98b94 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -6693,15 +6693,21 @@ static bool copyComposite(InterpState &S, CodePtr OpPC, 
const Pointer &Src,
   if (DestDesc->isPrimitiveArray()) {
     if (!SrcDesc->isPrimitiveArray())
       return false;
+    // For floating types, check the actual QualType so we don't accidentally
+    // mix up semantics.
+    if (SrcDesc->getPrimType() == PT_Float) {
+      if (!S.getASTContext().hasSimilarType(SrcDesc->getElemQualType(),
+                                            DestDesc->getElemQualType()))
+        return false;
+    }
+
     assert(SrcDesc->isPrimitiveArray());
     assert(SrcDesc->getNumElems() == DestDesc->getNumElems());
+    assert(SrcDesc->getPrimType() == DestDesc->getPrimType());
     PrimType ET = DestDesc->getPrimType();
     for (unsigned I = 0, N = DestDesc->getNumElems(); I != N; ++I) {
-      Pointer DestElem = Dest.atIndex(I);
-      TYPE_SWITCH(ET, {
-        DestElem.deref<T>() = Src.elem<T>(I);
-        DestElem.initialize();
-      });
+      TYPE_SWITCH(ET, { Dest.elem<T>(I) = Src.elem<T>(I); });
+      Dest.initializeElement(I);
     }
     return true;
   }
diff --git a/clang/test/AST/ByteCode/codegen.cpp 
b/clang/test/AST/ByteCode/codegen.cpp
index c2d2a6ef22bdc..972d883ce1d73 100644
--- a/clang/test/AST/ByteCode/codegen.cpp
+++ b/clang/test/AST/ByteCode/codegen.cpp
@@ -148,3 +148,5 @@ X test24() {
 // CHECK: _Z6test24v
 // CHECK-NOT: eh.resume
 // CHECK-NOT: unreachable
+
+auto MemcpySemantics = *(_Complex double *)&(float[2]){};

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

Reply via email to