[clang] [clang][bytecode] Reject composite copies on primitive pointers (PR #180683)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 22:11:31 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This should fail.
---
Full diff: https://github.com/llvm/llvm-project/pull/180683.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+5)
- (modified) clang/test/AST/ByteCode/complex.cpp (+9)
``````````diff
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;
+ };
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/180683
More information about the cfe-commits
mailing list