Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions regression/cbmc-library/__builtin_assume_aligned/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <assert.h>

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;
}
8 changes: 8 additions & 0 deletions regression/cbmc-library/__builtin_assume_aligned/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE gcc-only
main.c
--pointer-check --bounds-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
15 changes: 15 additions & 0 deletions src/ansi-c/library/gcc.c
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down
Loading