File: std-align-val-t-in-operator-new.cpp

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (57 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// RUN: %clang_cc1 -std=c++11                      -fsyntax-only -verify %s
// RUN: %clang_cc1 -std=c++11 -faligned-allocation -fsyntax-only -verify %s
// RUN: %clang_cc1 -std=c++14                      -fsyntax-only -verify %s
// RUN: %clang_cc1 -std=c++14 -faligned-allocation -fsyntax-only -verify %s
// RUN: %clang_cc1 -std=c++17                      -fsyntax-only -verify %s
// RUN: %clang_cc1 -std=c++17 -faligned-allocation -fsyntax-only -verify %s

namespace std {
typedef __SIZE_TYPE__ size_t;
struct nothrow_t {};
#if __cplusplus >= 201103L
enum class align_val_t : size_t {};
#else
enum align_val_t {
// We can't force an underlying type when targeting windows.
#ifndef _WIN32
  __zero = 0,
  __max = (size_t)-1
#endif
};
#endif
} // namespace std

void *operator new(std::size_t count, std::align_val_t al) __attribute__((alloc_align(2)));

#define OVERALIGNED alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2)

struct OVERALIGNED A {
  A();
  int n[128];
};

void *ptr_variable(int align) { return new (std::align_val_t(align)) A; }
void *ptr_align16() { return new (std::align_val_t(16)) A; }
void *ptr_align15() { return new (std::align_val_t(15)) A; } // expected-warning {{requested alignment is not a power of 2}}

struct alignas(128) S {
  S() {}
};

void *alloc_overaligned_struct() {
  return new S;
}

void *alloc_overaligned_struct_with_extra_variable_alignment(int align) {
  return new (std::align_val_t(align)) S;
}
void *alloc_overaligned_struct_with_extra_256_alignment(int align) {
  return new (std::align_val_t(256)) S;
}
void *alloc_overaligned_struct_with_extra_255_alignment(int align) {
  return new (std::align_val_t(255)) S; // expected-warning {{requested alignment is not a power of 2}}
}

std::align_val_t align_variable(int align) { return std::align_val_t(align); }
std::align_val_t align_align16() { return std::align_val_t(16); }
std::align_val_t align_align15() { return std::align_val_t(15); }