[clang] [clang][bytecode] Check primtypes in CopyArray op (PR #195628)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 4 03:15:10 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/195628.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (+6) 
- (modified) clang/test/AST/ByteCode/vectors.cpp (+9) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index f89ff3f18ce9d..2d0efff1439b8 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -3430,6 +3430,12 @@ inline bool CopyArray(InterpState &S, CodePtr OpPC, uint32_t SrcIndex,
   if (!SrcPtr.isBlockPointer() || !DestPtr.isBlockPointer())
     return false;
 
+  const Descriptor *SrcDesc = SrcPtr.getFieldDesc();
+  const Descriptor *DestDesc = DestPtr.getFieldDesc();
+  if (!SrcDesc->isPrimitiveArray() || !DestDesc->isPrimitiveArray() ||
+      SrcDesc->getPrimType() != Name || DestDesc->getPrimType() != Name)
+    return false;
+
   for (uint32_t I = 0; I != Size; ++I) {
     const Pointer &SP = SrcPtr.atIndex(SrcIndex + I);
 
diff --git a/clang/test/AST/ByteCode/vectors.cpp b/clang/test/AST/ByteCode/vectors.cpp
index db18d8360f36a..d09e9e05cde5a 100644
--- a/clang/test/AST/ByteCode/vectors.cpp
+++ b/clang/test/AST/ByteCode/vectors.cpp
@@ -184,3 +184,12 @@ namespace CopyArrayDummy {
     *(T *)&s = (T){0, 1, 2, 3};
   }
 }
+
+namespace CopyArrayCast {
+  typedef float __m128 __attribute__((__vector_size__(16)));
+  constexpr __m128 foo{1.0f, 2.0f, 3.0f, 4.0f};
+
+  typedef long T __attribute__((vector_size(4 * sizeof(long))));
+
+  void bar(void) { *(T *)&foo = (T{0, 1, 2, 3}); }
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/195628


More information about the cfe-commits mailing list