Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple=arm64-apple-ios -emit-llvm -o - | FileCheck %s |
| 2 | // RUN: %clang_cc1 %s -triple=arm64-apple-ios -emit-llvm -o - | FileCheck -check-prefix=CHECK-GLOBALS %s |
| 3 | |
| 4 | // __cxa_guard_acquire argument is 64-bit |
| 5 | // rdar://11540122 |
| 6 | struct A { |
| 7 | A(); |
| 8 | }; |
| 9 | |
| 10 | void f() { |
| 11 | // CHECK: call i32 @__cxa_guard_acquire(i64* |
| 12 | static A a; |
| 13 | } |
| 14 | |
| 15 | // ARM64 uses the C++11 definition of POD. |
| 16 | // rdar://12650514 |
| 17 | namespace test1 { |
| 18 | // This class is POD in C++11 and cannot have objects allocated in |
| 19 | // its tail-padding. |
| 20 | struct ABase {}; |
| 21 | struct A : ABase { |
| 22 | int x; |
| 23 | char c; |
| 24 | }; |
| 25 | |
| 26 | struct B : A { |
| 27 | char d; |
| 28 | }; |
| 29 | |
| 30 | int test() { |
| 31 | return sizeof(B); |
| 32 | } |
| 33 | // CHECK: define i32 @_ZN5test14testEv() |
| 34 | // CHECK: ret i32 12 |
| 35 | } |
| 36 | |
| 37 | namespace std { |
| 38 | class type_info; |
| 39 | } |
| 40 | |
| 41 | // ARM64 uses string comparisons for what would otherwise be |
| 42 | // default-visibility weak RTTI. rdar://12650568 |
| 43 | namespace test2 { |
| 44 | struct A { |
| 45 | virtual void foo(); |
| 46 | }; |
| 47 | void A::foo() {} |
Richard Smith | 91c18de | 2015-02-28 01:01:56 +0000 | [diff] [blame] | 48 | // CHECK-GLOBALS-DAG: @_ZTSN5test21AE = constant [11 x i8] |
David Blaikie | bdf40a6 | 2015-03-13 18:21:46 +0000 | [diff] [blame] | 49 | // CHECK-GLOBALS-DAG: @_ZTIN5test21AE = constant { {{.*}}, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @_ZTSN5test21AE, i32 0, i32 0) } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 50 | |
| 51 | struct __attribute__((visibility("hidden"))) B {}; |
| 52 | const std::type_info &b0 = typeid(B); |
Richard Smith | 91c18de | 2015-02-28 01:01:56 +0000 | [diff] [blame] | 53 | // CHECK-GLOBALS-DAG: @_ZTSN5test21BE = linkonce_odr hidden constant |
David Blaikie | bdf40a6 | 2015-03-13 18:21:46 +0000 | [diff] [blame] | 54 | // CHECK-GLOBALS-DAG: @_ZTIN5test21BE = linkonce_odr hidden constant { {{.*}}, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @_ZTSN5test21BE, i32 0, i32 0) } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 55 | |
| 56 | const std::type_info &b1 = typeid(B*); |
Richard Smith | 91c18de | 2015-02-28 01:01:56 +0000 | [diff] [blame] | 57 | // CHECK-GLOBALS-DAG: @_ZTSPN5test21BE = linkonce_odr hidden constant |
David Blaikie | bdf40a6 | 2015-03-13 18:21:46 +0000 | [diff] [blame] | 58 | // CHECK-GLOBALS-DAG: @_ZTIPN5test21BE = linkonce_odr hidden constant { {{.*}}, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @_ZTSPN5test21BE, i32 0, i32 0), i32 0, i8* bitcast |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 59 | |
| 60 | struct C {}; |
| 61 | const std::type_info &c0 = typeid(C); |
Richard Smith | 91c18de | 2015-02-28 01:01:56 +0000 | [diff] [blame] | 62 | // CHECK-GLOBALS-DAG: @_ZTSN5test21CE = linkonce_odr hidden constant |
| 63 | // CHECK-GLOBALS-DAG: @_ZTIN5test21CE = linkonce_odr hidden constant { {{.*}}, i8* inttoptr (i64 add (i64 ptrtoint ([11 x i8]* @_ZTSN5test21CE to i64), i64 -9223372036854775808) to i8*) } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 64 | |
| 65 | const std::type_info &c1 = typeid(C*); |
Richard Smith | 91c18de | 2015-02-28 01:01:56 +0000 | [diff] [blame] | 66 | // CHECK-GLOBALS-DAG: @_ZTSPN5test21CE = linkonce_odr hidden constant |
| 67 | // CHECK-GLOBALS-DAG: @_ZTIPN5test21CE = linkonce_odr hidden constant { {{.*}}, i8* inttoptr (i64 add (i64 ptrtoint ([12 x i8]* @_ZTSPN5test21CE to i64), i64 -9223372036854775808) to i8*), i32 0, i8* bitcast |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 68 | |
| 69 | // This class is explicitly-instantiated, but that instantiation |
| 70 | // doesn't guarantee to emit RTTI, so we can still demote the visibility. |
| 71 | template <class T> class D {}; |
| 72 | template class D<int>; |
| 73 | const std::type_info &d0 = typeid(D<int>); |
Richard Smith | 91c18de | 2015-02-28 01:01:56 +0000 | [diff] [blame] | 74 | // CHECK-GLOBALS-DAG: @_ZTSN5test21DIiEE = linkonce_odr hidden constant |
| 75 | // CHECK-GLOBALS-DAG: @_ZTIN5test21DIiEE = linkonce_odr hidden constant { {{.*}}, i8* inttoptr (i64 add (i64 ptrtoint ([14 x i8]* @_ZTSN5test21DIiEE to i64), i64 -9223372036854775808) to i8*) } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 76 | |
| 77 | // This class is explicitly-instantiated and *does* guarantee to |
| 78 | // emit RTTI, so we're stuck with having to use default visibility. |
| 79 | template <class T> class E { |
| 80 | virtual void foo() {} |
| 81 | }; |
| 82 | template class E<int>; |
Richard Smith | 91c18de | 2015-02-28 01:01:56 +0000 | [diff] [blame] | 83 | // CHECK-GLOBALS-DAG: @_ZTSN5test21EIiEE = weak_odr constant [14 x i8] |
| 84 | // CHECK-GLOBALS-DAG: @_ZTIN5test21EIiEE = weak_odr constant { {{.*}}, i8* inttoptr (i64 add (i64 ptrtoint ([14 x i8]* @_ZTSN5test21EIiEE to i64), i64 -9223372036854775808) to i8*) } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 85 | |
| 86 | } |
John McCall | d23b27e | 2016-09-16 02:40:45 +0000 | [diff] [blame] | 87 | |
| 88 | // ARM64 reserves the top half of the vtable offset in virtual |
| 89 | // member pointers. |
| 90 | namespace test3 { |
| 91 | struct A { |
| 92 | virtual void foo(); |
| 93 | virtual void bar(); |
| 94 | }; |
| 95 | |
| 96 | // The offset half of the pointer is still initialized to zero. |
| 97 | // CHECK-GLOBALS-DAG: @_ZN5test34mptrE = global { i64, i64 } { i64 0, i64 1 } |
| 98 | void (A::*mptr)() = &A::foo; |
| 99 | |
| 100 | // CHECK-LABEL: define void @_ZN5test34testEv() |
| 101 | // CHECK: [[TEMP:%.*]] = alloca [[A:.*]], align 8 |
| 102 | // CHECK: [[MEMPTR:%.*]] = load { i64, i64 }, { i64, i64 }* @_ZN5test34mptrE, align 8 |
| 103 | // CHECK: [[ADJUST_AND_IS_VIRTUAL:%.*]] = extractvalue { i64, i64 } [[MEMPTR]], 1 |
| 104 | // CHECK: [[ADJUST:%.*]] = ashr i64 [[ADJUST_AND_IS_VIRTUAL]], 1 |
| 105 | // CHECK: [[T0:%.*]] = bitcast [[A]]* [[TEMP]] to i8* |
| 106 | // CHECK: [[T1:%.*]] = getelementptr inbounds i8, i8* [[T0]], i64 [[ADJUST]] |
| 107 | // CHECK: [[ADJUSTED:%.*]] = bitcast i8* [[T1]] to [[A]]* |
| 108 | // CHECK: [[MEMBER:%.*]] = extractvalue { i64, i64 } [[MEMPTR]], 0 |
| 109 | // CHECK: [[T0:%.*]] = and i64 [[ADJUST_AND_IS_VIRTUAL]], 1 |
| 110 | // CHECK: [[IS_VIRTUAL:%.*]] = icmp ne i64 [[T0]], 0 |
| 111 | // CHECK: br i1 [[IS_VIRTUAL]], |
| 112 | // CHECK: [[T0:%.*]] = bitcast [[A]]* [[ADJUSTED]] to i8** |
| 113 | // CHECK: [[VPTR:%.*]] = load i8*, i8** [[T0]], align 8 |
| 114 | // CHECK: [[TRUNC:%.*]] = trunc i64 [[MEMBER]] to i32 |
| 115 | // CHECK: [[ZEXT:%.*]] = zext i32 [[TRUNC]] to i64 |
| 116 | // CHECK: [[T0:%.*]] = getelementptr i8, i8* [[VPTR]], i64 [[ZEXT]] |
| 117 | // CHECK: [[T1:%.*]] = bitcast i8* [[T0]] to void ([[A]]*)** |
| 118 | // CHECK: load void ([[A]]*)*, void ([[A]]*)** [[T1]], |
| 119 | void test() { |
| 120 | (A().*mptr)(); |
| 121 | } |
| 122 | } |