Example: pointer_from_int_disambiguation_3.c

up: index
prev: pointer_from_int_disambiguation_2_xy.c
next: pointer_from_int_disambiguation_3_xy.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    #include <stdio.h>
    #include <string.h> 
    #include <stdint.h>
    #include <inttypes.h>
    int y=2, x=1;
    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;
        r=r-1;  // is this free of UB?
        *r=12;  // and this?    
        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 Undefined behaviour: out of bounds pointer at memory store at 15:5-10
cerberus-concrete-concrete-permissive_pointer_arith-PVI-ae Undefined behaviour: out of bounds pointer at memory store at 15:5-10
cerberus-concrete-permissive_pointer_arith-PVI-ae-udi Undefined behaviour: out of bounds pointer at memory store at 15:5-10
gcc-8.3-O0 
gcc-8.3-O2 x=12 y=2 *q=2 *r=12
gcc-8.3-O3 x=12 y=2 *q=2 *r=12
gcc-8.3-O2-no-strict-aliasing x=12 y=2 *q=2 *r=12
gcc-8.3-O3-no-strict-aliasing x=12 y=2 *q=2 *r=12
clang-7.0.1-O0 
clang-7.0.1-O2 
clang-7.0.1-O3 
clang-7.0.1-O2-no-strict-aliasing 
clang-7.0.1-O3-no-strict-aliasing 
icc-19-O0 
icc-19-O2 
icc-19-O3 
icc-19-O2-no-strict-aliasing 
icc-19-O3-no-strict-aliasing