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