This is an archive of the discontinued LLVM Phabricator instance.

[scan-build] fix warnings emitted on Clang CodeGen code base
Needs ReviewPublic

Authored by apelete on May 5 2016, 3:15 AM.

Details

Reviewers
dblaikie
pcc
Summary

Fix "Logic error" warnings of the type "Called c++ object pointer is
null" reported by Clang Static Analyzer on the following files:

  • lib/CodeGen/CGDebugInfo.cpp,
  • lib/CodeGen/CodeGenModule.cpp.

Signed-off-by: Apelete Seketeli <apelete@seketeli.net>

Diff Detail

Event Timeline

apelete updated this revision to Diff 56254.May 5 2016, 3:15 AM
apelete retitled this revision from to [scan-build] fix warnings emitted on Clang CodeGen code base.
apelete added reviewers: dblaikie, pcc.
apelete updated this object.
apelete added a subscriber: cfe-commits.
dblaikie added inline comments.May 5 2016, 10:58 AM
lib/CodeGen/CGDebugInfo.cpp
1317

It looks like this assertion could actually be a different assertion a little higher up.

For 'V' to be non-null, one of the if/else if chain above must fire.

So change the last else if to an else, and the dyn_cast to a cast, and the cast will fail an internal assertion if it's not valid (& the analyzer can easily then see that at least one of the assignments to V happens - whether or not the analyzer assumes that all the initializers of V are non-null, that's a separate issue...)

lib/CodeGen/CodeGenModule.cpp
2302

Again, a bit confused about whether you're proposing fixing nearly every pointer parameter in Clang and LLVM to assert non-null... I think we'd need a discussion about what that looks like.

apelete added inline comments.May 9 2016, 4:38 AM
lib/CodeGen/CGDebugInfo.cpp
1317

I do not understand what you are suggesting here.
Are you suggesting I should try those changes and see for myself that at least one of the assignments to V actually happens (which would mean that the warning is a false positive), or are you suggesting that the right way to fix it is to remove the assert and replace the last 'else if' construct with an 'else' ?

lib/CodeGen/CodeGenModule.cpp
2302

Sorry my intentions were not clear.
The only function pointer parameters I'm asserting are the ones that trigger a warning when running scan-build.
This might not be the right way to fix the issue, I will be waiting for you advice in that case (please have a look at my reply to your concern on the mailing list).