[clang] [clang][analyzer] Extend CallAndMessageChecker argument initializedness check (PR #173854)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 5 11:27:15 PST 2026


================
@@ -264,9 +292,18 @@ bool CallAndMessageChecker::uninitRefOrPointer(
   if (!ParamT->isPointerOrReferenceType())
     return false;
 
+  bool AllowPartialInitializedness = StructInitializednessComplete;
----------------
NagyDonat wrote:

This initialization confused me, because these variable names seem to be opposites:
- `AllowPartialInitializedness` is true iff the checker allows partially initialized structs (in addition to completely initialized structs, which are obviously always OK)
- `StructInitializednessComplete` is true iff the checker requires that struct initializedness must be complete, i.e. a the checker only accepts completely initialized structs as "initialized".

As I looked up the definition of that member variable it says
```c++
  /// When checking a struct value for uninitialized data, should all the fields
  /// be un-initialized or only find one uninitialized field.
  bool StructInitializednessComplete = true;
```
which means that this initialization **is** correct, but `StructInitializednessComplete` is misnamed: for me its name means the opposite of the explanatory comment.

Of course, I see that this variable was added by PR https://github.com/llvm/llvm-project/pull/164600 where I gave an approving review, so I should have said this earlier :sweat_smile: – but as a delayed review comment I'm asking you now to pick a better name for that data member.

In situations like this – when there is a hard-to-name boolean – I personally like the approach where the `bool` type is replaced by a simple enum like
```c++
enum class InitializationLevel { Uninitialized, Partial, Full };
```
and then it is possible to use variables like `InitializationLevel RequiredInitLevel` which would be self-documenting.

However, I'm also completely open to using a boolean with a better name. In fact, the name `AllowPartialInitializedness` is fairly descriptive for this boolean value, so you can switch to using that name as the name of the data member, renaming the local boolean to `AllowPartialInitializednessHere`. 

https://github.com/llvm/llvm-project/pull/173854


More information about the cfe-commits mailing list