1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -triple x86_64-unknown-unknown -verify %s
2 
3 struct S0 {
4   int x;
5   static const int test0 = __builtin_omp_required_simd_align(x); // expected-error {{invalid application of '__builtin_omp_required_simd_align' to an expression, only type is allowed}}
6   static const int test1 = __builtin_omp_required_simd_align(decltype(S0::x));
7   auto test2() -> char(&)[__builtin_omp_required_simd_align(decltype(x))];
8 };
9 
10 struct S1; // expected-note 6 {{forward declaration}}
11 extern S1 s1;
12 const int test3 = __builtin_omp_required_simd_align(decltype(s1)); // expected-error {{invalid application of '__builtin_omp_required_simd_align' to an incomplete type 'decltype(s1)' (aka 'S1')}}
13 
14 struct S2 {
15   S2();
16   S1 &s;
17   int x;
18 
19   int test4 = __builtin_omp_required_simd_align(decltype(x)); // ok
20   int test5 = __builtin_omp_required_simd_align(decltype(s)); // expected-error {{invalid application of '__builtin_omp_required_simd_align' to an incomplete type 'S1'}}
21 };
22 
23 const int test6 = __builtin_omp_required_simd_align(decltype(S2::x));
24 const int test7 = __builtin_omp_required_simd_align(decltype(S2::s)); // expected-error {{invalid application of '__builtin_omp_required_simd_align' to an incomplete type 'S1'}}
25 
26 // Arguably, these should fail like the S1 cases do: the alignment of
27 // 's2.x' should depend on the alignment of both x-within-S2 and
28 // s2-within-S3 and thus require 'S3' to be complete.  If we start
29 // doing the appropriate recursive walk to do that, we should make
30 // sure that these cases don't explode.
31 struct S3 {
32   S2 s2;
33 
34   static const int test8 = __builtin_omp_required_simd_align(decltype(s2.x));
35   static const int test9 = __builtin_omp_required_simd_align(decltype(s2.s)); // expected-error {{invalid application of '__builtin_omp_required_simd_align' to an incomplete type 'S1'}}
36   auto test10() -> char(&)[__builtin_omp_required_simd_align(decltype(s2.x))];
37   static const int test11 = __builtin_omp_required_simd_align(decltype(S3::s2.x));
38   static const int test12 = __builtin_omp_required_simd_align(decltype(S3::s2.s)); // expected-error {{invalid application of '__builtin_omp_required_simd_align' to an incomplete type 'S1'}}
39   auto test13() -> char(&)[__builtin_omp_required_simd_align(decltype(s2.x))];
40 };
41 
42 // Same reasoning as S3.
43 struct S4 {
44   union {
45       int x;
46     };
47   static const int test0 = __builtin_omp_required_simd_align(decltype(x));
48   static const int test1 = __builtin_omp_required_simd_align(decltype(S0::x));
49   auto test2() -> char(&)[__builtin_omp_required_simd_align(decltype(x))];
50 };
51 
52 // Regression test for asking for the alignment of a field within an invalid
53 // record.
54 struct S5 {
55   S1 s;  // expected-error {{incomplete type}}
56   int x;
57 };
58 const int test8 = __builtin_omp_required_simd_align(decltype(S5::x));
59 
60 long long int test14[2];
61 
62 static_assert(__builtin_omp_required_simd_align(decltype(test14)) == 16, "foo");
63 
64 static_assert(__builtin_omp_required_simd_align(int[2]) == __builtin_omp_required_simd_align(int), ""); // ok
65 
66 namespace __builtin_omp_required_simd_align_array_expr {
67   alignas(32) extern int n[2];
68   static_assert(__builtin_omp_required_simd_align(decltype(n)) == 16, "");
69 
70   template<int> struct S {
71       static int a[];
72     };
73   template<int N> int S<N>::a[N];
74   static_assert(__builtin_omp_required_simd_align(decltype(S<1>::a)) == __builtin_omp_required_simd_align(int), "");
75   static_assert(__builtin_omp_required_simd_align(decltype(S<1128>::a)) == __builtin_omp_required_simd_align(int), "");
76 }
77 
n(T)78 template <typename T> void n(T) {
79   alignas(T) int T1;
80   char k[__builtin_omp_required_simd_align(decltype(T1))];
81   static_assert(sizeof(k) == __builtin_omp_required_simd_align(long long), "");
82 }
83 template void n(long long);
84