public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104504] New: spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero
@ 2022-02-11 15:15 nsz at gcc dot gnu.org
2022-02-11 18:06 ` [Bug middle-end/104504] " kees at outflux dot net
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: nsz at gcc dot gnu.org @ 2022-02-11 15:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104504
Bug ID: 104504
Summary: spurious -Wswitch-unreachable warning with
-ftrivial-auto-var-init=zero
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: nsz at gcc dot gnu.org
Target Milestone: ---
reduced from linux code on which gcc-12 warns now:
int foo(int x) {
switch(x) {
int y;
/* spuriously warns with -ftrivial-auto-var-init=zero */
default:
y = x * 2;
return y;
}
}
$ gcc -Wall -ftrivial-auto-var-init=zero -c a.c
a.c: In function 'foo':
a.c:3:13: warning: statement will never be executed [-Wswitch-unreachable]
3 | int y;
| ^
i can see why gcc warns, but it would be better not to.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/104504] spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero
2022-02-11 15:15 [Bug middle-end/104504] New: spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero nsz at gcc dot gnu.org
@ 2022-02-11 18:06 ` kees at outflux dot net
2022-02-12 0:41 ` kees at outflux dot net
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: kees at outflux dot net @ 2022-02-11 18:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104504
Kees Cook <kees at outflux dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kees at outflux dot net
--- Comment #1 from Kees Cook <kees at outflux dot net> ---
Similar issue exists in Clang, though Clang doesn't warn:
https://github.com/llvm/llvm-project/issues/44261
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/104504] spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero
2022-02-11 15:15 [Bug middle-end/104504] New: spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero nsz at gcc dot gnu.org
2022-02-11 18:06 ` [Bug middle-end/104504] " kees at outflux dot net
@ 2022-02-12 0:41 ` kees at outflux dot net
2022-02-12 9:18 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: kees at outflux dot net @ 2022-02-12 0:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104504
--- Comment #2 from Kees Cook <kees at outflux dot net> ---
As mentioned in a Linux kernel thread, isn't it possible to transform this:
switch (x) {
int y;
default:
y = x * 2;
return y;
}
into this:
{
int y;
switch (x) {
default:
y = x * 2;
return y;
}
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/104504] spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero
2022-02-11 15:15 [Bug middle-end/104504] New: spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero nsz at gcc dot gnu.org
2022-02-11 18:06 ` [Bug middle-end/104504] " kees at outflux dot net
2022-02-12 0:41 ` kees at outflux dot net
@ 2022-02-12 9:18 ` jakub at gcc dot gnu.org
2022-02-12 18:12 ` kees at outflux dot net
2022-02-12 20:22 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-02-12 9:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104504
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
At the C/C++ level certainly not, it could be
int foo(int x, int y) {
switch (bar (x, y)) {
int y;
default:
y = x * 2;
return y;
}
}
and the inner y shouldn't be in scope of the switch control expression.
Now, for this particular case, it surely could be handled like:
auto tmp_ = bar (x, y);
{
int y;
switch (tmp_) {
default:
y = x * 2;
return y;
}
}
but I really don't understand why exactly this case should get extra special
care when
switch (x) {
case 4:
++y;
case 5:
int y;
default:
y = x * 2;
return y;
}
can't easily.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/104504] spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero
2022-02-11 15:15 [Bug middle-end/104504] New: spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero nsz at gcc dot gnu.org
` (2 preceding siblings ...)
2022-02-12 9:18 ` jakub at gcc dot gnu.org
@ 2022-02-12 18:12 ` kees at outflux dot net
2022-02-12 20:22 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: kees at outflux dot net @ 2022-02-12 18:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104504
--- Comment #4 from Kees Cook <kees at outflux dot net> ---
(Ah, I knew this had been reported before. I found it now...)
Duplicate of: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102276
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/104504] spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero
2022-02-11 15:15 [Bug middle-end/104504] New: spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero nsz at gcc dot gnu.org
` (3 preceding siblings ...)
2022-02-12 18:12 ` kees at outflux dot net
@ 2022-02-12 20:22 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-12 20:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104504
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 102276.
*** This bug has been marked as a duplicate of bug 102276 ***
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-12 20:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-11 15:15 [Bug middle-end/104504] New: spurious -Wswitch-unreachable warning with -ftrivial-auto-var-init=zero nsz at gcc dot gnu.org
2022-02-11 18:06 ` [Bug middle-end/104504] " kees at outflux dot net
2022-02-12 0:41 ` kees at outflux dot net
2022-02-12 9:18 ` jakub at gcc dot gnu.org
2022-02-12 18:12 ` kees at outflux dot net
2022-02-12 20:22 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).