[clang] [clang][bytecode] Reject erroneous vector conversions (PR #201368)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 3 07:22:36 PDT 2026


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

None

>From 6669362cac4ee4360604c6d8d766429dcf8b5b8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 3 Jun 2026 16:21:23 +0200
Subject: [PATCH] [clang][bytecode] Reject erroneous vector conversions

---
 clang/lib/AST/ByteCode/Compiler.cpp |  3 +++
 clang/test/AST/ByteCode/cxx23.cpp   | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 732a9e227430c..88ed24b070bde 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4388,6 +4388,9 @@ bool Compiler<Emitter>::VisitAddrLabelExpr(const AddrLabelExpr *E) {
 
 template <class Emitter>
 bool Compiler<Emitter>::emitVectorConversion(const Expr *Src, const Expr *E) {
+  if (Src->containsErrors())
+    return false;
+
   const auto *VT = E->getType()->castAs<VectorType>();
   QualType ElemType = VT->getElementType();
   PrimType ElemT = classifyPrim(ElemType);
diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index 4619023af83e6..0050d34a47269 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -646,3 +646,17 @@ namespace DynamicCast {
   constexpr S s;
   constexpr int foo = (dynamic_cast<const S &>(s), 0);
 }
+
+#if __cplusplus >= 202302L
+namespace BrokenShuffleVector {
+  typedef float __m128 __attribute__((__vector_size__(16)));
+
+  static inline constexpr __m128 _mm_cvtps_pd(__m128 z) {
+    __builtin_convertvector(__builtin_shufflevector(z, z), __m128); // all-error {{first two arguments to '__builtin_shufflevector' must have the same type}} \
+                                                                    // all-warning {{expression result unused}}
+  }
+
+  constexpr __m128 kf1{1.0f, 2.0f, 3.0f, 4.0f};
+  constexpr __m128 v_mm_cvtps_pd = _mm_cvtps_pd(kf1); // all-error {{must be initialized by a constant expression}}
+}
+#endif



More information about the cfe-commits mailing list