https://github.com/BStott6 updated 
https://github.com/llvm/llvm-project/pull/166798

>From eab7dd02ab238c0029c2f0fc9a7f8f3ce1ab055c Mon Sep 17 00:00:00 2001
From: BStott <[email protected]>
Date: Thu, 6 Nov 2025 16:25:54 +0000
Subject: [PATCH 1/3] [Clang][CodeGen] Use EmitLoadOfLValue instead of
 EmitLoadOfScalar to get LHS for complex compound assignment

---
 clang/lib/CodeGen/CGExprComplex.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index f8a946a76554a..47435758fcde7 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -1283,7 +1283,7 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
     else
       OpInfo.LHS = EmitComplexToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc);
   } else {
-    llvm::Value *LHSVal = CGF.EmitLoadOfScalar(LHS, Loc);
+    llvm::Value *LHSVal = CGF.EmitLoadOfLValue(LHS, Loc).getScalarVal();
     // For floating point real operands we can directly pass the scalar form
     // to the binary operator emission and potentially get more efficient code.
     if (LHSTy->isRealFloatingType()) {

>From ab4e0ee3d2004f8f53f80764329d45aa5359268b Mon Sep 17 00:00:00 2001
From: BStott <[email protected]>
Date: Fri, 7 Nov 2025 16:39:58 +0000
Subject: [PATCH 2/3] Replace EmitStoreOfScalar with EmitStoreThroughLValue too

---
 clang/lib/CodeGen/CGExprComplex.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index 47435758fcde7..d281c4c20616a 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -1318,7 +1318,7 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
   } else {
     llvm::Value *ResVal =
         CGF.EmitComplexToScalarConversion(Result, OpInfo.Ty, LHSTy, Loc);
-    CGF.EmitStoreOfScalar(ResVal, LHS, /*isInit*/ false);
+    CGF.EmitStoreThroughLValue(RValue::get(ResVal), LHS, /*isInit*/ false);
     Val = RValue::get(ResVal);
   }
 

>From 5a203e606a45852242bec4bcab579ef97d35062a Mon Sep 17 00:00:00 2001
From: BStott <[email protected]>
Date: Mon, 10 Nov 2025 10:20:27 +0000
Subject: [PATCH 3/3] Introduce test for fixed crash

---
 .../CodeGen/2025-11-10-UBSanComplexBitfieldCrash.c     | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 clang/test/CodeGen/2025-11-10-UBSanComplexBitfieldCrash.c

diff --git a/clang/test/CodeGen/2025-11-10-UBSanComplexBitfieldCrash.c 
b/clang/test/CodeGen/2025-11-10-UBSanComplexBitfieldCrash.c
new file mode 100644
index 0000000000000..51ec1e9bc1d3f
--- /dev/null
+++ b/clang/test/CodeGen/2025-11-10-UBSanComplexBitfieldCrash.c
@@ -0,0 +1,10 @@
+// Reduced from https://github.com/llvm/llvm-project/issues/166512
+// RUN: %clang_cc1 %s -emit-obj -std=c23 -fsanitize=bool -o %t
+
+struct {
+  int : 7;
+  int : 7;
+  int : 7;
+  bool bobf : 1;
+} bits;
+int main() { bits.bobf /= __builtin_complex(.125f, .125f); }

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

Reply via email to