https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96672
Bug ID: 96672
Summary: Missing -Wclobbered diagnostic, or:
__attribute__((returns_twice)) does not inhibit
constant folding across call site
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: felix.von.s at posteo dot de
Target Milestone: ---
Created attachment 49072
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49072&action=edit
Sample program
The attached sample, compiled with -O3 -DVOLATILE= outputs 5; without either
flag it outputs 6.
I expected at least one of the following:
- that the compiler warn about the clobbered x variable at the return
statement;
- that the program output 6 whether or not x is declared volatile.
Currently neither is the case; compiling with -Wall -Wextra -Wclobbered emits
no warnings. While the standard mandates that the variable be declared
volatile, GCC seems to make some effort to preserve the expected semantics even
when this requirement is not met; this would seem like a missed case.