diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGenObjC/nontrivial-c-struct-exception.m | 31 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/weak-in-c-struct.m | 193 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/module.map | 10 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/template-nontrivial0.h | 13 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/template-nontrivial1.h | 6 | ||||
-rw-r--r-- | clang/test/Modules/templates.mm | 10 |
6 files changed, 262 insertions, 1 deletions
diff --git a/clang/test/CodeGenObjC/nontrivial-c-struct-exception.m b/clang/test/CodeGenObjC/nontrivial-c-struct-exception.m index a926a6d493b..7db53bb7424 100644 --- a/clang/test/CodeGenObjC/nontrivial-c-struct-exception.m +++ b/clang/test/CodeGenObjC/nontrivial-c-struct-exception.m @@ -1,12 +1,18 @@ -// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -fobjc-exceptions -fexceptions -fobjc-arc-exceptions -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -fobjc-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s // CHECK: %[[STRUCT_STRONG:.*]] = type { i32, i8* } +// CHECK: %[[STRUCT_WEAK:.*]] = type { i32, i8* } typedef struct { int i; id f1; } Strong; +typedef struct { + int i; + __weak id f1; +} Weak; + // CHECK: define void @testStrongException() // CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_STRONG]], align 8 // CHECK: %[[AGG_TMP1:.*]] = alloca %[[STRUCT_STRONG]], align 8 @@ -31,3 +37,26 @@ void calleeStrong(Strong, Strong); void testStrongException(void) { calleeStrong(genStrong(), genStrong()); } + +// CHECK: define void @testWeakException() +// CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_WEAK]], align 8 +// CHECK: %[[AGG_TMP1:.*]] = alloca %[[STRUCT_WEAK]], align 8 +// CHECK: call void @genWeak(%[[STRUCT_WEAK]]* sret %[[AGG_TMP]]) +// CHECK: invoke void @genWeak(%[[STRUCT_WEAK]]* sret %[[AGG_TMP1]]) + +// CHECK: call void @calleeWeak(%[[STRUCT_WEAK]]* %[[AGG_TMP]], %[[STRUCT_WEAK]]* %[[AGG_TMP1]]) +// CHECK: ret void + +// CHECK: landingpad { i8*, i32 } +// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_TMP]] to i8** +// CHECK: call void @__destructor_8_w8(i8** %[[V3]]) +// CHECK: br label + +// CHECK: resume + +Weak genWeak(void); +void calleeWeak(Weak, Weak); + +void testWeakException(void) { + calleeWeak(genWeak(), genWeak()); +} diff --git a/clang/test/CodeGenObjC/weak-in-c-struct.m b/clang/test/CodeGenObjC/weak-in-c-struct.m new file mode 100644 index 00000000000..b0f4c085102 --- /dev/null +++ b/clang/test/CodeGenObjC/weak-in-c-struct.m @@ -0,0 +1,193 @@ +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - %s | FileCheck -check-prefix=ARM64 -check-prefix=COMMON %s +// RUN: %clang_cc1 -triple thumbv7-apple-ios10 -fobjc-arc -fblocks -fobjc-runtime=ios-10.0 -emit-llvm -o - %s | FileCheck -check-prefix=COMMON %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13 -fobjc-arc -fblocks -fobjc-runtime=macosx-10.13.0 -emit-llvm -o - %s | FileCheck -check-prefix=COMMON %s +// RUN: %clang_cc1 -triple i386-apple-macosx10.13.0 -fobjc-arc -fblocks -fobjc-runtime=macosx-fragile-10.13.0 -emit-llvm -o - %s | FileCheck -check-prefix=COMMON %s + +typedef void (^BlockTy)(void); + +// COMMON: %[[STRUCT_WEAK:.*]] = type { i32, i8* } + +typedef struct { + int f0; + __weak id f1; +} Weak; + +Weak getWeak(void); +void calleeWeak(Weak); + +// ARM64: define void @test_constructor_destructor_Weak() +// ARM64: %[[T:.*]] = alloca %[[STRUCT_WEAK]], align 8 +// ARM64: %[[V0:.*]] = bitcast %[[STRUCT_WEAK]]* %[[T]] to i8** +// ARM64: call void @__default_constructor_8_w8(i8** %[[V0]]) +// ARM64: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[T]] to i8** +// ARM64: call void @__destructor_8_w8(i8** %[[V1]]) +// ARM64: ret void + +// ARM64: define linkonce_odr hidden void @__default_constructor_8_w8(i8** %[[DST:.*]]) +// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8 +// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V1]] = bitcast i8** %[[V0]] to i8* +// ARM64: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 8 +// ARM64: %[[V3:.*]] = bitcast i8* %[[V2]] to i8** +// ARM64: %[[V4:.*]] = bitcast i8** %[[V3]] to i8* +// ARM64: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false) + +// ARM64: define linkonce_odr hidden void @__destructor_8_w8(i8** %[[DST:.*]]) +// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8 +// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V1:.*]] = bitcast i8** %[[V0]] to i8* +// ARM64: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 8 +// ARM64: %[[V3:.*]] = bitcast i8* %[[V2]] to i8** +// ARM64: call void @objc_destroyWeak(i8** %[[V3]]) + +void test_constructor_destructor_Weak(void) { + Weak t; +} + +// ARM64: define void @test_copy_constructor_Weak(%[[STRUCT_WEAK]]* %{{.*}}) +// ARM64: call void @__copy_constructor_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}}) +// ARM64: call void @__destructor_8_w8(i8** %{{.*}}) + +// ARM64: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) +// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8 +// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8 +// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 +// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32* +// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32* +// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8 +// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8 +// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8* +// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8 +// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** +// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8* +// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8 +// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8** +// ARM64: call void @objc_copyWeak(i8** %[[V7]], i8** %[[V10]]) + +void test_copy_constructor_Weak(Weak *s) { + Weak t = *s; +} + +// ARM64: define void @test_copy_assignment_Weak(%[[STRUCT_WEAK]]* %{{.*}}, %[[STRUCT_WEAK]]* %{{.*}}) +// ARM64: call void @__copy_assignment_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}}) + +// ARM64: define linkonce_odr hidden void @__copy_assignment_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) +// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8 +// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8 +// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 +// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32* +// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32* +// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8 +// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8 +// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8* +// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8 +// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** +// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8* +// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8 +// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8** +// ARM64: %[[V11:.*]] = call i8* @objc_loadWeakRetained(i8** %[[V10]]) +// ARM64: %[[V12:.*]] = call i8* @objc_storeWeak(i8** %[[V7]], i8* %[[V11]]) +// ARM64: call void @objc_release(i8* %[[V11]]) + +void test_copy_assignment_Weak(Weak *d, Weak *s) { + *d = *s; +} + +// ARM64: define internal void @__Block_byref_object_copy_(i8*, i8*) +// ARM64: call void @__move_constructor_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}}) + +// ARM64: define linkonce_odr hidden void @__move_constructor_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) +// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8 +// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8 +// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 +// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32* +// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32* +// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8 +// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8 +// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8* +// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8 +// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** +// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8* +// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8 +// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8** +// ARM64: call void @objc_moveWeak(i8** %[[V7]], i8** %[[V10]]) + +void test_move_constructor_Weak(void) { + __block Weak t; + BlockTy b = ^{ (void)t; }; +} + +// ARM64: define void @test_move_assignment_Weak(%[[STRUCT_WEAK]]* %{{.*}}) +// ARM64: call void @__move_assignment_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}}) + +// ARM64: define linkonce_odr hidden void @__move_assignment_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]]) +// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8 +// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8 +// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8 +// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8 +// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8 +// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32* +// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32* +// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8 +// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8 +// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8* +// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8 +// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8** +// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8* +// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8 +// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8** +// ARM64: %[[V11:.*]] = call i8* @objc_loadWeakRetained(i8** %[[V10]]) +// ARM64: %[[V12:.*]] = call i8* @objc_storeWeak(i8** %[[V7]], i8* %[[V11]]) +// ARM64: call void @objc_destroyWeak(i8** %[[V10]]) +// ARM64: call void @objc_release(i8* %[[V11]]) + +void test_move_assignment_Weak(Weak *p) { + *p = getWeak(); +} + +// COMMON: define void @test_parameter_Weak(%[[STRUCT_WEAK]]* %[[A:.*]]) +// COMMON: %[[V0:.*]] = bitcast %[[STRUCT_WEAK]]* %[[A]] to i8** +// COMMON: call void @__destructor_{{.*}}(i8** %[[V0]]) + +void test_parameter_Weak(Weak a) { +} + +// COMMON: define void @test_argument_Weak(%[[STRUCT_WEAK]]* %[[A:.*]]) +// COMMON: %[[A_ADDR:.*]] = alloca %[[STRUCT_WEAK]]* +// COMMON: %[[AGG_TMP:.*]] = alloca %[[STRUCT_WEAK]] +// COMMON: store %[[STRUCT_WEAK]]* %[[A]], %[[STRUCT_WEAK]]** %[[A_ADDR]] +// COMMON: %[[V0:.*]] = load %[[STRUCT_WEAK]]*, %[[STRUCT_WEAK]]** %[[A_ADDR]] +// COMMON: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_TMP]] to i8** +// COMMON: %[[V2:.*]] = bitcast %[[STRUCT_WEAK]]* %[[V0]] to i8** +// COMMON: call void @__copy_constructor_{{.*}}(i8** %[[V1]], i8** %[[V2]]) +// COMMON: call void @calleeWeak(%[[STRUCT_WEAK]]* %[[AGG_TMP]]) +// COMMON-NEXT: ret + +void test_argument_Weak(Weak *a) { + calleeWeak(*a); +} + +// COMMON: define void @test_return_Weak(%[[STRUCT_WEAK]]* noalias sret %[[AGG_RESULT:.*]], %[[STRUCT_WEAK]]* %[[A:.*]]) +// COMMON: %[[A_ADDR:.*]] = alloca %[[STRUCT_WEAK]]* +// COMMON: store %[[STRUCT_WEAK]]* %[[A]], %[[STRUCT_WEAK]]** %[[A_ADDR]] +// COMMON: %[[V0:.*]] = load %[[STRUCT_WEAK]]*, %[[STRUCT_WEAK]]** %[[A_ADDR]] +// COMMON: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_RESULT]] to i8** +// COMMON: %[[V2:.*]] = bitcast %[[STRUCT_WEAK]]* %[[V0]] to i8** +// COMMON: call void @__copy_constructor_{{.*}}(i8** %[[V1]], i8** %[[V2]]) +// COMMON: ret void + +Weak test_return_Weak(Weak *a) { + return *a; +} diff --git a/clang/test/Modules/Inputs/module.map b/clang/test/Modules/Inputs/module.map index 4788daa4316..93fe4688730 100644 --- a/clang/test/Modules/Inputs/module.map +++ b/clang/test/Modules/Inputs/module.map @@ -460,3 +460,13 @@ module innerstructredef { header "innerstructredef.h" } } + +module template_nontrivial0 { + header "template-nontrivial0.h" + export * +} + +module template_nontrivial1 { + header "template-nontrivial1.h" + export * +} diff --git a/clang/test/Modules/Inputs/template-nontrivial0.h b/clang/test/Modules/Inputs/template-nontrivial0.h new file mode 100644 index 00000000000..cff080ee5cc --- /dev/null +++ b/clang/test/Modules/Inputs/template-nontrivial0.h @@ -0,0 +1,13 @@ +template <class T> +struct Class0 { + Class0(); + Class0(const Class0<T> &); + ~Class0(); + T *p; +}; + +struct S0 { + id x; +}; + +Class0<S0> returnNonTrivial(); diff --git a/clang/test/Modules/Inputs/template-nontrivial1.h b/clang/test/Modules/Inputs/template-nontrivial1.h new file mode 100644 index 00000000000..24136f0cae4 --- /dev/null +++ b/clang/test/Modules/Inputs/template-nontrivial1.h @@ -0,0 +1,6 @@ +@import template_nontrivial0; + +struct S1 { + S1(); + Class0<S0> a; +}; diff --git a/clang/test/Modules/templates.mm b/clang/test/Modules/templates.mm index 9c3f327acb7..95e7a9caea5 100644 --- a/clang/test/Modules/templates.mm +++ b/clang/test/Modules/templates.mm @@ -122,3 +122,13 @@ void testWithAttributes() { static_assert(alignof(decltype(a)) == 2, ""); static_assert(alignof(decltype(b)) == 2, ""); } + +// Check that returnNonTrivial doesn't return Class0<S0> directly in registers. + +// CHECK: declare void @_Z16returnNonTrivialv(%struct.Class0* sret) + +@import template_nontrivial0; +@import template_nontrivial1; + +S1::S1() : a(returnNonTrivial()) { +} |