Example: pointer_arith_algebraic_properties_2_global.c

up: index
prev: provenance_tag_bits_via_uintptr_t_1.c
next: pointer_arith_algebraic_properties_3_global.c

1
2
3
4
5
6
7
8
9
10
    #include <stdio.h>
    #include <inttypes.h>
    int y[2], x[2];
    int main() {
      int *p=(int*)(((uintptr_t)&(x[0])) + 
        (((uintptr_t)&(y[1]))-((uintptr_t)&(y[0]))));
      *p = 11;  // is this free of undefined behaviour?
      printf("x[1]=%d *p=%d\n",x[1],*p);
      return 0;
    }
[link to run test in Cerberus]

Experimental data (what does this mean?)

cerberus-concrete-PVI x[1]=11 *p=11
cerberus-concrete-PNVI x[1]=11 *p=11
gcc-8.1-O0 x[1]=11 *p=11
gcc-8.1-O2 x[1]=11 *p=11
gcc-8.1-O3 x[1]=11 *p=11
gcc-8.1-O2-no-strict-aliasing x[1]=11 *p=11
gcc-8.1-O3-no-strict-aliasing x[1]=11 *p=11
clang-6.0-O0 x[1]=11 *p=11
clang-6.0-O2 x[1]=11 *p=11
clang-6.0-O3 x[1]=11 *p=11
clang-6.0-O2-no-strict-aliasing x[1]=11 *p=11
clang-6.0-O3-no-strict-aliasing x[1]=11 *p=11
clang-6.0-UBSAN x[1]=11 *p=11
clang-6.0-ASAN x[1]=11 *p=11
clang-6.0-MSAN x[1]=11 *p=11
icc-19-O0 x[1]=11 *p=11
icc-19-O2 x[1]=11 *p=11
icc-19-O3 x[1]=11 *p=11
icc-19-O2-no-strict-aliasing x[1]=11 *p=11
icc-19-O3-no-strict-aliasing x[1]=11 *p=11
compcert-3.4 x[1]=11 *p=11
compcert-3.4-O x[1]=11 *p=11
kcc-1.0 pointer_arith_algebraic_properties_2_global.c:5:3: warning: Conversion from an integer to non-null pointer.

Implementation defined behavior (IMPL-CCV13):
see C11 section 6.3.2.3:5 http://rvdoc.org/C11/6.3.2.3
see CERT section INT36-C http://rvdoc.org/CERT/INT36-C

x[1]=11 *p=11