Missing -Wc23-extensions after 4c9fd71e18f211bfe7d43ef841b429a8ef94a140
I noticed that a particular instance of -Wc23-extensions in the Linux kernel was visible with LLVM 23 but not LLVM 24 (we don't see these warnings with LLVM prior to 22 because we use -fms-extensions instead of the narrower -fms-anonymous-structs introduced in LLVM 23), for which I bisected to https://github.com/llvm/llvm-project/commit/4c9fd71e18f211bfe7d43ef841b429a8ef94a140 as the culprit commit.
void foo(int *);
void bar(void)
{
int a;
foo(&a);
switch (a) {
case 0:
int b = 0;
foo(&b);
case 1:
int c = 2;
foo(&c);
}
}
With LLVM 23.1.3
$ clang -Wall -Wextra -std=gnu11 -fsyntax-only test.c
test.c:8:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
8 | int b = 0;
| ^
test.c:11:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
11 | int c = 2;
| ^
2 warnings generated.
With LLVM post 4c9fd71e18f211bfe7d43ef841b429a8ef94a140
$ clang -Wall -Wextra -std=gnu11 -fsyntax-only test.c
$ git bisect log
# bad: [1ae71725e3edb2bb5c5bed7f2cff9d2f22e10636] LLVMgold: Parse -plugin-opt options into LibraryOptionsContext (#233144)
# good: [6af0a79d7a4e8558e89290df56491521c6730acd] Bump version to 24.0.0git (#209473)
git bisect start '1ae71725e3edb2bb5c5bed7f2cff9d2f22e10636' 'llvmorg-24-init'
# bad: [0d4ed3cdbe004e07d441e7e2d62d1b9a13bcf07f] [InstCombine] Evaluate zext nneg as sext where possible (#212230)
git bisect bad 0d4ed3cdbe004e07d441e7e2d62d1b9a13bcf07f
# good: [7214eb03c28238b89b6ba7e6d56b67359d6cf79e] [MLIR][Mem2Reg] Add support for memref.alloca_scope (#214221)
git bisect good 7214eb03c28238b89b6ba7e6d56b67359d6cf79e
# good: [ea3bbd57e9c1c7b39311f4fa1143f1683f1e6afe] [RISCV][NFCI] Introduce Base for Pseudo Expansion Passes (#218170)
git bisect good ea3bbd57e9c1c7b39311f4fa1143f1683f1e6afe
# good: [f4a4a1dedda89cc937432193cfcab5d1e3cc9396] [flang][test] Extend coverage for procedure-valued function results (#219477)
git bisect good f4a4a1dedda89cc937432193cfcab5d1e3cc9396
# good: [baaa72f60e597919db2d119379f048ccfaf20530] [GlobalOpt] Fix crash on self-referential global (#219777)
git bisect good baaa72f60e597919db2d119379f048ccfaf20530
# bad: [c6f9cf2bf5a36e42606a684d6a0c37c005dd4bc2] [AArch64] Add Neoverse V3AE scheduling info for v264 frecpe (#219115)
git bisect bad c6f9cf2bf5a36e42606a684d6a0c37c005dd4bc2
# bad: [437f88f61b16e5564713d0058433f4b34c41bf51] [AMDGPU][SIInsertWaitcnts] Fix soft wait removal with loop-carried deps (#220357)
git bisect bad 437f88f61b16e5564713d0058433f4b34c41bf51
# good: [847eee6a93f2a57ec716a5b78ec527b9f95a64a4] Revert "[SLP]Vectorize unique scalars of splat gather nodes as separate subtrees" (#220584)
git bisect good 847eee6a93f2a57ec716a5b78ec527b9f95a64a4
# good: [54d941486fec3a81f9d8e5a595947d540eace85c] [lldb] Add generic address space support (#214089)
git bisect good 54d941486fec3a81f9d8e5a595947d540eace85c
# bad: [f62aa8433fd3e06c60baddfe5ced6824ebfcb5a4] [NFCI] Update the directive pure-emitter to skip the switch if empty (#220255)
git bisect bad f62aa8433fd3e06c60baddfe5ced6824ebfcb5a4
# bad: [34dc057c4c095dc98cbbd0b1d16c8bf6b2e18c09] [flang][cuda] Honor component CUDA attrs in assignment copies (#220398)
git bisect bad 34dc057c4c095dc98cbbd0b1d16c8bf6b2e18c09
# bad: [89b21bed656009821f8c79128e7032fdddc6689b] [libc] Stop printing \0 in stdio/fputc_test.cpp (#220544)
git bisect bad 89b21bed656009821f8c79128e7032fdddc6689b
# bad: [3ae01af71df1ab3eb868ca15297c565568019ce8] [flang][NFC] Remove dead declarations and fix include guard (#219961)
git bisect bad 3ae01af71df1ab3eb868ca15297c565568019ce8
# bad: [4c9fd71e18f211bfe7d43ef841b429a8ef94a140] [Clang] Use Compat diagnostics for most extension/compatibility warnings (#216693)
git bisect bad 4c9fd71e18f211bfe7d43ef841b429a8ef94a140
# first 'bad' commit: [4c9fd71e18f211bfe7d43ef841b429a8ef94a140] [Clang] Use Compat diagnostics for most extension/compatibility warnings (#216693)
Is this expected behavior? If so, I do not mind, as this warning is kind of pointless for the kernel since GCC 11+ supports it as an extension with no warning and LLVM < 23 will not warn because of the aforementioned -fms-extensions (meaning only GCC 8 through 10 and LLVM 23 and 24 matter for warnings/errors, which is pretty narrow) but I do not want to rely on that if it is not expected and could be fixed at some point down the line.
cc @philnik777 @AaronBallman
CC @philnik777
The warning still exists; it was just switched from ExtWarn to Extension, i.e. it only prints if you explicitly request -Wc23-extensions or -pedantic. I don't think it was intentional? At least, I don't see any discussion of it in the pull request.
I think I'm fine with the change; the construct is widely supported as an extension on modern compilers, and it's not really a big deal if you use it by accident in a project that does care about supporting older compilers.
Hi! I'm planning to work on this issue as part of the CS3423 Compilers II hackathon at IIT Hyderabad. I'd like to investigate the missing -Wc23-extensions diagnostics, implement a fix, and add the corresponding regression test. Could you please assign this issue to me? Thank you!
The discussion here might conclude that we don't want to do anything, in which case your patch won't be accepted.
If you're okay with that, go ahead, I guess.
3. Hi! I'm planning to work on this issue as part of the CS3423 Compilers II hackathon at IIT Hyderabad. I'd like to investigate the missing
-Wc23-extensionsdiagnostics, implement a fix, and add the corresponding regression test. Could you please assign this issue to me? Thank you!
I would strongly urge folks to not jump on issues and starting working on them until comments w/ maintainers have been made and the discussion has some agreement.
2. CC @philnik777 The warning still exists; it was just switched from ExtWarn to Extension, i.e. it only prints if you explicitly request -Wc23-extensions or -pedantic. I don't think it was intentional? At least, I don't see any discussion of it in the pull request. I think I'm fine with the change; the construct is widely supported as an extension on modern compilers, and it's not really a big deal if you use it by accident in a project that does care about supporting older compilers.
I'm also fine with the change in behavior here. We've been inconsistent with how we apply Extension vs ExtWarn and only recently started nailing down documented recommendations for folks: https://clang.llvm.org/docs/InternalsManual.html#extension-vs-extwarn and this is one that I think doesn't fit the suggestions for warning by default.
I would strongly urge folks to not jump on issues and starting working on them until comments w/ maintainers have been made and the discussion has some agreement.
+1, making a PR for an issue that's still under active discussion is not the end of the world but it adds friction where none is needed (it's too hard to follow bifurcated conversations happening on the PR and the issue, it spends precious reviewer time on things that may not need to be reviewed at all, etc). Better to wait for the discussion on the issue to concluded.
In this case, I believe this is not a defect, so I am closing. Feel free to continue discussing though and reopen if you think this should be changed back to a warning by default.
I didn't want to make this change, but I agree that the change fits with the guidelines written down since then, so there is no point in reverting the change now.