This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] bugprone-signal-handler improvements: display call chain
ClosedPublic

Authored by balazske on Jan 26 2022, 1:27 AM.

Details

Summary

Display notes for a possible call chain if an unsafe function is found to be
called (maybe indirectly) from a signal handler.
The call chain displayed this way includes probably not the first calls of
the functions, but it is a valid possible (in non path-sensitive way) one.

Diff Detail

Event Timeline

balazske created this revision.Jan 26 2022, 1:27 AM
balazske requested review of this revision.Jan 26 2022, 1:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2022, 1:27 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added inline comments.Jan 26 2022, 5:36 AM
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
199–200

Do we have to worry about CallLevel + 1 being negative here? (Is there a need for an assert?)

207–208

Do we have to worry about call expressions for which we cannot find the declaration (like a call through a function pointer)? (Should we add some test coverage involving a call stack with a call through a function pointer?)

clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
39–43

Might as well not make this an optional parameter -- no real benefit from it (there's only two call sites).

balazske added inline comments.Jan 26 2022, 6:42 AM
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
199–200

Really yes, but here is no assert because it is on line 161 and the function is called only there. A df_iterator path contains the start and end node, and there should be at least one function if we have any report do show, the path length should be at least 1 (make assert for that?). (Later there could be cases when the function is called with path length 1.)

207–208

A declaration should always be there in the CallGraphNode, probably not a definition. The call graph does not insert nodes for function pointer calls.

aaron.ballman added inline comments.Jan 26 2022, 7:07 AM
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
199–200

Thanks for the explanation -- an assert that the path has at least 1 element wouldn't be awful, but also doesn't seem like something we'd get a lot of value from here. It's up to you if you want to add an assert or not.

207–208

Oh! I didn't know the CallGraph didn't model calls through function pointers (I had assumed we would model that because there's still a CallExpr involved.)

Can you add a test case involving a call stack with a call through a function pointer (with comments), just to demonstrate the behavior?

njames93 added inline comments.Jan 26 2022, 8:25 AM
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
192–218

Small nit.

balazske updated this revision to Diff 403528.Jan 27 2022, 12:25 AM
balazske marked an inline comment as done.

Added assert, added test with function pointer, improved text message generation.

balazske marked 4 inline comments as done.Jan 27 2022, 12:28 AM
This revision is now accepted and ready to land.Jan 27 2022, 8:11 AM