[PATCH] D51866: [analyzer][UninitializedObjectChecker] New flag to ignore guarded uninitialized fields

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 8 02:35:58 PDT 2018


xazax.hun added inline comments.


================
Comment at: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp:501
+  auto FieldAccessM = memberExpr(hasDeclaration(equalsNode(FD))).bind("access");
+  // TODO: Should we only regard asserts as guards, or maybe something else too?
+  auto GuardM = callExpr(callee(functionDecl(hasName("assert")))).bind("guard");
----------------
I would consider any access that is guarded by if, ternary operator, switch as a guard.

For example I would consider field guarded in the following method:
```
int *method() {
  return cond ? field : nullptr;
}
```

But unguarded in this:
```
int *method() {
  return field ? field2 : nullptr;
}
```

Also, knowing that a variable is guarded or not might be a useful heuristic for other checks too. So if you do plan to cover all those cases. I would recommend to implement it outside of this check so other checks might also leverage this functionality.


https://reviews.llvm.org/D51866





More information about the cfe-commits mailing list