[clang] [clang][bytecode] Reject vectors with non-primitive element types (PR #155597)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 27 04:30:48 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

This happens for e.g. arm's float8 types.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+8-4) 
- (modified) clang/test/CodeGenCXX/int64_uint64.cpp (+8) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 8ed9e64f5f8ff..c314f0a132196 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1376,11 +1376,17 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
 
 template <class Emitter>
 bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
   assert(!E->isCommaOp() &&
          "Comma op should be handled in VisitBinaryOperator");
   assert(E->getType()->isVectorType());
-  assert(E->getLHS()->getType()->isVectorType());
-  assert(E->getRHS()->getType()->isVectorType());
+  assert(LHS->getType()->isVectorType());
+  assert(RHS->getType()->isVectorType());
+
+  // We can only handle vectors with primitive element types.
+  if (!canClassify(LHS->getType()->castAs<VectorType>()->getElementType()))
+    return false;
 
   // Prepare storage for result.
   if (!Initializing && !E->isCompoundAssignmentOp() && !E->isAssignmentOp()) {
@@ -1391,8 +1397,6 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
       return false;
   }
 
-  const Expr *LHS = E->getLHS();
-  const Expr *RHS = E->getRHS();
   const auto *VecTy = E->getType()->getAs<VectorType>();
   auto Op = E->isCompoundAssignmentOp()
                 ? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
diff --git a/clang/test/CodeGenCXX/int64_uint64.cpp b/clang/test/CodeGenCXX/int64_uint64.cpp
index f4fd9ea76147f..8046ea9376d9e 100644
--- a/clang/test/CodeGenCXX/int64_uint64.cpp
+++ b/clang/test/CodeGenCXX/int64_uint64.cpp
@@ -6,6 +6,14 @@
 // RUN:   -target-feature +neon \
 // RUN:   -emit-llvm -w -O1 -o - %s | FileCheck --check-prefix=CHECK-AARCH64 %s
 
+// RUN: %clang_cc1 -triple arm-linux-guneabi \
+// RUN:   -target-cpu cortex-a8 -fexperimental-new-constant-interpreter \
+// RUN:   -emit-llvm -w -O1 -o - %s | FileCheck --check-prefix=CHECK-ARM %s
+
+// RUN: %clang_cc1 -triple arm64-linux-gnueabi \
+// RUN:   -target-feature +neon -fexperimental-new-constant-interpreter \
+// RUN:   -emit-llvm -w -O1 -o - %s | FileCheck --check-prefix=CHECK-AARCH64 %s
+
 // REQUIRES: aarch64-registered-target || arm-registered-target
 
 // Test if int64_t and uint64_t can be correctly mangled.

``````````

</details>


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


More information about the cfe-commits mailing list