annotate clang/test/SemaCXX/align-x86.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2 // expected-no-diagnostics
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 using size_t = decltype(sizeof(0));
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 struct complex_double {
anatofuz
parents:
diff changeset
7 double real;
anatofuz
parents:
diff changeset
8 double imag;
anatofuz
parents:
diff changeset
9 };
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 template <typename T, size_t ABI, size_t Preferred>
anatofuz
parents:
diff changeset
12 struct check_alignment {
anatofuz
parents:
diff changeset
13 using type = T;
anatofuz
parents:
diff changeset
14 static type value;
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 static_assert(__alignof__(value) == Preferred, "__alignof__(value) != Preferred");
anatofuz
parents:
diff changeset
17 static_assert(__alignof__(type) == Preferred, "__alignof__(type) != Preferred");
anatofuz
parents:
diff changeset
18 static_assert(alignof(type) == ABI, "alignof(type) != ABI");
anatofuz
parents:
diff changeset
19 };
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 // PR3433
anatofuz
parents:
diff changeset
22 template struct check_alignment<double, 4, 8>;
anatofuz
parents:
diff changeset
23 template struct check_alignment<long long, 4, 8>;
anatofuz
parents:
diff changeset
24 template struct check_alignment<unsigned long long, 4, 8>;
anatofuz
parents:
diff changeset
25 template struct check_alignment<complex_double, 4, 4>;
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 // PR6362
anatofuz
parents:
diff changeset
28 struct __attribute__((packed))
anatofuz
parents:
diff changeset
29 packed_struct {
anatofuz
parents:
diff changeset
30 unsigned int a;
anatofuz
parents:
diff changeset
31 } g_packedstruct;
anatofuz
parents:
diff changeset
32 template struct check_alignment<packed_struct, 1, 1>;
anatofuz
parents:
diff changeset
33 static_assert(__alignof__(g_packedstruct.a) == 1, "__alignof__(packed_struct.member) != 1");
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 template struct check_alignment<double[3], 4, 8>;
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 enum big_enum { x = 18446744073709551615ULL };
anatofuz
parents:
diff changeset
38 template struct check_alignment<big_enum, 4, 8>;
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 // PR5637
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 #define ALIGNED(x) __attribute__((aligned(x)))
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 typedef ALIGNED(2) struct {
anatofuz
parents:
diff changeset
45 char a[3];
anatofuz
parents:
diff changeset
46 } aligned_before_struct;
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 static_assert(sizeof(aligned_before_struct) == 3, "");
anatofuz
parents:
diff changeset
49 static_assert(sizeof(aligned_before_struct[1]) == 4, "");
anatofuz
parents:
diff changeset
50 static_assert(sizeof(aligned_before_struct[2]) == 6, "");
anatofuz
parents:
diff changeset
51 static_assert(sizeof(aligned_before_struct[2][1]) == 8, "");
anatofuz
parents:
diff changeset
52 static_assert(sizeof(aligned_before_struct[1][2]) == 6, "");
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 typedef struct ALIGNED(2) {
anatofuz
parents:
diff changeset
55 char a[3];
anatofuz
parents:
diff changeset
56 } aligned_after_struct;
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 static_assert(sizeof(aligned_after_struct) == 4, "");
anatofuz
parents:
diff changeset
59 static_assert(sizeof(aligned_after_struct[1]) == 4, "");
anatofuz
parents:
diff changeset
60 static_assert(sizeof(aligned_after_struct[2]) == 8, "");
anatofuz
parents:
diff changeset
61 static_assert(sizeof(aligned_after_struct[2][1]) == 8, "");
anatofuz
parents:
diff changeset
62 static_assert(sizeof(aligned_after_struct[1][2]) == 8, "");