This is an archive of the discontinued LLVM Phabricator instance.

[scan-build] fix warnings emiited on LLVM Analysis code base
ClosedPublic

Authored by apelete on May 5 2016, 4:49 AM.

Details

Summary

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

  • lib/Analysis/ScalarEvolution.cpp,
  • lib/Analysis/LoopInfo.cpp.

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

Diff Detail

Event Timeline

apelete updated this revision to Diff 56266.May 5 2016, 4:49 AM
apelete retitled this revision from to [scan-build] fix warnings emiited on LLVM Analysis code base.
apelete added reviewers: silviu.baranga, atrick, hfinkel.
apelete updated this object.
apelete added a subscriber: llvm-commits.
sbaranga added inline comments.
lib/Analysis/LoopInfo.cpp
515

Do we really need three of these?

lib/Analysis/ScalarEvolution.cpp
5557

Maybe a more meaningful string here would be "ExitNotTakenExtras is NULL while having more than one exit".

apelete updated this revision to Diff 56590.May 9 2016, 9:34 AM

[scan-build] fix warnings emiited on LLVM Analysis code base

Changes since last revision:

  • lib/Analysis/LoopInfo.cpp: remove redundant asserts,
  • lib/Analysis/ScalarEvolution.cpp: reword assert message.
sbaranga added inline comments.May 11 2016, 7:10 AM
lib/Analysis/LoopInfo.cpp
551

Would there be any reason to have this assert here and not at the top?

apelete added inline comments.May 11 2016, 8:57 AM
lib/Analysis/LoopInfo.cpp
551

Code path that leads to "Called C++ object pointer is null" is the one inside the for() loop on line 537.
Not sure asserting outside that path would help, I'm going to verify that.

apelete added inline comments.May 11 2016, 3:07 PM
lib/Analysis/LoopInfo.cpp
551

Tested moving the assert at the top of function, and I can confirm that it has no effect on the codepath inside the for() loop at line 537.

Would you prefer to have it at the beginning of the for() loop ?

sbaranga added inline comments.May 12 2016, 2:57 AM
lib/Analysis/LoopInfo.cpp
551

Sorry for taking so long to reply. I don't fully understand how clang gets this warning, but having it at the top of the function would surely guarantee that Unloop is not null. So maybe the static analyzer is too eager?

I think it would be overall a lot better to change Unloop to be a reference (which removes this issue entirely).

apelete updated this revision to Diff 57030.May 12 2016, 6:54 AM

[scan-build] fix warnings emiited on LLVM Analysis code base

Changes since last revision:

  • lib/Analysis/LoopInfo.cpp: change 'Unloop' member of UnloopUpdater class to be a reference to avoid null pointer warning from Clang Static Analyzer.
sbaranga accepted this revision.May 12 2016, 6:56 AM
sbaranga added a reviewer: sbaranga.

Thanks, LGTM!

-Silviu

This revision is now accepted and ready to land.May 12 2016, 6:56 AM

Thanks, LGTM!

-Silviu

I don't have commit access so please go ahead and commit this for me when you're ready.

Thanks for your review.

sbaranga closed this revision.May 13 2016, 8:01 AM

Committed in r269424.