This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Disable LLVM_ENABLE_PEDANTIC by default for GCC
AbandonedPublic

Authored by MaskRay on Feb 1 2022, 1:53 PM.

Details

Reviewers
mstorsjo
Summary

Motivated by D118551:
warning: ISO C++11 requires at least one argument for the "..." in a variadic macro
cannot be suppressed by #pragma GCC diagnostic ignored "-Wpedantic".
(no diagnostic in -std=c++20 mode)

We don't keep warning cleanliness as strict with GCC anyway.

Diff Detail

Event Timeline

MaskRay created this revision.Feb 1 2022, 1:53 PM
MaskRay requested review of this revision.Feb 1 2022, 1:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2022, 1:53 PM
MaskRay edited the summary of this revision. (Show Details)Feb 1 2022, 1:54 PM

In compiler-rt (and other places with unittests) we've used SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG [1] to detect and suppress variadic macro warnings on gcc. Is that a viable approach for the motivating change?

[1] https://github.com/llvm/llvm-project/blob/db8ef9463ce14f7de0e0a9f438b5e91425fba3a3/llvm/cmake/modules/AddLLVM.cmake#L1475

In compiler-rt (and other places with unittests) we've used SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG [1] to detect and suppress variadic macro warnings on gcc. Is that a viable approach for the motivating change?

[1] https://github.com/llvm/llvm-project/blob/db8ef9463ce14f7de0e0a9f438b5e91425fba3a3/llvm/cmake/modules/AddLLVM.cmake#L1475

-Wno-gnu-zero-variadic-macro-arguments is Clang specific. lld/ELF can add something like -Wno-pedantic but it just seems to add CMake complexity to a toplevel project.
It seems to me that genuine issues detected by gcc -pedantic but not clang -pedantic are rare enough that we probably should just not bother with gcc -pedantic if it is not suppressable by a pragma.

It seems to me that genuine issues detected by gcc -pedantic but not clang -pedantic are rare enough that we probably should just not bother with gcc -pedantic if it is not suppressable by a pragma.

I tried to look into the actual total number of warnings when building with GCC (a pretty much default build of LLVM with cmake on Ubuntu 18.04 and 20.04); while it's not warning free, the numbers of warnings with a recent distro isn't that bad. Building LLVM 13 (clang, lld, lldb enabled) with GCC 9.3 (Ubuntu 20.04) produces 16 warnings - building the current LLVM 14 branch produces 20 warnings. So it's not all that horrible - I just reacted to the fact that there were new warnings I hadn't seen before. (If building with GCC 7.5 from Ubuntu 18.04, LLVM 13 produces 64 warnings though, and LLVM 14 produces 72 warnings, so that's not quite as clean - but that's also a much older compiler.)

If disabling LLVM_ENABLE_PEDANTIC when building LLVM 14, the total number of warnings produced by GCC only drops by 7 (to 13 warnings with GCC 9.3) - only those 7 new warnings in lld are removed.

So I'm a little undecided about this patch - do we risk losing other useful warnings? Maybe not, if the only thing we currently lose are these new ones in ldd - as we've fixed everything else.

But we do occasionally run into cases where the GCC build warns about small syntax issues that apparently don't warn in clang builds (that often are fixed by me/someone else within a couple hours or so), not sure if we'd lose those too. At least one recent such case that I checked wasn't affected by LLVM_ENABLE_PEDANTIC.

In the end, I think I'm leaning towards wanting this patch though.

MaskRay abandoned this revision.Jul 1 2022, 10:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2022, 10:38 AM
Herald added a subscriber: StephenFan. · View Herald Transcript