[clang] [Clang] Add MaterializeTemporaryExpr for __builtin_bit_cast on lvalues (PR #219646)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 29 00:27:25 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Sangam Paudel (sangam151)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/219646.diff
1 Files Affected:
- (modified) clang/lib/Sema/SemaCast.cpp (+7)
``````````diff
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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/219646
More information about the cfe-commits
mailing list