Example: provenance_union_punning_2_auto_xy.c

up: index
prev: provenance_union_punning_2_global_yx.c
next: provenance_union_punning_2_auto_yx.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    #include <stdio.h>
    #include <string.h> 
    #include <inttypes.h>
    int x=1, y=2;
    typedef union { uintptr_t ui; int *p; } un;
    int main() {
      un u; 
      int *px = &x;
      uintptr_t i = (uintptr_t)px;
      i = i + sizeof(int);
      u.ui = i;
      int *p = u.p;
      int *q = &y;
      printf("Addresses: p=%p q=%p\n",(void*)p,(void*)q);
      if (memcmp(&p, &q, sizeof(p)) == 0) {
        *p = 11;  // does this have undefined behaviour?
        printf("x=%d y=%d *p=%d *q=%d\n",x,y,*p,*q);
      }
      return 0;
    }
[link to run test in Cerberus]

Experimental data (what does this mean?)

cerberus-concrete-PVI-plain Addresses: p=(@empty, 0xffffffe8) q=(@3, 0xffffffe0)
cerberus-concrete-PVI-ae Addresses: p=(@empty, 0xffffffe8) q=(@3, 0xffffffe0)
cerberus-concrete-PVI-ae-udi Addresses: p=(@2, 0xffffffe8) q=(@3, 0xffffffe0)
gcc-8.3-O0 Addresses: p=0x100001024 q=0x100001024
x=1 y=11 *p=11 *q=11
gcc-8.3-O2 Addresses: p=0x100001020 q=0x100001018
gcc-8.3-O3 Addresses: p=0x100001020 q=0x100001018
gcc-8.3-O2-no-strict-aliasing Addresses: p=0x100001020 q=0x100001018
gcc-8.3-O3-no-strict-aliasing Addresses: p=0x100001020 q=0x100001018
clang-7.0.1-O0 Addresses: p=0x10000101c q=0x10000101c
x=1 y=11 *p=11 *q=11
clang-7.0.1-O2 Addresses: p=0x10000101c q=0x10000101c
x=1 y=11 *p=11 *q=11
clang-7.0.1-O3 Addresses: p=0x10000101c q=0x10000101c
x=1 y=11 *p=11 *q=11
clang-7.0.1-O2-no-strict-aliasing Addresses: p=0x10000101c q=0x10000101c
x=1 y=11 *p=11 *q=11
clang-7.0.1-O3-no-strict-aliasing Addresses: p=0x10000101c q=0x10000101c
x=1 y=11 *p=11 *q=11
icc-19-O0 Addresses: p=0x600b7c q=0x600b7c
x=1 y=11 *p=11 *q=11
icc-19-O2 Addresses: p=0x6046c4 q=0x6046c4
x=1 y=2 *p=11 *q=11
icc-19-O3 Addresses: p=0x6046c4 q=0x6046c4
x=1 y=2 *p=11 *q=11
icc-19-O2-no-strict-aliasing Addresses: p=0x6046c4 q=0x6046c4
x=1 y=2 *p=11 *q=11
icc-19-O3-no-strict-aliasing Addresses: p=0x6046c4 q=0x6046c4
x=1 y=2 *p=11 *q=11