[clang] [clang][bytecode] Reject composite copies on primitive pointers (PR #180683)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 22:10:58 PST 2026


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

This should fail.

>From 3a6d72736561bcd020635a41a9ce4593d091d3fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 10 Feb 2026 07:09:44 +0100
Subject: [PATCH] [clang][bytecode] Reject composite copies on primitive
 pointers

This should fail.
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 5 +++++
 clang/test/AST/ByteCode/complex.cpp      | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index e47fc43ee8638..3db76c7ad4b41 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -6110,6 +6110,11 @@ static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src,
 }
 
 bool DoMemcpy(InterpState &S, CodePtr OpPC, const Pointer &Src, Pointer &Dest) {
+  if (!Src.isBlockPointer() || Src.getFieldDesc()->isPrimitive())
+    return false;
+  if (!Dest.isBlockPointer() || Dest.getFieldDesc()->isPrimitive())
+    return false;
+
   return copyComposite(S, OpPC, Src, Dest);
 }
 
diff --git a/clang/test/AST/ByteCode/complex.cpp b/clang/test/AST/ByteCode/complex.cpp
index 4440f201bb059..8ae0e63886727 100644
--- a/clang/test/AST/ByteCode/complex.cpp
+++ b/clang/test/AST/ByteCode/complex.cpp
@@ -460,3 +460,12 @@ namespace Discard {
   }
   static_assert(test_side_effect() == 1);
 }
+
+namespace MemcpyOp {
+  const double x = 0.;
+
+  void foo() {
+    _Complex double z;
+    z = *(_Complex double *)&x;
+  };
+}



More information about the cfe-commits mailing list