[Bug tree-optimization/126848] New: Repeated reads of an indeterminate value do not yield the same value

"peppe at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126848

            Bug ID: 126848
           Summary: Repeated reads of an indeterminate value do not yield
                    the same value
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peppe at gcc dot gnu.org
  Target Milestone: ---

Consider this testcase:

```
[[gnu::noipa]] 
int g(int c) 
{
    int a;
    int x = c ? a : 1;
    return x - a;
}

int main() 
{ 
    return g(1);
} 
```

On GCC 16.2 with -std=c++26 -O2, this program exits with 1. 

Shouldn't it exit with 0? It is my understanding that, under P2795R5 / C++26
rules (implemented in GCC 16), re-reading the same indeterminate value is
indeed erroneous behavior, but it must still yield the same value back:
https://eel.is/c++draft/basic.indet#example-1

This means that `x-a` must be 0 if `c` is true, no matter what's the erroneous
value of `a`.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.