https://github.com/sangam151 created 
https://github.com/llvm/llvm-project/pull/219646

This patch fixes #219531.

__builtin_bit_cast on an lvalue, such as a vector element access (v.y),
was missing a MaterializeTemporaryExpr in the AST. This caused code
generation to load from the start of the vector instead of the
specified lane.

This patch wraps the operand in a MaterializeTemporaryExpr when it
is an lvalue, ensuring the correct lane is materialized before the
bitcast.

Tested on Windows (x64) with the provided reproducer.

>From f20b046448e53d4a7d68dfa39fc7b5a44368a5eb Mon Sep 17 00:00:00 2001
From: sangam <[email protected]>
Date: Sat, 29 Aug 2026 13:06:54 +0545
Subject: [PATCH] [Clang] Add MaterializeTemporaryExpr for __builtin_bit_cast
 on lvalues

Signed-off-by: sangam <[email protected]>
---
 clang/lib/Sema/SemaCast.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 133837623a7a6..985a50cf150b0 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -446,6 +446,13 @@ ExprResult Sema::BuildBuiltinBitCastExpr(SourceLocation 
KWLoc,
     Operand = PR.get();
   }
 
+  if (Operand->isLValue()) {
+    Operand = CreateMaterializeTemporaryExpr(Operand->getType(), Operand,
+                                             /*BoundToLvalue=*/false);
+    if (!Operand)
+      return ExprError();
+  }
+
   CastOperation Op(*this, TSI->getType(), Operand);
   Op.OpRange = CastOperation::OpRangeType(KWLoc, KWLoc, RParenLoc);
   TypeLoc TL = TSI->getTypeLoc();

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to