annotate clang/test/Sema/tls_alignment.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents c4bab56944e8
children
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
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
3 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -std=c++17 -fsyntax-only -verify %s
150
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
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
21 // A templated type
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
22 template <typename>
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
23 struct templated_struct {};
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
24 // expected-note@-1{{candidate template ignored: couldn't infer template argument ''}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
25 // expected-note@-2{{candidate function template not viable: requires 1 argument, but 0 were provided}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
26
150
anatofuz
parents:
diff changeset
27 // A typedef of the aligned struct.
anatofuz
parents:
diff changeset
28 typedef aligned_struct another_aligned_struct;
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 // A typedef to redefine a non-aligned struct as aligned.
anatofuz
parents:
diff changeset
31 typedef __attribute__(( aligned(64) )) non_aligned_struct yet_another_aligned_struct;
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 // Non aligned variable doesn't cause an error.
anatofuz
parents:
diff changeset
34 __thread non_aligned_struct foo;
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 // Variable aligned because of its type should cause an error.
anatofuz
parents:
diff changeset
37 __thread aligned_struct bar; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 // Variable explicitly aligned in the declaration should cause an error.
anatofuz
parents:
diff changeset
40 __thread non_aligned_struct bar2 __attribute__(( aligned(64) )); // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 // Variable aligned because of one of its fields should cause an error.
anatofuz
parents:
diff changeset
43 __thread struct_with_aligned_field bar3; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 // Variable aligned because of typedef, first case.
anatofuz
parents:
diff changeset
46 __thread another_aligned_struct bar4; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 // Variable aligned because of typedef, second case.
anatofuz
parents:
diff changeset
49 __thread yet_another_aligned_struct bar5; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
50
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
51 // No crash for undeduced type.
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
52 __thread templated_struct bar6; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'templated_struct'}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
53
150
anatofuz
parents:
diff changeset
54 int baz ()
anatofuz
parents:
diff changeset
55 {
anatofuz
parents:
diff changeset
56 return foo.some_data[0] + bar.some_data[1] + bar2.some_data[2] +
anatofuz
parents:
diff changeset
57 bar3.some_aligned_data[3] + bar4.some_data[4] +
anatofuz
parents:
diff changeset
58 bar5.some_data[5];
anatofuz
parents:
diff changeset
59 }
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 template<class T> struct templated_tls {
anatofuz
parents:
diff changeset
62 static __thread T t;
anatofuz
parents:
diff changeset
63 T other_t __attribute__(( aligned(64) ));
anatofuz
parents:
diff changeset
64 };
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
65 __thread templated_tls<int> blah; // expected-error{{alignment (64) of thread-local variable}}
150
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 template <int N>
anatofuz
parents:
diff changeset
68 struct S {
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
69 struct alignas(64) B {};
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
70 struct alignas(N) C {};
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
71 static inline void f() {
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
72 thread_local B b; // expected-error{{alignment (64) of thread-local variable}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
73 thread_local C c; // expected-error{{alignment (64) of thread-local variable}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
74 }
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
75 template<int J> static inline thread_local int b alignas(J) = J; // expected-error{{alignment (64) of thread-local variable}}
150
anatofuz
parents:
diff changeset
76 static int __thread __attribute__((aligned(N))) x; // expected-error{{alignment (64) of thread-local variable}}
anatofuz
parents:
diff changeset
77 };
anatofuz
parents:
diff changeset
78
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
79 int blag() {
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
80 // Verify alignment check where the alignment is a template parameter.
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
81 // The check is only performed during instantiation.
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
82 S<64> s_instance; // expected-note{{in instantiation of template class 'S<64>' requested here}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
83
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
84 // Verify alignment for dependent local variables.
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
85 S<64>::f(); // expected-note{{in instantiation of member function 'S<64>::f' requested here}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
86
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
87 // Verify alignment check where a dependent type is involved.
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
88 // The check is (correctly) not performed on "t", but the check still is
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
89 // performed on the structure as a whole once it has been instantiated.
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
90 return blah.other_t * 2 + S<64>::b<64>; // expected-note{{in instantiation of static data member 'S<64>::b' requested here}}
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
91 }