Example: align4.c

up: index
prev: align3.c
next: call1.c

    /*
      Author: Alex Richardson
    */
    #include <string.h>
    #include <stdint.h>
    #include <stdio.h>
    
    static void *copy_cap_size(void* dst, void* src) {
        return memcpy(dst, src, sizeof(void*));
    }
    
    void* copy_cap_aligned(uintptr_t *buffer, uintptr_t value) {
        return copy_cap_size(buffer, &value);
    }
    
    int main()
    {
        int x=42;
        int *p;
        copy_cap_aligned((uintptr_t*)&p, (uintptr_t)&x);
        fprintf(stderr,"Value %d\n", *p);
    }
    

Experimental data (what does this mean?)

clang-morello-O3-bounds-conservative
clang-riscv-O3-bounds-conservative
 tests/cheri/align4.c:9:12: warning: found underaligned store of capability type (aligned to 1 bytes instead of 16). Will use memcpy() instead of capability load to preserve tags if it is aligned correctly at runtime [-Wcheri-inefficient]
return memcpy(dst, src, sizeof(void*));
^
tests/cheri/align4.c:9:12: note: use __builtin_assume_aligned() or cast to (u)intptr_t* if you know that the pointer is actually aligned to capability size; this will allow the memcpy() or memmove() call to be inlined if the size is constant (otherwise a library call must be used to maintain tag bits). For more information see https://github.com/CTSRD-CHERI/llvm-project/wiki/Unaligned-capability-copies
1 warning generated.
Value 42
 
gcc-morello-O0
gcc-morello-O3
clang-morello-O0-bounds-conservative
clang-morello-O0-bounds-references-only
clang-morello-O0-bounds-subobject-safe
clang-morello-O3-bounds-subobject-safe
clang-morello-O0-bounds-aggressive
clang-morello-O0-bounds-very-aggressive
clang-morello-O0-bounds-everywhere-unsafe
clang-riscv-O0-bounds-conservative
clang-riscv-O0-bounds-references-only
clang-riscv-O0-bounds-subobject-safe
clang-riscv-O3-bounds-subobject-safe
clang-riscv-O0-bounds-aggressive
clang-riscv-O0-bounds-very-aggressive
clang-riscv-O0-bounds-everywhere-unsafe
cerberus-cheri
cerberus-cheri-no-pnvi
cerberus-cheri-revocation
cerberus-cheri-revocation-no-pnvi
cerberus-cheri-cornucopia
cerberus-cheri-cornucopia-no-pnvi
 Value 42