This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Improve C++ support in bugprone-signal-handler.
AbandonedPublic

Authored by balazske on Nov 10 2020, 7:04 AM.

Details

Summary

Check for namespaces and lambda signal handler was added.

Diff Detail

Event Timeline

balazske created this revision.Nov 10 2020, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 10 2020, 7:04 AM
balazske requested review of this revision.Nov 10 2020, 7:04 AM
balazske edited projects, added Restricted Project; removed Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2021, 7:40 AM
njames93 added inline comments.Mar 1 2021, 10:18 AM
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
100–101

What happens differently in c++17 and later?

137

Why can't c++ linkage functions be used a signal handlers.
This is also not sticking to the documentation of this check. Ths documentation just lists that it guards against non asynchronous-safe functions being called from signal handlers.

241–242

Why can't lambdas be used as signal handlers, If they are stateless they can be implicitly converted to function pointers. Or is this something about needing C linkage?

balazske added inline comments.Mar 2 2021, 1:05 AM
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
100–101

The plan is to add later features to the checker that check different restrictions on the signal handler function. These restrictions may differ in C++14 and C++17 (cppreference.com tells about the difference too, and CERT rule MSC54-CPP). I do not want to make the checker valid for C++17 and later restrict it to C++14 again (if C++14 but not C++17 features are added). (It is not exactly clarified which aspects of the restrictions are to be checked in the checker.) In the current state the allowed callable functions seems to be the same for C++11 and later (this is defined by POSIX).

137

The checker documentation will be fixed. For C++14 the "common subset of C and C++" is allowed to be used as signal handler (but not for C++17) and only C linkage. For C++17 it is not clear if C++ linkage is allowed, and it is not clear if calling functions with C++ linkage is allowed from the signal handler.

241–242

I suspect that the problem is the C linkage.

balazske added a reviewer: jfb.Mar 2 2021, 2:17 AM
balazske abandoned this revision.Feb 22 2022, 2:06 AM

Newer revision: D118996