This is an archive of the discontinued LLVM Phabricator instance.

[clang] Suppress warnings for tautological comparison in generated macro code
Needs ReviewPublic

Authored by protze.joachim on Jun 8 2021, 4:05 AM.

Details

Summary

The warnings for some of the generated and included files can quickly fill pages and might hide serious issues. The macro purposely performs tautological comparison to filter those cases. Filtering the warning for the respective code regions seems a reasonable approach.

Diff Detail

Event Timeline

protze.joachim created this revision.Jun 8 2021, 4:05 AM
protze.joachim requested review of this revision.Jun 8 2021, 4:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2021, 4:05 AM

This sort of diagnostic suppression is not portable and will require checking for #ifdef __clang__. Personally, I'm not fond of this style of diagnostic suppression (non-portable and rather distracting due to verbosity), but I don't know that there's a better way to do the suppression in this case...

I don't think, this needs ifdefs. As I understand, a compiler is supposed to ignore unknown pragmas.
I fully agree that the suppression will not be compatible with other compilers.

I don't think, this needs ifdefs. As I understand, a compiler is supposed to ignore unknown pragmas.

It does. You can see it produces diagnostics in -Wall mode in GCC and it produces diagnostics at any warning level in MSVC or ICC (https://godbolt.org/z/58nqGx14o). We don't use it often in the code base, but the very select places we've done it, we've protected it (https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/Hexagon/HexagonDepDecoders.inc#L12, https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/StringRef.h#L878 which are the only two non-test places in the Clang + LLVM + extra code base we've done this before).

ychen added a subscriber: ychen.Jun 8 2021, 9:39 AM

We could use a table to avoid the warning and speed the build a little bit. https://reviews.llvm.org/D98110

We could use a table to avoid the warning and speed the build a little bit. https://reviews.llvm.org/D98110

That's an interesting approach, thank you for sharing it! I wonder how use of a table impacts performance given that the table is on the stack and there can be a lot of options (a bit less worried for things like OpenMP kinds or overloadable operators as those as much smaller)?

ychen added a comment.Jun 8 2021, 11:12 AM

We could use a table to avoid the warning and speed the build a little bit. https://reviews.llvm.org/D98110

That's an interesting approach, thank you for sharing it! I wonder how use of a table impacts performance given that the table is on the stack and there can be a lot of options (a bit less worried for things like OpenMP kinds or overloadable operators as those as much smaller)?

I think performance should be better if there are noticeable differences at all. The code footprint is much smaller although there are additional data loads that are most likely in the cache.