[clang] [clang][analyzer] Fix the false positive ArgInitializedness warning on unnamed bit-field (PR #145066)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 3 07:44:40 PDT 2025
================
@@ -2122,8 +2122,21 @@ SVal RegionStoreManager::getBindingForField(RegionBindingsConstRef B,
if (const std::optional<SVal> &V = B.getDirectBinding(R))
return *V;
- // If the containing record was initialized, try to get its constant value.
+ // UnnamedBitField is always Undefined unless using memory operation such
+ // as 'memset'.
+ // For example, for code
+ // typedef struct {
+ // int i :2;
+ // int :30; // unnamed bit-field
+ // } A;
+ // A a = {1};
+ // The bits of the unnamed bit-field in local variable a can be anything.
const FieldDecl *FD = R->getDecl();
+ if (FD->isUnnamedBitField()) {
+ return UndefinedVal();
+ }
+
+ // If the containing record was initialized, try to get its constant value.
----------------
Tedlion wrote:
The continue line is added in commit 3720e2f00630ace63fbf2c8d154e340c029fc186, when the function `tryBindSmallStruct` is added. The commit log illustrates the reason for binding a LazyCompoundVal to simple struct by memberwise copy, but discusses nothing about the unnamed bit-field.
I'll make a new pull-request to fix this soon.
https://github.com/llvm/llvm-project/pull/145066
More information about the cfe-commits
mailing list