tls_alignment.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // TLS variable cannot be aligned to more than 32 bytes on PS4.
  2. // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -verify %s
  3. // A non-aligned type.
  4. struct non_aligned_struct {
  5. int some_data[16]; // 64 bytes of stuff, non aligned.
  6. };
  7. // An aligned type.
  8. struct __attribute__(( aligned(64) )) aligned_struct {
  9. int some_data[12]; // 48 bytes of stuff, aligned to 64.
  10. };
  11. // A type with an aligned field.
  12. struct struct_with_aligned_field {
  13. int some_aligned_data[12] __attribute__(( aligned(64) )); // 48 bytes of stuff, aligned to 64.
  14. };
  15. // A typedef of the aligned struct.
  16. typedef aligned_struct another_aligned_struct;
  17. // A typedef to redefine a non-aligned struct as aligned.
  18. typedef __attribute__(( aligned(64) )) non_aligned_struct yet_another_aligned_struct;
  19. // Non aligned variable doesn't cause an error.
  20. __thread non_aligned_struct foo;
  21. // Variable aligned because of its type should cause an error.
  22. __thread aligned_struct bar; // expected-error{{alignment (64) of thread-local variable}}
  23. // Variable explicitly aligned in the declaration should cause an error.
  24. __thread non_aligned_struct bar2 __attribute__(( aligned(64) )); // expected-error{{alignment (64) of thread-local variable}}
  25. // Variable aligned because of one of its fields should cause an error.
  26. __thread struct_with_aligned_field bar3; // expected-error{{alignment (64) of thread-local variable}}
  27. // Variable aligned because of typedef, first case.
  28. __thread another_aligned_struct bar4; // expected-error{{alignment (64) of thread-local variable}}
  29. // Variable aligned because of typedef, second case.
  30. __thread yet_another_aligned_struct bar5; // expected-error{{alignment (64) of thread-local variable}}
  31. int baz ()
  32. {
  33. return foo.some_data[0] + bar.some_data[1] + bar2.some_data[2] +
  34. bar3.some_aligned_data[3] + bar4.some_data[4] +
  35. bar5.some_data[5];
  36. }
  37. // Verify alignment check where a dependent type is involved.
  38. // The check is (correctly) not performed on "t", but the check still is
  39. // performed on the structure as a whole once it has been instantiated.
  40. template<class T> struct templated_tls {
  41. static __thread T t;
  42. T other_t __attribute__(( aligned(64) ));
  43. };
  44. __thread templated_tls<int> blah; // expected-error{{alignment (64) of thread-local variable}}
  45. int blag() {
  46. return blah.other_t * 2;
  47. }
  48. // Verify alignment check where the alignment is a template parameter.
  49. // The check is only performed during instantiation.
  50. template <int N>
  51. struct S {
  52. static int __thread __attribute__((aligned(N))) x; // expected-error{{alignment (64) of thread-local variable}}
  53. };
  54. S<64> s_instance; // expected-note{{in instantiation of template class 'S<64>' requested here}}