This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Print the offending function at EndAnalysis crash
ClosedPublic

Authored by steakhal on Jun 9 2022, 3:24 AM.

Details

Summary

I've faced crashes in the past multiple times when some
check::EndAnalysis callback caused some crash.
It's really anoying that it doesn't tell which function triggered this
callback.

This patch adds the well-known trace for that situation as well.
Example:

1.      <eof> parser at end of file
2.      While analyzing stack:
        #0 Calling test11

Note that this does not have tests.
I've considered unittests for this purpose, by using the
ASSERT_DEATH() similarly how we check double eval called functions in
ConflictingEvalCallsTest.cpp, however, that the testsuite won't invoke
the custom handlers. Only the message of the llvm_unreachable() will
be printed. Consequently, it's not applicable for us testing this
feature.

I've also considered using an end-to-end LIT test for this.
For that, we would need to somehow overload the clang_analyzer_crash()
ExprInspection handler, to get triggered by other events than the
EvalCall. I'm not saying that we could not come up with a generic way
of causing crash in a specific checker callback, but I'm not sure if
that would worth the effort.

Diff Detail

Event Timeline

steakhal created this revision.Jun 9 2022, 3:24 AM
Herald added a project: Restricted Project. · View Herald Transcript
steakhal requested review of this revision.Jun 9 2022, 3:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 3:24 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
steakhal edited the summary of this revision. (Show Details)Jun 9 2022, 3:25 AM
martong added inline comments.Jun 9 2022, 3:42 AM
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
616

Okay, so, at least we will get the name of the top-level function, right? Some comments might be useful here.

steakhal updated this revision to Diff 435532.Jun 9 2022, 6:49 AM
steakhal marked an inline comment as done.
  • Add a comment to the trace builder.
martong accepted this revision.Jun 9 2022, 6:54 AM

LGTM!

This revision is now accepted and ready to land.Jun 9 2022, 6:54 AM
This revision was landed with ongoing or failed builds.Jun 10 2022, 3:21 AM
This revision was automatically updated to reflect the committed changes.