diff --git a/regression/cbmc-library/__builtin_assume_aligned/main.c b/regression/cbmc-library/__builtin_assume_aligned/main.c new file mode 100644 index 00000000000..3da9952acf4 --- /dev/null +++ b/regression/cbmc-library/__builtin_assume_aligned/main.c @@ -0,0 +1,12 @@ +#include + +int main() +{ + int x = 5; + // Per the GCC documentation __builtin_assume_aligned returns its + // first argument (and asserts nothing at run time). + void *p = __builtin_assume_aligned(&x, 4); + assert(p == &x); + assert(*(int *)p == 5); + return 0; +} diff --git a/regression/cbmc-library/__builtin_assume_aligned/test.desc b/regression/cbmc-library/__builtin_assume_aligned/test.desc new file mode 100644 index 00000000000..28345e3383d --- /dev/null +++ b/regression/cbmc-library/__builtin_assume_aligned/test.desc @@ -0,0 +1,8 @@ +CORE gcc-only +main.c +--pointer-check --bounds-check +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/src/ansi-c/library/gcc.c b/src/ansi-c/library/gcc.c index cf33e06002c..3ff1b73b23b 100644 --- a/src/ansi-c/library/gcc.c +++ b/src/ansi-c/library/gcc.c @@ -1,3 +1,18 @@ +/* FUNCTION: __builtin_assume_aligned */ + +void *__builtin_assume_aligned(const void *exp, __CPROVER_size_t align, ...) +{ + // Per the GCC documentation, this returns `exp` and allows the + // compiler to assume the returned pointer is at least `align`-byte + // aligned (with an optional run-time misalignment offset in the + // variadic part). The alignment claim is an optimisation hint; for + // verification we model the identity value flow and do not prune + // (assume) or check (assert) the alignment, which keeps the model + // conservative. + (void)align; + return (void *)exp; +} + /* FUNCTION: __builtin_ia32_sfence */ #if defined(__i386__) || defined(__x86_64__)