1 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wover-aligned -verify %s
2 
3 namespace test1 {
4 struct Test {
5   template <typename T>
6   struct SeparateCacheLines {
7     T data;
8   } __attribute__((aligned(256)));
9 
10   SeparateCacheLines<int> high_contention_data[10];
11 };
12 
helper()13 void helper() {
14   Test t;
15   new Test;  // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
16   new Test[10];  // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
17 }
18 }
19 
20 namespace test2 {
21 class Test {
22   typedef int __attribute__((aligned(256))) aligned_int;
23   aligned_int high_contention_data[10];
24 };
25 
helper()26 void helper() {
27   Test t;
28   new Test;  // expected-warning {{type 'test2::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
29   new Test[10];  // expected-warning {{type 'test2::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
30 }
31 }
32 
33 namespace test3 {
34 struct Test {
35   template <typename T>
36   struct SeparateCacheLines {
37     T data;
38   } __attribute__((aligned(256)));
39 
operator newtest3::Test40   void* operator new(unsigned long) {
41     return 0; // expected-warning {{'operator new' should not return a null pointer unless it is declared 'throw()'}}
42   }
43 
44   SeparateCacheLines<int> high_contention_data[10];
45 };
46 
helper()47 void helper() {
48   Test t;
49   new Test;
50   new Test[10];  // expected-warning {{type 'test3::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
51 }
52 }
53 
54 namespace test4 {
55 struct Test {
56   template <typename T>
57   struct SeparateCacheLines {
58     T data;
59   } __attribute__((aligned(256)));
60 
operator new[]test4::Test61   void* operator new[](unsigned long) {
62     return 0; // expected-warning {{'operator new[]' should not return a null pointer unless it is declared 'throw()'}}
63   }
64 
65   SeparateCacheLines<int> high_contention_data[10];
66 };
67 
helper()68 void helper() {
69   Test t;
70   new Test;  // expected-warning {{type 'test4::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
71   new Test[10];
72 }
73 }
74