https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102276
Bug ID: 102276
Summary: -ftrivial-auto-var-init fails to initialize a
variable, causes a spurious warning
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: amonakov at gcc dot gnu.org
Target Milestone: ---
int g(int *);
int f1()
{
switch (0) {
int x;
default:
return g(&x);
}
}
int f2()
{
goto L;
{
int x;
L:
return g(&x);
}
}
Compiling with -O2 -ftrivial-auto-var-init=pattern causes spurious
warning: statement will never be executed [-Wswitch-unreachable]
5 | int x;
| ^
In both f1 and f2, resulting assembly does not in fact initialize 'x':
f1:
subq $24, %rsp
leaq 12(%rsp), %rdi
call g
addq $24, %rsp
ret
f2:
subq $24, %rsp
leaq 12(%rsp), %rdi
call g
addq $24, %rsp
ret