[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / alignas.c
blob391553bc540ec03a7a69ea296c39b619c7e3ec40
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -Dalignof=__alignof %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -Dalignof=_Alignof -DUSING_C11_SYNTAX %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -DUSING_C11_SYNTAX %s
5 _Alignas(3) int align_illegal; //expected-error {{requested alignment is not a power of 2}}
6 _Alignas(int) char align_big;
7 _Alignas(1) int align_small; // expected-error {{requested alignment is less than minimum}}
8 _Alignas(1) unsigned _Alignas(8) int _Alignas(1) align_multiple;
10 struct align_member {
11 _Alignas(8) int member;
12 _Alignas(1) char bitfield : 1; // expected-error {{'_Alignas' attribute cannot be applied to a bit-field}}
15 typedef _Alignas(8) char align_typedef; // expected-error {{'_Alignas' attribute only applies to variables and fields}}
17 void f(_Alignas(1) char c) { // expected-error {{'_Alignas' attribute cannot be applied to a function parameter}}
18 _Alignas(1) register char k; // expected-error {{'_Alignas' attribute cannot be applied to a variable with 'register' storage class}}
21 #ifdef USING_C11_SYNTAX
22 // expected-warning-re@+4{{'{{(_A|a)}}lignof' applied to an expression is a GNU extension}}
23 // expected-warning-re@+4{{'{{(_A|a)}}lignof' applied to an expression is a GNU extension}}
24 // expected-warning-re@+4{{'{{(_A|a)}}lignof' applied to an expression is a GNU extension}}
25 #endif
26 _Static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong");
27 _Static_assert(alignof(align_small) == 1, "j's alignment is wrong");
28 _Static_assert(alignof(align_multiple) == 8, "l's alignment is wrong");
29 _Static_assert(alignof(struct align_member) == 8, "quuux's alignment is wrong");
30 _Static_assert(sizeof(struct align_member) == 8, "quuux's size is wrong");
32 struct GH95032_1 {
33 _Alignas(16) char bytes[16];
35 _Static_assert(_Alignof(struct GH95032_1) == 16, "");
37 #if __STDC_VERSION__ >= 202311L
38 struct GH95032_2 {
39 alignas(16) char bytes[16];
41 static_assert(alignof(struct GH95032_2) == 16);
42 #endif