https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93051

--- Comment #1 from Alexander Cherepanov <ch3root at openwall dot com> ---
Example with a restricted pointer (dom2):

----------------------------------------------------------------------
#include <stdio.h>

__attribute__((noipa,optnone)) // imagine it in a separate TU
static void *opaque(void *p) { return p; }

__attribute__((noipa)) // imagine it in a separate TU
static void f(int *restrict p, int *restrict q)
{
    int *r = opaque(p); // hide provenance of p
    if (r == q) {
        *p = 1;
        *r = 2;
        printf("result: %d\n", *p);
    }

    opaque(q);
}

int main()
{
    int x;
    f(&x, &x);
}
----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -Wno-attributes test.c && ./a.out
test.c: In function ‘main’:
test.c:22:7: warning: passing argument 1 to ‘restrict’-qualified parameter
aliases with argument 2 [-Wrestrict]
   22 |     f(&x, &x);
      |       ^~  ~~
result: 2
$ gcc -std=c11 -pedantic -Wall -Wextra -Wno-attributes -O3 test.c && ./a.out
test.c: In function ‘main’:
test.c:22:7: warning: passing argument 1 to ‘restrict’-qualified parameter
aliases with argument 2 [-Wrestrict]
   22 |     f(&x, &x);
      |       ^~  ~~
result: 1
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.0 20191223 (experimental)
----------------------------------------------------------------------

Strictly speaking this example is not about provenance (both pointers have the
same provenance) but, for the optimizer, different restricted pointers probably
play similar roles.

Despite the warning, equal restricted pointers are fine per se -- see, e.g.,
Example 3 in C11, 6.7.3.1p10.

Reply via email to