Example: pointer_from_int_disambiguation_1_xy.c

up: index
prev: pointer_from_int_disambiguation_1.c
next: pointer_from_int_disambiguation_2.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    #include <stdio.h>
    #include <string.h> 
    #include <stdint.h>
    #include <inttypes.h>
    int x=1, y=2;
    int main() {
      int *p = &x+1;
      int *q = &y;
      uintptr_t i = (uintptr_t)p;
      uintptr_t j = (uintptr_t)q;
      if (memcmp(&p, &q, sizeof(p)) == 0) {
        int *r = (int *)i;
        *r=11;  // is this free of UB?
        printf("x=%d y=%d *q=%d *r=%d\n",x,y,*q,*r); 
      }
    }
[link to run test in Cerberus]

Experimental data (what does this mean?)

cerberus-concrete-concrete-permissive_pointer_arith-PVI-plain 
cerberus-concrete-concrete-permissive_pointer_arith-PVI-ae 
cerberus-concrete-permissive_pointer_arith-PVI-ae-udi 
gcc-8.3-O0 x=1 y=11 *q=11 *r=11
gcc-8.3-O2 
gcc-8.3-O3 
gcc-8.3-O2-no-strict-aliasing 
gcc-8.3-O3-no-strict-aliasing 
clang-7.0.1-O0 x=1 y=11 *q=11 *r=11
clang-7.0.1-O2 x=1 y=11 *q=11 *r=11
clang-7.0.1-O3 x=1 y=11 *q=11 *r=11
clang-7.0.1-O2-no-strict-aliasing x=1 y=11 *q=11 *r=11
clang-7.0.1-O3-no-strict-aliasing x=1 y=11 *q=11 *r=11
icc-19-O0 x=1 y=11 *q=11 *r=11
icc-19-O2 x=1 y=2 *q=2 *r=11
icc-19-O3 x=1 y=2 *q=2 *r=11
icc-19-O2-no-strict-aliasing x=1 y=2 *q=2 *r=11
icc-19-O3-no-strict-aliasing x=1 y=2 *q=2 *r=11