Example: intr3.c

up: index
prev: intr2.c
next: intr4.c

    #include <inttypes.h>
    #include <cheriintrin.h>
    #include <stdio.h>
    #include "capprint.h"
    
    int main()
    {
        int v = 42;
        const int *x = &v;
        fprintf(stderr,"Original: %" PTR_FMT "\n", sptr((void*)x));
        int *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/intr3.c:11:14: error: constraint violation: initializing 'signed int*' with an expression of type 'const signed int*' discards qualifiers
int *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 3 and 4:
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.

FOOTNOTE.112:
The asymmetric appearance of these constraints with respect to type qualifiers is due to the conversion
(specified in 6.3.2.1) that changes lvalues to ``the value of the expression'' and thus removes any type
qualifiers that were applied to the type category of the expression (for example, it removes const but
not volatile from the type int volatile * const).
 
clang-riscv-O3-bounds-conservative
clang-riscv-O3-bounds-subobject-safe
 tests/cheri/intr3.c:11:10: warning: initializing 'int *' with an expression of type 'const int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
int *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/intr3.c:11:10: warning: initializing 'int *' with an expression of type 'const int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
int *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/intr3.c:11:10: warning: initializing 'int *' with an expression of type 'const int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
int *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/intr3.c:11:10: warning: initializing 'int *' with an expression of type 'const int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
int *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/intr3.c:11:10: warning: initializing 'int *' with an expression of type 'const int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
int *y = cheri_perms_and(x, 0l);
^ ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Original: 0xfffffff7ff5c [rwRW,0xfffffff7ff5c-0xfffffff7ff60]
Modified: 0xfffffff7ff5c [,0xfffffff7ff5c-0xfffffff7ff60]
 
gcc-morello-O3 tests/cheri/intr3.c: In function 'main':
tests/cheri/intr3.c:11:14: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
11 | int *y = cheri_perms_and(x, 0l);
| ^~~~~~~~~~~~~~~
Original: 0x7fffffdc [rwRW,0x7fffffdc-0x7fffffe0]
Modified: 0x7fffffdc [,0x7fffffdc-0x7fffffe0]
 
gcc-morello-O0 tests/cheri/intr3.c: In function 'main':
tests/cheri/intr3.c:11:14: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
11 | int *y = cheri_perms_and(x, 0l);
| ^~~~~~~~~~~~~~~
Original: 0x7fffffbc [rwRW,0x7fffffbc-0x7fffffc0]
Modified: 0x7fffffbc [,0x7fffffbc-0x7fffffc0]