Fix false negative on NilArgChecker when creating literal object, such as @[nullableObject].
I don't have commit access.
Differential D152269
[StaticAnalyzer] Fix false negative on NilArgChecker when creating literal object tripleCC on Jun 6 2023, 7:12 AM. Authored by
Details Fix false negative on NilArgChecker when creating literal object, such as @[nullableObject]. I don't have commit access.
Diff Detail
Event Timeline
Comment Actions I had some improvement opportunities in mind scattered, so I decided to do them, and here is how the diff looks for me now: Basically, I reworked the two branches a bit to express the intent more strait forward. I'm also testing that the "assumption" after the objc call thingie (message passing?) the pointer is assumed to be "nonnull". For this, I'm using the eagerly-assume=false to ensure we don't split null and non-null states eagerly when we encounter the p == nil inside clang_analyzer_eval() call argument. I think all my changes are aligned with your intent, right? One more thing I was thinking of was to make this ObjC null checking checker depend on the "nullability" checker package, but it turns out we can only depend on individual checkers as of now. I tried some ideas there, e.g. depending on the base checker of that package but it didn't work, so I dropped the idea. (clang/include/clang/StaticAnalyzer/Checkers/Checkers.td) Do you plan to contribute more ObjC-related fixes in the future? And I also wanted to thank you for the high-quality patches you submitted so far! Comment Actions Yes, your changes are aligned with my intent. It seems like you have made excellent optimizations to this patch. + MyView *view = b ? [[MyView alloc] init] : 0; // expected-warning {{Potential leak of an object stored into 'view'}} + NSMutableArray *subviews = [[view subviews] mutableCopy]; // expected-warning {{Potential leak of an object stored into 'subviews'}} I will continue to contribute more ObjC-related fixes in the future, and currently, my work is also related to this. Comment Actions I think we shouldn't add the -fobj-arc as these two new issues are considered TPs, and meaningful for the test file they are part of. It's just that they are not that meaningful in the scope of this patch, but that shouldn't hold us back from improving what the test covers and demonstrates, so I'm fine if those two appear as part of this patch.
Sounds good. Thanks for clarifying.
I don't mind. You don't need to give attribution. Keep parts of the whole as you wish. Comment Actions Thanks. By the way , there are already other unit tests focus on leak scenarios, such as the retain-release*.m test cases. Should we focus on testing container issues here? Currently, Objective-C code almost always uses ARC (Automatic Reference Counting). Comment Actions T Both makes sense. You can probably better judge this. I'm totally fine with any of the two options. One note, clang-format the affected lines. |
This means that we would raise an issue if ArgSVal might be null. We usually warn if we are sure there is a bug, aka. if it must be null. Consequently, the condition should be rather StNull && !StNonNull instead of just StNull.