annotate clang/test/Sema/tls_alignment.cpp @ 169:1f21f60db75c

Added tag llvm10 for changeset 980e56f2e095
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 09:26:57 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // TLS variable cannot be aligned to more than 32 bytes on PS4.
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // A non-aligned type.
anatofuz
parents:
diff changeset
7 struct non_aligned_struct {
anatofuz
parents:
diff changeset
8 int some_data[16]; // 64 bytes of stuff, non aligned.
anatofuz
parents:
diff changeset
9 };
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 // An aligned type.
anatofuz
parents:
diff changeset
12 struct __attribute__(( aligned(64) )) aligned_struct {
anatofuz
parents:
diff changeset
13 int some_data[12]; // 48 bytes of stuff, aligned to 64.
anatofuz
parents:
diff changeset
14 };
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 // A type with an aligned field.
anatofuz
parents:
diff changeset
17 struct struct_with_aligned_field {
anatofuz
parents:
diff changeset
18 int some_aligned_data[12] __attribute__(( aligned(64) )); // 48 bytes of stuff, aligned to 64.
anatofuz
parents:
diff changeset
19 };
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 // A typedef of the aligned struct.
anatofuz
parents:
diff changeset
22 typedef aligned_struct another_aligned_struct;
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 // A typedef to redefine a non-aligned struct as aligned.
anatofuz
parents:
diff changeset
25 typedef __attribute__(( aligned(64) )) non_aligned_struct yet_another_aligned_struct;
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 // Non aligned variable doesn't cause an error.
anatofuz
parents:
diff changeset
28 __thread non_aligned_struct foo;
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 // Variable aligned because of its type should cause an error.
anatofuz
parents:
diff changeset
31 __thread aligned_struct bar; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 // Variable explicitly aligned in the declaration should cause an error.
anatofuz
parents:
diff changeset
34 __thread non_aligned_struct bar2 __attribute__(( aligned(64) )); // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 // Variable aligned because of one of its fields should cause an error.
anatofuz
parents:
diff changeset
37 __thread struct_with_aligned_field bar3; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 // Variable aligned because of typedef, first case.
anatofuz
parents:
diff changeset
40 __thread another_aligned_struct bar4; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 // Variable aligned because of typedef, second case.
anatofuz
parents:
diff changeset
43 __thread yet_another_aligned_struct bar5; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 int baz ()
anatofuz
parents:
diff changeset
46 {
anatofuz
parents:
diff changeset
47 return foo.some_data[0] + bar.some_data[1] + bar2.some_data[2] +
anatofuz
parents:
diff changeset
48 bar3.some_aligned_data[3] + bar4.some_data[4] +
anatofuz
parents:
diff changeset
49 bar5.some_data[5];
anatofuz
parents:
diff changeset
50 }
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 // Verify alignment check where a dependent type is involved.
anatofuz
parents:
diff changeset
54 // The check is (correctly) not performed on "t", but the check still is
anatofuz
parents:
diff changeset
55 // performed on the structure as a whole once it has been instantiated.
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 template<class T> struct templated_tls {
anatofuz
parents:
diff changeset
58 static __thread T t;
anatofuz
parents:
diff changeset
59 T other_t __attribute__(( aligned(64) ));
anatofuz
parents:
diff changeset
60 };
anatofuz
parents:
diff changeset
61 __thread templated_tls<int> blah; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 int blag() {
anatofuz
parents:
diff changeset
64 return blah.other_t * 2;
anatofuz
parents:
diff changeset
65 }
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 // Verify alignment check where the alignment is a template parameter.
anatofuz
parents:
diff changeset
69 // The check is only performed during instantiation.
anatofuz
parents:
diff changeset
70 template <int N>
anatofuz
parents:
diff changeset
71 struct S {
anatofuz
parents:
diff changeset
72 static int __thread __attribute__((aligned(N))) x; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
73 };
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 S<64> s_instance; // expected-note{{in instantiation of template class 'S<64>' requested here}}