https://github.com/AhmedKamel10 updated 
https://github.com/llvm/llvm-project/pull/225597

>From 24f6a72b872a1ee6ef34435e2ffe55cb6661714a Mon Sep 17 00:00:00 2001
From: ahmedkamel10 <[email protected]>
Date: Wed, 23 Sep 2026 07:53:34 +0300
Subject: [PATCH 1/2] [Clang] Fix integer promotion of bit-fields in statement
 expressions

---
 clang/lib/AST/Expr.cpp      | 7 +++++++
 clang/test/Sema/stmtexprs.c | 9 +++++++++
 2 files changed, 16 insertions(+)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 6ce0a29aa3bd78..728be799c50a39 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4273,6 +4273,13 @@ FieldDecl *Expr::getSourceBitField() {
       break;
   }
 
+  if (StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
+    CompoundStmt *CS = SE->getSubStmt();
+    if (ValueStmt *VS = dyn_cast_or_null<ValueStmt>(CS->body_back()))
+      if (Expr *EX = VS->getExprStmt())
+        return EX->getSourceBitField();
+  }
+
   if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
     if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
       if (Field->isBitField())
diff --git a/clang/test/Sema/stmtexprs.c b/clang/test/Sema/stmtexprs.c
index 7493bbcef363d9..b5fd9c21226b44 100644
--- a/clang/test/Sema/stmtexprs.c
+++ b/clang/test/Sema/stmtexprs.c
@@ -7,3 +7,12 @@ void stmtexprs(int i) {
   // expected-warning@+1 {{assumption is ignored because it contains 
(potential) side-effects}}
   __builtin_assume( ({ if (i) ({ stmtexpr_fn(); }); 1; }) );
 }
+
+struct S {
+  unsigned b : 3;
+};
+
+void test_bitfield_promotion(struct S s) {
+  _Static_assert(_Generic(+({ s.b; }), int: 1, unsigned: 2) == 1,
+                 "bit-field in statement expression should be promoted");
+}

>From 4b9f66f2e61fafb612f46ea22b52e051a64a3d30 Mon Sep 17 00:00:00 2001
From: ahmedkamel10 <[email protected]>
Date: Wed, 23 Sep 2026 17:39:20 +0300
Subject: [PATCH 2/2] Add release note and additional test coverage for
 bit-field promotion in statement expressions

---
 clang/docs/ReleaseNotes.md  | 5 ++++-
 clang/test/Sema/stmtexprs.c | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index e5da258b9950a3..18003de80b08e1 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -548,7 +548,10 @@ features cannot lower the translation-unit ABI level;
 - Fixed an ICE hat occurred when using `__imag int/float` as lvalue in 
assignment. (#GH119498)
 - Fixed an assertion failure in `-Wsign-compare` when a negated or 
complemented vector of unsigned integers was compared against a signed 
constant. (#GH203575)
 - Fixed an assertion failure when a constant statement expression that 
declares a variable is used as a bound of an OpenMP loop. A statement 
expression in a bound of a non-rectangular loop is now diagnosed. (#GH153987)
-
+- Fixed a bug where a bit-field accessed as the result of a statement 
expression
+  (e.g. `({ s.b; })`) was not subject to integer promotion, unlike an ordinary
+  bit-field access. (#GH221542)
+  
 #### Bug Fixes to Compiler Builtins
 
 - Fixed a crash when classifying a call to a builtin with dependent arguments,
diff --git a/clang/test/Sema/stmtexprs.c b/clang/test/Sema/stmtexprs.c
index b5fd9c21226b44..baddba18445c82 100644
--- a/clang/test/Sema/stmtexprs.c
+++ b/clang/test/Sema/stmtexprs.c
@@ -15,4 +15,10 @@ struct S {
 void test_bitfield_promotion(struct S s) {
   _Static_assert(_Generic(+({ s.b; }), int: 1, unsigned: 2) == 1,
                  "bit-field in statement expression should be promoted");
+  _Static_assert(_Generic(+s.b, int: 1, unsigned: 2) == 1,
+                 "ordinary bit-field access should be promoted");
+  _Static_assert(_Generic(({ s.b; }), int: 1, unsigned: 2) == 2,
+                 "bit-field in statement expression without unary + should not 
be promoted");
+  _Static_assert(_Generic(s.b, int: 1, unsigned: 2) == 2,
+                 "ordinary bit-field access without unary + should not be 
promoted");
 }

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

Reply via email to