Debian Codegraph @

clang/test/SemaCXX/warn-new-overaligned.cpp

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