llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.52k stars 11.79k forks source link

clang -Wunknown-pragmas shouldn't warn about a '#pragma GCC diagnostic' it doesn't know #25810

Open seanm opened 8 years ago

seanm commented 8 years ago
Bugzilla Link 25436
Version trunk
OS All
CC @brooksmoses,@zygoloid,@Weverything

Extended Description

If clang r252202 encounters this:

pragma GCC diagnostic ignored "-Wlarger-than="

it warns:

test.c:1:32: warning: unknown warning group '-Wlarger-than=', ignored [-Wunknown-pragmas]

pragma GCC diagnostic ignored "-Wlarger-than="

                           ^

GCC has a -Wlarger-than= warning, clang does not (itself bug #​10623).

I realize I'm sorta asking for such warnings by specifying -Wunknown-pragmas, but I think this is a bit different. Ordinarily, I would guard complier/platform-specific pragmas with something like:

if GNUC

but that won't help because clang (incompletely) pretends to be GCC. (And -Wlarger-than= is in gcc 4.2, so adding version checks won't help.)

I guess the only workaround for portable code is something like:

if GNUC && !clang

Basically, I see little value in -Wunknown-pragmas warning that clang's GCC emulation is not 100%. Perhaps a special case for "#pragma GCC"? Or whitelist known GCC warning flags that clang doesn't support?

behdad commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#50006

95fadc6e-27a4-4ec4-8170-f8709f580b54 commented 4 years ago

This is still happening with trunk, although now it blames the warning on -Wunknown-warning-option (at least in my case).

This is preventing us from compiling NumPY with -Wunknown-warning-option turned on, because of this line: https://github.com/numpy/numpy/blob/master/numpy/linalg/umath_linalg.c.src#L734

numpy/linalg/umath_linalg.c.src:744:32: error: unknown warning group '-Wmaybe-uninitialized', ignored [-Werror,-Wunknown-warning-option]

pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

                           ^

1 error generated.

seanm commented 5 years ago

Just a note to say issue still occurs with trunk 347180.

Interestingly, if one passes "-Wlarger-than=3000" to clang it doesn't complain that the flag is unknown (for gcc compatibility no doubt), so why inconsistently complain in the pragma case?