2012-06-30 21:33:57 +00:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -Dalignof=__alignof %s
|
2013-01-29 10:18:33 +00:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -Dalignof=_Alignof -DUSING_C11_SYNTAX %s
|
2024-07-18 08:23:41 -04:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -DUSING_C11_SYNTAX %s
|
2011-09-29 18:04:28 +00:00
|
|
|
|
|
|
|
_Alignas(3) int align_illegal; //expected-error {{requested alignment is not a power of 2}}
|
|
|
|
_Alignas(int) char align_big;
|
2013-02-01 08:12:08 +00:00
|
|
|
_Alignas(1) int align_small; // expected-error {{requested alignment is less than minimum}}
|
2011-09-29 18:04:28 +00:00
|
|
|
_Alignas(1) unsigned _Alignas(8) int _Alignas(1) align_multiple;
|
|
|
|
|
|
|
|
struct align_member {
|
|
|
|
_Alignas(8) int member;
|
2013-01-29 09:02:09 +00:00
|
|
|
_Alignas(1) char bitfield : 1; // expected-error {{'_Alignas' attribute cannot be applied to a bit-field}}
|
2011-09-29 18:04:28 +00:00
|
|
|
};
|
|
|
|
|
2013-02-01 08:25:07 +00:00
|
|
|
typedef _Alignas(8) char align_typedef; // expected-error {{'_Alignas' attribute only applies to variables and fields}}
|
2013-01-29 09:02:09 +00:00
|
|
|
|
|
|
|
void f(_Alignas(1) char c) { // expected-error {{'_Alignas' attribute cannot be applied to a function parameter}}
|
|
|
|
_Alignas(1) register char k; // expected-error {{'_Alignas' attribute cannot be applied to a variable with 'register' storage class}}
|
|
|
|
}
|
2011-09-29 18:04:28 +00:00
|
|
|
|
2013-01-29 10:18:33 +00:00
|
|
|
#ifdef USING_C11_SYNTAX
|
2024-07-18 08:23:41 -04:00
|
|
|
// expected-warning-re@+4{{'{{(_A|a)}}lignof' applied to an expression is a GNU extension}}
|
|
|
|
// expected-warning-re@+4{{'{{(_A|a)}}lignof' applied to an expression is a GNU extension}}
|
|
|
|
// expected-warning-re@+4{{'{{(_A|a)}}lignof' applied to an expression is a GNU extension}}
|
2013-01-29 10:18:33 +00:00
|
|
|
#endif
|
2012-06-30 21:33:57 +00:00
|
|
|
_Static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong");
|
|
|
|
_Static_assert(alignof(align_small) == 1, "j's alignment is wrong");
|
|
|
|
_Static_assert(alignof(align_multiple) == 8, "l's alignment is wrong");
|
|
|
|
_Static_assert(alignof(struct align_member) == 8, "quuux's alignment is wrong");
|
2011-09-29 18:04:28 +00:00
|
|
|
_Static_assert(sizeof(struct align_member) == 8, "quuux's size is wrong");
|
2024-07-18 08:23:41 -04:00
|
|
|
|
|
|
|
struct GH95032_1 {
|
|
|
|
_Alignas(16) char bytes[16];
|
|
|
|
};
|
|
|
|
_Static_assert(_Alignof(struct GH95032_1) == 16, "");
|
|
|
|
|
|
|
|
#if __STDC_VERSION__ >= 202311L
|
|
|
|
struct GH95032_2 {
|
|
|
|
alignas(16) char bytes[16];
|
|
|
|
};
|
|
|
|
static_assert(alignof(struct GH95032_2) == 16);
|
|
|
|
#endif
|