Example: pointer_from_integer_1ig.c

up: index
prev: pointer_from_integer_1pg.c
next: pointer_from_integer_1p.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) {
      int j=5;
      int *p = (int*)i;
      if (p==&j)
        *p=7;
      printf("j=%d &j=%p\n",j,(void*)&j); 
    }
    int main() {
      uintptr_t j = ADDRESS_PFI_1IG;
      f(j);
    }
[link to run test in Cerberus]

Experimental data (what does this mean?)

cerberus-concrete-PVI EXECUTION 0:
Undefined behaviour: the operand of the unary '*' operator has an invalid value at 8:5-7

EXECUTION 1 (exit = Specified(0)):
j=5 &j=(@5, 0x28)
cerberus-concrete-PNVI j=7 &j=(@5, 0x28)
gcc-8.1-O0 j=7 &j=0x7fffffffdc04
gcc-8.1-O2 j=5 &j=0x7fffffffdc2c
gcc-8.1-O3 j=5 &j=0x7fffffffdc2c
gcc-8.1-O2-no-strict-aliasing j=5 &j=0x7fffffffdc0c
gcc-8.1-O3-no-strict-aliasing j=5 &j=0x7fffffffdc0c
clang-6.0-O0 j=7 &j=0x7fffffffdbc4
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=0x7fffffffdbf0
icc-19-O2 j=5 &j=0x7fffffffdb84
icc-19-O3 j=5 &j=0x7fffffffdb84
icc-19-O2-no-strict-aliasing j=5 &j=0x7fffffffdb84
icc-19-O3-no-strict-aliasing j=5 &j=0x7fffffffdb84
compcert-3.4 j=7 &j=0x7fffffffe6d8
compcert-3.4-O j=5 &j=0x7fffffffe6d8
kcc-1.0 j=5 &j=(nil)
Conversion from an integer to non-null pointer:
> in f at pointer_from_integer_1ig.c:6:3
in main at pointer_from_integer_1ig.c:13:3

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