Example: pointer_arith_algebraic_properties_3_global.c

up: index
prev: pointer_arith_algebraic_properties_2_global.c
next: pointer_copy_memcpy.c

1
2
3
4
5
6
7
8
9
10
11
12
    #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?
      //(equivalent to the &x[0]+(&(y[1])-&(y[0])) version?)
      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 Undefined behaviour: the operand of the unary '*' operator has an invalid value at 8:3-5
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 exit codes: compile 0 / execute 139 pointer_arith_algebraic_properties_3_global.c:5:3: error: A pointer (or array subscript) outside the bounds of an object.

Undefined behavior (UB-CEA1):
see C11 section 6.5.6:8 http://rvdoc.org/C11/6.5.6
see C11 section J.2:1 item 46 http://rvdoc.org/C11/J.2
see CERT-C section ARR30-C http://rvdoc.org/CERT-C/ARR30-C
see CERT-C section ARR37-C http://rvdoc.org/CERT-C/ARR37-C
see CERT-C section STR31-C http://rvdoc.org/CERT-C/STR31-C
see MISRA-C section 8.18:1 http://rvdoc.org/MISRA-C/8.18
see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1

pointer_arith_algebraic_properties_3_global.c:5:3: error: Computing pointer difference between two different objects.

Undefined behavior (UB-CEA5):
see C11 section 6.5.6:9 http://rvdoc.org/C11/6.5.6
see C11 section J.2:1 item 48 http://rvdoc.org/C11/J.2
see CERT-C section ARR36-C http://rvdoc.org/CERT-C/ARR36-C
see MISRA-C section 8.18:2 http://rvdoc.org/MISRA-C/8.18
see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1

pointer_arith_algebraic_properties_3_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

pointer_arith_algebraic_properties_3_global.c:5:3: error: Indeterminate value used in an expression.

Undefined behavior (UB-CEE2):
see C11 section 6.2.4 http://rvdoc.org/C11/6.2.4
see C11 section 6.7.9 http://rvdoc.org/C11/6.7.9
see C11 section 6.8 http://rvdoc.org/C11/6.8
see C11 section J.2:1 item 11 http://rvdoc.org/C11/J.2
see CERT-C section EXP33-C http://rvdoc.org/CERT-C/EXP33-C
see MISRA-C section 8.9:1 http://rvdoc.org/MISRA-C/8.9
see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1

Dereferencing a null pointer:
> in main at pointer_arith_algebraic_properties_3_global.c:8:3

Undefined behavior (UB-CER3):
see C11 section 6.5.3.2:4 http://rvdoc.org/C11/6.5.3.2
see C11 section J.2:1 item 43 http://rvdoc.org/C11/J.2
see CERT-C section EXP34-C http://rvdoc.org/CERT-C/EXP34-C
see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1

Execution failed (configuration dumped)