https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128916
Bug ID: 128916
Summary: [13/14/15/16/17 Regression] wrong code: &local inside
an assume attribute refers to the outlined
assumption's copy, so q == &x is folded to false and
wrong ranges are exported
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: 0599jiangyc at gmail dot com
Target Milestone: ---
The following code:
```c
/* Godbolt: x86-64 gcc (trunk), flags: -O2
Wrong code: address of a local inside an assumption refers to the outlined
assume body's by-value parameter copy, not to the caller's object.
gcc -O2 repro.c && ./a.out -> exit 1 (prints 17), expected 7.
Also -O3, -Os, -O1 -ftree-vrp. -O0/-O1: 7. clang -O2: 7.
The assumption (c > 5 || q == &x) is TRUE at run time (q == &x), so no UB.
*/
#include <stdio.h>
__attribute__((noipa)) int f(int c, int *p)
{
int x = 7;
int *q = p ? p : &x;
__attribute__((assume(c > 5 || q == &x)));
return (c > 5) * 10 + *q;
}
int main(void)
{
int r = f(0, 0);
printf("%d\n", r);
return r != 7;
}
```
Resulted in this output:
```
$ gcc -O2 repro.c && ./a.out
17
(gcc -O0 and -O1 print 7, the value the assumption-free program computes; the
C++23 [[assume]] version repro.cc behaves the same with g++ -O2)
```
Trunk: https://godbolt.org/z/z7Gvvoo4d (x86-64 gcc trunk, -O2, executed;
reproduces as of 2026-11-13; GCC 13.1, 14.1, 15.1 and 16.1 are also wrong)