Example: pointer_from_integer_2g.c

up: index
prev: pointer_from_integer_2.c
next: provenance_lost_escape_1.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    #include <stdio.h>
    #include <stdint.h>
    #include "charon_address_guesses.h"
    void f() {
      uintptr_t i=ADDRESS_PFI_2G;
      int *p = (int*)i;
      *p=7;
    }
    int main() {
      int j=5;
      if ((uintptr_t)&j == ADDRESS_PFI_2G)
        f();
      printf("j=%d &j=%p\n",j,(void*)&j); 
    }
[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 7:3-5
cerberus-concrete-PNVI j=7 &j=(@3, 0x14)
gcc-8.1-O0 j=7 &j=0x7fffffffdc2c
gcc-8.1-O2 j=7 &j=0x7fffffffdc2c
gcc-8.1-O3 j=7 &j=0x7fffffffdc2c
gcc-8.1-O2-no-strict-aliasing j=7 &j=0x7fffffffdc0c
gcc-8.1-O3-no-strict-aliasing j=7 &j=0x7fffffffdc0c
clang-6.0-O0 j=7 &j=0x7fffffffdbe8
clang-6.0-O2 j=5 &j=0x7fffffffdbf4
clang-6.0-O3 j=5 &j=0x7fffffffdbf4
clang-6.0-O2-no-strict-aliasing j=5 &j=0x7fffffffdbd4
clang-6.0-O3-no-strict-aliasing j=5 &j=0x7fffffffdbd4
clang-6.0-UBSAN j=5 &j=0x7fffffffdbf4
clang-6.0-ASAN j=5 &j=0x7fffffffdb60
clang-6.0-MSAN j=5 &j=0x7fffffffdbec
icc-19-O0 j=7 &j=0x7fffffffdc20
icc-19-O2 j=7 &j=0x6046c0
icc-19-O3 j=7 &j=0x6046c0
icc-19-O2-no-strict-aliasing j=7 &j=0x6046c0
icc-19-O3-no-strict-aliasing j=7 &j=0x6046c0
compcert-3.4 j=7 &j=0x7fffffffe6f8
compcert-3.4-O j=5 &j=0x7fffffffe6e8
kcc-1.0 j=5 &j=(nil)
Comparison of unspecified value:
> in main at pointer_from_integer_2g.c:11:3

Unspecified value or behavior (USP-CERL7):
see C11 section 6.5.9 http://rvdoc.org/C11/6.5.9
see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1