[PATCH] D96719: [clang-tidy] Add new check 'bugprone-thread-canceltype-asynchronous' and alias 'cert-pos47-c'.
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 18 06:04:32 PST 2021
aaron.ballman added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/ThreadCanceltypeAsynchronousCheck.cpp:38
+ };
+ const auto TryExpandAsInteger =
+ [](Preprocessor::macro_iterator It) -> Optional<unsigned> {
----------------
balazske wrote:
> aaron.ballman wrote:
> > Do we know that POSIX implementations always use a simple integer here, or do we have to worry about code like:
> > ```
> > #define PTHREAD_CANCEL_ASYNCHRONOUS (1 << 0)
> > ```
> > or
> > ```
> > #define PTHREAD_CANCEL_ASYNCHRONOUS SOME_OTHER_MACRO
> > ```
> Theoretically it is possible that the macro is defined not as a simple number ([[https://pubs.opengroup.org/onlinepubs/9699919799/ | at this page ]] see "Symbolic Constant"). But I am not sure if it is possible to get the value from the preprocessor for any constant expression.
>
> There is a similar function `tryExpandAsInteger` already in clang (CheckerHelpers.cpp) that can be reused here, probably it retrieves the macro definition better. The function could be put into one of the "utils" files, maybe **LexerUtils.h**, it is already needed at 2 places (bad-signal-to-kill-thread and here).
>
Having a single place to get this information would be an improvement, but not necessary for this patch. If you don't know of a POSIX implementation that uses something other than a positive integer literal for the expansion, I think the current code is fine.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96719/new/
https://reviews.llvm.org/D96719
More information about the cfe-commits
mailing list