Example: intr2.c

up: index
prev: intr1.c
next: intr3.c

    #include <inttypes.h>
    #include <cheriintrin.h>
    #include <stdio.h>
    #include "capprint.h"
    
    int main()
    {
        int v = 42;
        int *x = &v;
        fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)x));
        intptr_t y = cheri_perms_and(x, 0l); 
        fprintf(stderr,"Modified: %" PTR_FMT "\n", sptr((void*)y));
    }

Experimental data (what does this mean?)

cerberus-cheri
cerberus-cheri-no-pnvi
cerberus-cheri-revocation
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia
cerberus-cheri-cornucopia-no-pnvi
 exit codes: compile 0 / execute 1 tests/cheri/intr2.c:11:18: error: constraint violation: initializing 'intptr_t' with an expression with a non arithmetic type 'signed int*'
intptr_t y = cheri_perms_and(x, 0l);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
§6.7.9#11, sentence 2:
11 The initializer for a scalar shall be a single expression, optionally enclosed in braces. The
initial value of the object is that of the expression (after conversion); the same type
constraints and conversions as for simple assignment apply, taking the type of the scalar
to be the unqualified version of its declared type.

§6.5.16.1#1, bullet 1:
1 One of the following shall hold:112)
-- the left operand has atomic, qualified, or unqualified arithmetic type, and the right has
arithmetic type;
-- the left operand has an atomic, qualified, or unqualified version of a structure or union
type compatible with the type of the right;
-- the left operand has atomic, qualified, or unqualified pointer type, and (considering
the type the left operand would have after lvalue conversion) both operands are
pointers to qualified or unqualified versions of compatible types, and the type pointed
to by the left has all the qualifiers of the type pointed to by the right;
-- the left operand has atomic, qualified, or unqualified pointer type, and (considering
the type the left operand would have after lvalue conversion) one operand is a pointer
to an object type, and the other is a pointer to a qualified or unqualified version of
void, and the type pointed to by the left has all the qualifiers of the type pointed to
by the right;
-- the left operand is an atomic, qualified, or unqualified pointer, and the right is a null
pointer constant; or
-- the left operand has type atomic, qualified, or unqualified _Bool, and the right is a
pointer.
 
clang-riscv-O3-bounds-conservative
clang-riscv-O3-bounds-subobject-safe
 tests/cheri/intr2.c:11:14: warning: incompatible pointer to integer conversion initializing 'intptr_t' (aka '__intcap') with an expression of type 'int *' [-Wint-conversion]
intptr_t y = cheri_perms_and(x, 0l);
^ ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Original: 0x3fffdfff2c [rwRW,0x3fffdfff2c-0x3fffdfff30]
Modified: 0x3fffdfff2c [,0x3fffdfff2c-0x3fffdfff30]
 
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
 tests/cheri/intr2.c:11:14: warning: incompatible pointer to integer conversion initializing 'intptr_t' (aka '__intcap') with an expression of type 'int *' [-Wint-conversion]
intptr_t y = cheri_perms_and(x, 0l);
^ ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Original: 0x3fffdfff6c [rwRW,0x3fffdfff6c-0x3fffdfff70]
Modified: 0x3fffdfff6c [,0x3fffdfff6c-0x3fffdfff70]
 
clang-morello-O3-bounds-subobject-safe tests/cheri/intr2.c:11:14: warning: incompatible pointer to integer conversion initializing 'intptr_t' (aka '__intcap') with an expression of type 'int *' [-Wint-conversion]
intptr_t y = cheri_perms_and(x, 0l);
^ ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Original: 0xfffffff7fefc [rwRW,0xfffffff7fefc-0xfffffff7ff00]
Modified: 0xfffffff7fefc [,0xfffffff7fefc-0xfffffff7ff00]
 
clang-morello-O3-bounds-conservative tests/cheri/intr2.c:11:14: warning: incompatible pointer to integer conversion initializing 'intptr_t' (aka '__intcap') with an expression of type 'int *' [-Wint-conversion]
intptr_t y = cheri_perms_and(x, 0l);
^ ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Original: 0xfffffff7ff1c [rwRW,0xfffffff7ff1c-0xfffffff7ff20]
Modified: 0xfffffff7ff1c [,0xfffffff7ff1c-0xfffffff7ff20]
 
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
 tests/cheri/intr2.c:11:14: warning: incompatible pointer to integer conversion initializing 'intptr_t' (aka '__intcap') with an expression of type 'int *' [-Wint-conversion]
intptr_t y = cheri_perms_and(x, 0l);
^ ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Original: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
Modified: 0xfffffff7ff5c [,0xfffffff7ff5c-0xfffffff7ff60]
 
gcc-morello-O3 tests/cheri/intr2.c: In function 'main':
tests/cheri/intr2.c:11:18: warning: initialization of 'intptr_t' {aka '__intcap'} from 'int *' makes integer from pointer without a cast [-Wint-conversion]
11 | intptr_t y = cheri_perms_and(x, 0l);
| ^~~~~~~~~~~~~~~
Original: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
Modified: 0x7fffffdc [,0x7fffffdc-0x7fffffe0]
 
gcc-morello-O0 tests/cheri/intr2.c: In function 'main':
tests/cheri/intr2.c:11:18: warning: initialization of 'intptr_t' {aka '__intcap'} from 'int *' makes integer from pointer without a cast [-Wint-conversion]
11 | intptr_t y = cheri_perms_and(x, 0l);
| ^~~~~~~~~~~~~~~
Original: 0x7fffffbc [rwRW,0x7fffffbc-0x7fffffc0]
Modified: 0x7fffffbc [,0x7fffffbc-0x7fffffc0]