Example: intptr10.c

up: index
prev: intptr9.c
next: intptr10a.c

    #include <stdio.h>
    #include "capprint.h"
    
    #define ALIGNMENT_BITS 1
    
    int main()
    {
        int n = 42;
        int *p = &n;
    
        fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)p));
        p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
        fprintf(stderr,"Re-aligned: %" 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: "UB_CHERI_InvalidCap", loc: "<14:36--14:38>"}
Original: (@disabled, 0xffffe700 [rwRW,0xffffe700-0xffffe704])
Re-aligned: (@disabled, 0xffffe700)
 
cerberus-cheri
cerberus-cheri-revocation
cerberus-cheri-cornucopia
 exit codes: compile 0 / execute 1 Undefined {ub: "UB_CHERI_InvalidCap", loc: "<14:36--14:38>"}
Original: (@82, 0xffffe700 [rwRW,0xffffe700-0xffffe704])
Re-aligned: (@82, 0xffffe700)
 
clang-riscv-O3-bounds-subobject-safe exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register cs2.
0x00000000001020aa in main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 0x00000000001020aa in main () at tests/cheri/intptr10.c:14
n = <optimized out>
p = <optimized out>


Original: 0x3fffdfff2c [rwRW,0x3fffdfff2c-0x3fffdfff30]
Re-aligned: 0x3fffdfff2c
 
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
 exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register ca2.
0x000000000010206e in main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 0x000000000010206e in main () at tests/cheri/intptr10.c:14
n = 42
p = 0x3fffdfff6c


Original: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70]
Re-aligned: 0x3fffdfff6c
 
clang-riscv-O3-bounds-conservative exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register cs4.
0x00000000001020a4 in main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 0x00000000001020a4 in main () at tests/cheri/intptr10.c:14
n = <optimized out>
p = <optimized out>


Original: 0x3fffdfff2c [rwRW,0x3fffdfff2c-0x3fffdfff30]
Re-aligned: 0x3fffdfff2c
 
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only
 exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault caused by register ca1.
0x0000000000102026 in main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 0x0000000000102026 in main () at tests/cheri/intptr10.c:14
n = 42
p = 0x3fffdfff6c


Original: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70]
Re-aligned: 0x3fffdfff6c
 
clang-morello-O3-bounds-subobject-safe exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
0x00000000001110f0 in main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 0x00000000001110f0 in main () at tests/cheri/intptr10.c:14
n = 42
p = 0xfffffff7fefc


Original: 0xfffffff7fefc [rwRW,0xfffffff7fefc-0xfffffff7ff00]
Re-aligned: 0xfffffff7fefc
 
clang-morello-O0-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
 exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
0x0000000000110f04 in main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 0x0000000000110f04 in main () at tests/cheri/intptr10.c:14
n = 42
p = 0xfffffff7ff5c


Original: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
Re-aligned: 0xfffffff7ff5c
 
clang-morello-O3-bounds-conservative exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 main () at tests/cheri/intptr10.c:14
n = 42
p = 0xfffffff7ff1c


Original: 0xfffffff7ff1c [rwRW,0xfffffff7ff1c-0xfffffff7ff20]
Re-aligned: 0xfffffff7ff1c
 
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only
 exit codes: compile 0 / execute 1 tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
^
1 warning generated.

Program received signal SIGPROT, CHERI protection violation.
Capability tag fault.
0x0000000000110ebc in main () at tests/cheri/intptr10.c:14
14 fprintf(stderr,"Value %d\n", *p);
#0 0x0000000000110ebc in main () at tests/cheri/intptr10.c:14
n = 42
p = 0xfffffff7ff5c


Original: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
Re-aligned: 0xfffffff7ff5c
 
gcc-morello-O3 exit codes: compile 0 / execute 137 tests/cheri/intptr10.c: In function 'main':
tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
12 | p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
| ^
tests/cheri/intptr10.c:12:9: note: insert cast to intptr_t to silence this warning
Original: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
Re-aligned: 0x7fffffdc
 
gcc-morello-O0 exit codes: compile 0 / execute 137 tests/cheri/intptr10.c: In function 'main':
tests/cheri/intptr10.c:12:9: warning: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Wcheri-capability-misuse]
12 | p = (int*)(((unsigned long long)p >> ALIGNMENT_BITS) << ALIGNMENT_BITS);
| ^
tests/cheri/intptr10.c:12:9: note: insert cast to intptr_t to silence this warning
Original: 0x7fffffcc [rwRW,0x7fffffcc-0x7fffffd0]
Re-aligned: 0x7fffffcc