Example: bounds2.c

up: index
prev: bounds1.c
next: bounds2a.c

    #include <stdio.h>
    #include "capprint.h"
    
    int main()
    {
        int x=42;
        int *p = &x;
        
        fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)p));
        
        p=p+100;
        fprintf(stderr,"OOB: %" PTR_FMT "\n", sptr((void*)p));
        
        p=p-100;
        fprintf(stderr,"Recovered: %" PTR_FMT "\n", sptr((void*)p));
        fprintf(stderr,"Value: %d\n", *p);
    }

Experimental data (what does this mean?)

cerberus-cheri-no-pnvi
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia-no-pnvi
 exit codes: compile 0 / execute 1 Undefined {ub: "UB046_array_pointer_outside", loc: "<11:7--11:12>"}
Original: (@disabled, 0xffffe700 [rwRW,0xffffe700-0xffffe704])
 
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia
 exit codes: compile 0 / execute 1 Undefined {ub: "UB046_array_pointer_outside", loc: "<11:7--11:12>"}
Original: (@83, 0xffffe700 [rwRW,0xffffe700-0xffffe704])
 
clang-riscv-O3-bounds-subobject-safe Original: 0x3fffdfff2c [rwRW,0x3fffdfff2c-0x3fffdfff30]
OOB: 0x3fffe000bc [rwRW,0x3fffdfff2c-0x3fffdfff30]
Recovered: 0x3fffdfff2c [rwRW,0x3fffdfff2c-0x3fffdfff30]
Value: 42
 
clang-riscv-O3-bounds-conservative Original: 0x3fffdfff3c [rwRW,0x3fffdfff3c-0x3fffdfff40]
OOB: 0x3fffe000cc [rwRW,0x3fffdfff3c-0x3fffdfff40]
Recovered: 0x3fffdfff3c [rwRW,0x3fffdfff3c-0x3fffdfff40]
Value: 42
 
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
 Original: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70]
OOB: 0x3fffe000fc [rwRW,0x3fffdfff6c-0x3fffdfff70]
Recovered: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70]
Value: 42
 
clang-morello-O3-bounds-subobject-safe Original: 0xfffffff7fefc [rwRW,0xfffffff7fefc-0xfffffff7ff00]
OOB: 0xfffffff8008c [rwRW,0xfffffff7fefc-0xfffffff7ff00]
Recovered: 0xfffffff7fefc [rwRW,0xfffffff7fefc-0xfffffff7ff00]
Value: 42
 
clang-morello-O3-bounds-conservative Original: 0xfffffff7ff2c [rwRW,0xfffffff7ff2c-0xfffffff7ff30]
OOB: 0xfffffff800bc [rwRW,0xfffffff7ff2c-0xfffffff7ff30]
Recovered: 0xfffffff7ff2c [rwRW,0xfffffff7ff2c-0xfffffff7ff30]
Value: 42
 
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only
clang-morello-O0-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
 Original: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
OOB: 0xfffffff800ec [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
Recovered: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
Value: 42
 
gcc-morello-O3 tests/cheri/bounds2.c: In function 'main':
tests/cheri/bounds2.c:11:6: warning: array subscript 100 is outside array bounds of 'int[1]' [-Warray-bounds]
11 | p=p+100;
| ~^~~~~~
tests/cheri/bounds2.c:6:9: note: while referencing 'x'
6 | int x=42;
| ^
Original: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
OOB: 0x8000016c [rwRW,0x7fffffdc-0x7fffffe0]
Recovered: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
Value: 42
 
gcc-morello-O0 Original: 0x7fffffcc [rwRW,0x7fffffcc-0x7fffffd0]
OOB: 0x8000015c [rwRW,0x7fffffcc-0x7fffffd0]
Recovered: 0x7fffffcc [rwRW,0x7fffffcc-0x7fffffd0]
Value: 42