xref: /aosp_15_r20/external/clang/test/SemaCXX/warn-new-overaligned-3.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wover-aligned %s -isystem %S/Inputs -verify
2*67e74705SXin Li 
3*67e74705SXin Li // This test ensures that we still get the warning even if we #include <new>
4*67e74705SXin Li // where the header here simulates <new>.
5*67e74705SXin Li #include <warn-new-overaligned-3.h>
6*67e74705SXin Li 
7*67e74705SXin Li namespace test1 {
8*67e74705SXin Li struct Test {
9*67e74705SXin Li   template <typename T>
10*67e74705SXin Li   struct SeparateCacheLines {
11*67e74705SXin Li     T data;
12*67e74705SXin Li   } __attribute__((aligned(256)));
13*67e74705SXin Li 
14*67e74705SXin Li   SeparateCacheLines<int> high_contention_data[10];
15*67e74705SXin Li };
16*67e74705SXin Li 
helper()17*67e74705SXin Li void helper() {
18*67e74705SXin Li   Test t;
19*67e74705SXin Li   new Test;  // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
20*67e74705SXin Li   new Test[10];  // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
21*67e74705SXin Li }
22*67e74705SXin Li }
23*67e74705SXin Li 
24*67e74705SXin Li namespace test2 {
25*67e74705SXin Li struct helper { int i __attribute__((aligned(256))); };
26*67e74705SXin Li 
27*67e74705SXin Li struct Placement {
Placementtest2::Placement28*67e74705SXin Li   Placement() {
29*67e74705SXin Li     new (d) helper();
30*67e74705SXin Li   }
31*67e74705SXin Li   helper *d;
32*67e74705SXin Li };
33*67e74705SXin Li }
34