ORCA-C/Tests/Conformance/c11align.c
Stephen Heumann 6ead1d4caf Add a set of new tests for C95/C99/C11 features that we now support.
These are currently only run by the new DOIT3 test-running script.

Note that these tests are designed to be applicable to most implementations of C95/C99/C11, not just ORCA/C. They do make certain assumptions not guaranteed by the standards (e.g. power of 2 types and some properties of IEEE-like FP), but in general those assumptions should be true for most 'normal' systems.
2021-08-22 17:32:56 -05:00

45 lines
1.0 KiB
C

/*
* Test alignment functionality (C11/C17).
*/
#include <stdio.h>
#include <stdalign.h>
#include <stddef.h>
#include <stdlib.h>
int main(void) {
char _Alignas(short) a;
alignas(_Alignof(max_align_t)) char b;
a = 'a';
b = 'b';
if (a != 'a' || b != 'b')
goto Fail;
if (!(alignof(char) <= _Alignof(int)))
goto Fail;
if (!(alignof(long double) <= _Alignof(max_align_t)))
goto Fail;
long *lp = aligned_alloc(alignof(long), sizeof(long)*2);
if (lp == NULL)
goto Fail;
*(lp+1) = 123456789;
if (lp[1] != 123456789)
goto Fail;
free(lp);
// aligned_alloc with invalid alignment must return NULL (C17).
lp = aligned_alloc(123, 123);
if (lp)
goto Fail;
printf ("Passed Conformance Test c11align\n");
return 0;
Fail:
printf ("Failed Conformance Test c11align\n");
}