This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by balazske on Mar 4 2021, 8:53 AM.

Details

Summary

Add a new feature to display the call chain if an unsafe function is
found in a signal handler or function called from it.
Warning messages are improved too.

Diff Detail

Event Timeline

balazske created this revision.Mar 4 2021, 8:53 AM
balazske requested review of this revision.Mar 4 2021, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2021, 8:53 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This needs tests demonstrating the notes. The defacto way is to replace all CHECK-MESSAGESDirectives with CHECK-NOTES. This'll for file check to look for lines containing note.

I tried to test the notes but could not get it to work. I think the problem is related to the fact that the notes are displayed at different locations that are past or before the current warning. The solution could be to manually specify line numbers in the CHECK-NOTE parts but I do not like this (and did not tried it). Or is there other solution?

The issue is FileCheck expects its directives to be in order they appear in the file being checked. Notes are always emitted just after the warning they are attached to.
So there are a few ways to go:

  • use CHECK-NOTES-DAG to disregard the ordering and place them next to the location of the note in the code, to give correct line information.
  • place the CHECK-NOTES directly after the warning they are attached.

Going with the first option makes it much harder to reason about.
Going with the second option you'll either have to just put a generic number regex for the line number, use (potentially large) relative @LINE offsets or absolute line numbers.

balazske updated this revision to Diff 329017.Mar 8 2021, 7:51 AM

Adding test of notes.
Tests are re-arranged significantly.

I think call stack may be useful for other checks too. May be code should be moved to utilities?

Eugene.Zelenko edited reviewers, added: hokein; removed: Eugene.Zelenko.Mar 8 2021, 9:11 AM
Eugene.Zelenko added a project: Restricted Project.

I think call stack may be useful for other checks too. May be code should be moved to utilities?

Yes it is useful for other checks, but the code here is specialized for this problem only. It is possible to make a call graph that stores the "parents" of the calls, probably root items that are of a special kind, and can add notes for call chain. But there is already a clang::CallGraph that can compute call graph, if I remember correctly it was not usable here because the parent node (caller) is not available. That CallGraph could be extended too.

So, about the tests, gentle ping @njames93

balazske abandoned this revision.Jan 26 2022, 2:35 AM

A new implementation is in D118224.