126 lines · cpp
1// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s -Wno-return-type-c-linkage -std=c++03 | FileCheck %s -check-prefixes=CHECK2 3// For now just check that the RISC-V triples are accepted, but don't check the IR, as swiftcall is not yet supported.4// RUN: %clang_cc1 -triple riscv32-unknown-linux-gnu -emit-llvm -o - %s -Wno-return-type-c-linkage -std=c++035// RUN: %clang_cc1 -triple riscv64-unknown-linux-gnu -emit-llvm -o - %s -Wno-return-type-c-linkage -std=c++036 7// This isn't really testing anything ARM-specific; it's just a convenient8// 32-bit platform.9 10#define SWIFTCALL __attribute__((swiftcall))11#define OUT __attribute__((swift_indirect_result))12#define ERROR __attribute__((swift_error_result))13#define CONTEXT __attribute__((swift_context))14 15/*****************************************************************************/16/********************************** LOWERING *********************************/17/*****************************************************************************/18 19#define TEST(TYPE) \20 extern "C" SWIFTCALL TYPE return_##TYPE(void) { \21 TYPE result = {}; \22 return result; \23 } \24 extern "C" SWIFTCALL void take_##TYPE(TYPE v) { \25 } \26 extern "C" void test_##TYPE() { \27 take_##TYPE(return_##TYPE()); \28 }29 30/*****************************************************************************/31/*********************************** STRUCTS *********************************/32/*****************************************************************************/33 34typedef struct {35} struct_empty;36TEST(struct_empty);37// CHECK-LABEL: define {{.*}} @return_struct_empty()38// CHECK: ret void39// CHECK-LABEL: define {{.*}} @take_struct_empty()40// CHECK: ret void41 42// This is only properly testable in C++ because it relies on empty structs43// actually taking up space in a structure without requiring any extra data44// to be passed.45typedef struct {46 int x;47 struct_empty padding[2];48 char c1;49 float f0;50 float f1;51} struct_1;52TEST(struct_1);53// CHECK-LABEL: define {{.*}} @return_struct_1()54// CHECK: [[RET:%.*]] = alloca [[REC:%.*]], align 455// CHECK: @llvm.memset56// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG:{ i32, \[2 x i8\], i8, \[1 x i8\], float, float }]], ptr [[RET]], i32 0, i32 057// CHECK: [[FIRST:%.*]] = load i32, ptr [[T0]], align 458// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[RET]], i32 0, i32 259// CHECK: [[SECOND:%.*]] = load i8, ptr [[T0]], align 260// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[RET]], i32 0, i32 461// CHECK: [[THIRD:%.*]] = load float, ptr [[T0]], align 462// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[RET]], i32 0, i32 563// CHECK: [[FOURTH:%.*]] = load float, ptr [[T0]], align 464// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i8, float, float }]] poison, i32 [[FIRST]], 065// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i8 [[SECOND]], 166// CHECK: [[T2:%.*]] = insertvalue [[UAGG]] [[T1]], float [[THIRD]], 267// CHECK: [[T3:%.*]] = insertvalue [[UAGG]] [[T2]], float [[FOURTH]], 368// CHECK: ret [[UAGG]] [[T3]]69// CHECK-LABEL: define {{.*}} @take_struct_1(i32 %0, i8 %1, float %2, float %3)70// CHECK: [[V:%.*]] = alloca [[REC]], align 471// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 072// CHECK: store i32 %0, ptr [[T0]], align 473// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 274// CHECK: store i8 %1, ptr [[T0]], align 275// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 476// CHECK: store float %2, ptr [[T0]], align 477// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 578// CHECK: store float %3, ptr [[T0]], align 479// CHECK: ret void80// CHECK-LABEL: define{{.*}} void @test_struct_1()81// CHECK: [[TMP:%.*]] = alloca [[REC]], align 482// CHECK: [[CALL:%.*]] = call [[SWIFTCC:swiftcc]] [[UAGG]] @return_struct_1()83// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 084// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 085// CHECK: store i32 [[T1]], ptr [[T0]], align 486// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 287// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 188// CHECK: store i8 [[T1]], ptr [[T0]], align 289// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 490// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 291// CHECK: store float [[T1]], ptr [[T0]], align 492// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 593// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 394// CHECK: store float [[T1]], ptr [[T0]], align 495// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 096// CHECK: [[FIRST:%.*]] = load i32, ptr [[T0]], align 497// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 298// CHECK: [[SECOND:%.*]] = load i8, ptr [[T0]], align 299// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 4100// CHECK: [[THIRD:%.*]] = load float, ptr [[T0]], align 4101// CHECK: [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 5102// CHECK: [[FOURTH:%.*]] = load float, ptr [[T0]], align 4103// CHECK: call [[SWIFTCC]] void @take_struct_1(i32 [[FIRST]], i8 [[SECOND]], float [[THIRD]], float [[FOURTH]])104// CHECK: ret void105 106struct struct_indirect_1 {107 int x;108 ~struct_indirect_1();109};110TEST(struct_indirect_1)111 112// CHECK-LABEL: define {{.*}} void @return_struct_indirect_1({{.*}} dead_on_unwind noalias writable sret113 114// Should not be byval.115// CHECK-LABEL: define {{.*}} void @take_struct_indirect_1(ptr noundef{{( %.*)?}})116 117// Do a simple standalone test here of a function definition to ensure that118// we don't have problems due to failure to eagerly synthesize a copy119// constructor declaration.120class struct_trivial {121 int x;122};123// CHECK-LABEL: define{{.*}} swiftcc void @test_struct_trivial(i32{{( %.*)?}})124extern "C" SWIFTCALL125void test_struct_trivial(struct_trivial triv) {}126