[clang] [clang][bytecode] Check floating-point semantics in `Memcpy` op (PR #202204)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 7 19:35:01 PDT 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/202204
>From 196ecbd6f32196e85b466514d3187be4a7f19f96 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
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 | 3 +++
2 files changed, 14 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..1b846baadc7b4 100644
--- a/clang/test/AST/ByteCode/codegen.cpp
+++ b/clang/test/AST/ByteCode/codegen.cpp
@@ -148,3 +148,6 @@ X test24() {
// CHECK: _Z6test24v
// CHECK-NOT: eh.resume
// CHECK-NOT: unreachable
+
+/// Used to crash in codegen because the cast worked.
+auto MemcpySemantics = *(_Complex double *)&(float[2]){};
More information about the cfe-commits
mailing list