This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Change code of SignalHandlerCheck (NFC).
ClosedPublic

Authored by balazske on Jan 23 2022, 11:59 PM.

Details

Summary

Using clang::CallGraph to get the called functions.
This makes a better foundation to improve support for
C++ and print the call chain.

Diff Detail

Event Timeline

balazske created this revision.Jan 23 2022, 11:59 PM
balazske requested review of this revision.Jan 23 2022, 11:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2022, 11:59 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

The plan is to take over functionality from D91164, D97960 and D33825 after this change.

Thanks for the cleanup, I like the direction this is heading. But is this actually NFC? I thought using a CallGraph would change the behavior in code like:

if (false) { // Statically known never to take this branch
  bad_call(); // Used to diagnose, does it still?
}

but I could be remembering incorrectly.

clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
129

Should we also assert that this matcher is triggered before any other matcher is matched?

Alternatively, instead of matching on the TU decl itself, would it make sense to walk the decl contexts up to the TU level on the first match?

njames93 added inline comments.Jan 24 2022, 12:55 PM
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
129

The nicest solution would be to change the OnStartOfTranslationUnit callback to pass the ASTContext. That way checks which require setup code like this don't need to register matchers.
However this would be a breaking change.

balazske updated this revision to Diff 402832.Jan 25 2022, 3:38 AM

Added tests to check more specific behavior.
Removed AST matcher of TU.

balazske marked 2 inline comments as done.Jan 25 2022, 3:45 AM

The CallGraph just scans for FunctionDecl and CallExpr, no check for unreachable code is there.

clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
129

Call graph is now populated at the first normal match, no need for the additional AST matcher.

aaron.ballman accepted this revision.Jan 25 2022, 5:39 AM

LGTM aside from a commenting nit. Thanks!

clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
136
This revision is now accepted and ready to land.Jan 25 2022, 5:39 AM
balazske updated this revision to Diff 402881.Jan 25 2022, 6:02 AM
balazske marked an inline comment as done.

Corrected a comment.

balazske marked an inline comment as done.Jan 25 2022, 6:02 AM
This revision was landed with ongoing or failed builds.Jan 25 2022, 6:54 AM
This revision was automatically updated to reflect the committed changes.