https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/132427

>From 72aafcc255bbcfccb3fa5317e260faf97a3dfed5 Mon Sep 17 00:00:00 2001
From: kr-2003 <kumar.kr.abhi...@gmail.com>
Date: Fri, 21 Mar 2025 20:45:11 +0530
Subject: [PATCH 1/3] [clang][analyzer] Removed warnings for unnamed bitfields

---
 .../UninitializedObject/UninitializedObjectChecker.cpp        | 4 ++++
 1 file changed, 4 insertions(+)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 6e1222fedad3e..bf954c3711309 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -332,6 +332,10 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
     }
 
     if (isPrimitiveType(T)) {
+      if (I->isUnnamedBitField()) {
+        IsAnyFieldInitialized = true;
+        continue;
+      }
       if (isPrimitiveUninit(V)) {
         if (addFieldToUninits(LocalChain.add(RegularField(FR))))
           ContainsUninitField = true;

>From ff01085e3e7aaab4a5dd54e69b3f5be19d43001f Mon Sep 17 00:00:00 2001
From: kr-2003 <kumar.kr.abhi...@gmail.com>
Date: Fri, 21 Mar 2025 22:46:33 +0530
Subject: [PATCH 2/3] removed IsAnyFieldInitialized after isUnnamedBitField

---
 .../Checkers/UninitializedObject/UninitializedObjectChecker.cpp  | 1 -
 1 file changed, 1 deletion(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index bf954c3711309..bf7759975b3ec 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -333,7 +333,6 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 
     if (isPrimitiveType(T)) {
       if (I->isUnnamedBitField()) {
-        IsAnyFieldInitialized = true;
         continue;
       }
       if (isPrimitiveUninit(V)) {

>From fdff9198f3355ff2f27da5f8682875ba500cbeb9 Mon Sep 17 00:00:00 2001
From: kr-2003 <kumar.kr.abhi...@gmail.com>
Date: Sat, 22 Mar 2025 03:34:17 +0530
Subject: [PATCH 3/3] added regression tests for unnamed bitfield

---
 .../Analysis/cxx-uninitialized-object.cpp     | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/clang/test/Analysis/cxx-uninitialized-object.cpp 
b/clang/test/Analysis/cxx-uninitialized-object.cpp
index e3fa8ae8d7f29..43b1628388509 100644
--- a/clang/test/Analysis/cxx-uninitialized-object.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object.cpp
@@ -1182,3 +1182,24 @@ void fComplexTest() {
   // TODO: we should emit a warning for x2.x and x2.y.
   ComplexUninitTest x2;
 }
+
+struct PaddingBitfieldTest {
+  int a;
+  long long : 7; // padding, previously flagged as uninitialized
+  PaddingBitfieldTest(int a) : a(a) {}
+};
+
+void fPaddingBitfieldTest() {
+  PaddingBitfieldTest pb(42);
+  // no-warning: Unnamed bitfield is now ignored, fixing false positive
+}
+
+struct NamedBitfieldTest {
+  int b; 
+  long long named : 7; // expected-note{{uninitialized field 'this->named'}}
+  NamedBitfieldTest(int b) : b(b) {} // expected-warning{{1 uninitialized 
field at the end of the constructor call}}
+};
+
+void fNamedBitfieldTest() {
+  NamedBitfieldTest nb(42); 
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to