2016-09-07 23:15:51 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=i386-pc-linux | FileCheck -check-prefix LINUX %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 %s
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
struct Empty {};
|
|
|
|
|
|
|
|
struct EmptyWithCtor {
|
|
|
|
EmptyWithCtor() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Small {
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This is a C++11 trivial and standard-layout struct but not a C++03 POD.
|
|
|
|
struct SmallCpp11NotCpp03Pod : Empty {
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SmallWithCtor {
|
|
|
|
SmallWithCtor() {}
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
2016-05-03 01:41:07 +08:00
|
|
|
struct Multibyte {
|
|
|
|
char a, b, c, d;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Packed {
|
|
|
|
short a;
|
|
|
|
int b;
|
|
|
|
short c;
|
|
|
|
};
|
|
|
|
|
2013-06-21 20:45:15 +08:00
|
|
|
struct SmallWithDtor {
|
|
|
|
SmallWithDtor();
|
|
|
|
~SmallWithDtor();
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
struct SmallWithVftable {
|
|
|
|
int x;
|
|
|
|
virtual void foo();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Medium {
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MediumWithCopyCtor {
|
|
|
|
MediumWithCopyCtor();
|
|
|
|
MediumWithCopyCtor(const struct MediumWithCopyCtor &);
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Big {
|
|
|
|
int a, b, c, d, e, f;
|
|
|
|
};
|
|
|
|
|
2014-05-03 08:33:28 +08:00
|
|
|
struct BigWithDtor {
|
|
|
|
BigWithDtor();
|
|
|
|
~BigWithDtor();
|
|
|
|
int a, b, c, d, e, f;
|
|
|
|
};
|
|
|
|
|
2017-01-14 01:18:19 +08:00
|
|
|
struct BaseNoByval : Small {
|
|
|
|
int bb;
|
|
|
|
};
|
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// WIN32: declare dso_local void @"{{.*take_bools_and_chars.*}}"
|
2014-02-01 08:04:45 +08:00
|
|
|
// WIN32: (<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor,
|
2014-04-11 03:09:43 +08:00
|
|
|
// WIN32: i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>* inalloca)
|
2014-02-01 08:04:45 +08:00
|
|
|
void take_bools_and_chars(char a, char b, SmallWithDtor c, char d, bool e, int f, bool g);
|
|
|
|
void call_bools_and_chars() {
|
|
|
|
take_bools_and_chars('A', 'B', SmallWithDtor(), 'D', true, 13, false);
|
|
|
|
}
|
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
// Returning structs that fit into a register.
|
|
|
|
Small small_return() { return Small(); }
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z12small_returnv(%struct.Small* noalias sret %agg.result)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
|
|
|
|
// WIN64: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
Medium medium_return() { return Medium(); }
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z13medium_returnv(%struct.Medium* noalias sret %agg.result)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
|
|
|
|
// WIN64: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
// Returning structs that fit into a register but are not POD.
|
|
|
|
SmallCpp11NotCpp03Pod small_non_pod_return() { return SmallCpp11NotCpp03Pod(); }
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z20small_non_pod_returnv(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
|
|
|
|
// WIN64: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
SmallWithCtor small_with_ctor_return() { return SmallWithCtor(); }
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z22small_with_ctor_returnv(%struct.SmallWithCtor* noalias sret %agg.result)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
|
|
|
|
// WIN64: define dso_local void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
|
2016-08-26 02:23:28 +08:00
|
|
|
// FIXME: The 'sret' mark here doesn't seem to be enough to convince LLVM to
|
|
|
|
// preserve the hidden sret pointer in R0 across the function.
|
2018-03-17 04:36:49 +08:00
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
SmallWithVftable small_with_vftable_return() { return SmallWithVftable(); }
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z25small_with_vftable_returnv(%struct.SmallWithVftable* noalias sret %agg.result)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
|
|
|
|
// WIN64: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
MediumWithCopyCtor medium_with_copy_ctor_return() { return MediumWithCopyCtor(); }
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z28medium_with_copy_ctor_returnv(%struct.MediumWithCopyCtor* noalias sret %agg.result)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
|
|
|
|
// WIN64: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
|
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
// Returning a large struct that doesn't fit into a register.
|
|
|
|
Big big_return() { return Big(); }
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z10big_returnv(%struct.Big* noalias sret %agg.result)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
|
|
|
|
// WIN64: define dso_local void @"?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
void small_arg(Small s) {}
|
2015-04-04 02:10:29 +08:00
|
|
|
// LINUX-LABEL: define void @_Z9small_arg5Small(i32 %s.0)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?small_arg@@YAXUSmall@@@Z"(i32 %s.0)
|
|
|
|
// WIN64: define dso_local void @"?small_arg@@YAXUSmall@@@Z"(i32 %s.coerce)
|
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?small_arg@@YAXUSmall@@@Z"([1 x i32] %s.coerce)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void medium_arg(Medium s) {}
|
2015-04-04 02:10:29 +08:00
|
|
|
// LINUX-LABEL: define void @_Z10medium_arg6Medium(i32 %s.0, i32 %s.1)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?medium_arg@@YAXUMedium@@@Z"(i32 %s.0, i32 %s.1)
|
|
|
|
// WIN64: define dso_local void @"?medium_arg@@YAXUMedium@@@Z"(i64 %s.coerce)
|
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?medium_arg@@YAXUMedium@@@Z"([2 x i32] %s.coerce)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
2017-01-14 01:18:19 +08:00
|
|
|
void base_no_byval_arg(BaseNoByval s) {}
|
|
|
|
// LINUX-LABEL: define void @_Z17base_no_byval_arg11BaseNoByval(%struct.BaseNoByval* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?base_no_byval_arg@@YAXUBaseNoByval@@@Z"(i32 %s.0, i32 %s.1)
|
|
|
|
// WIN64: define dso_local void @"?base_no_byval_arg@@YAXUBaseNoByval@@@Z"(i64 %s.coerce)
|
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?base_no_byval_arg@@YAXUBaseNoByval@@@Z"([2 x i32] %s.coerce)
|
2017-01-14 01:18:19 +08:00
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
void small_arg_with_ctor(SmallWithCtor s) {}
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z19small_arg_with_ctor13SmallWithCtor(%struct.SmallWithCtor* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.0)
|
|
|
|
// WIN64: define dso_local void @"?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.coerce)
|
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"([1 x i32] %s.coerce)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
2016-05-03 01:41:07 +08:00
|
|
|
// FIXME: We could coerce to a series of i32s here if we wanted to.
|
|
|
|
void multibyte_arg(Multibyte s) {}
|
|
|
|
// LINUX-LABEL: define void @_Z13multibyte_arg9Multibyte(%struct.Multibyte* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?multibyte_arg@@YAXUMultibyte@@@Z"(%struct.Multibyte* byval align 4 %s)
|
|
|
|
// WIN64: define dso_local void @"?multibyte_arg@@YAXUMultibyte@@@Z"(i32 %s.coerce)
|
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?multibyte_arg@@YAXUMultibyte@@@Z"([1 x i32] %s.coerce)
|
2016-05-03 01:41:07 +08:00
|
|
|
|
|
|
|
void packed_arg(Packed s) {}
|
|
|
|
// LINUX-LABEL: define void @_Z10packed_arg6Packed(%struct.Packed* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?packed_arg@@YAXUPacked@@@Z"(%struct.Packed* byval align 4 %s)
|
|
|
|
// WIN64: define dso_local void @"?packed_arg@@YAXUPacked@@@Z"(%struct.Packed* %s)
|
2016-05-03 01:41:07 +08:00
|
|
|
|
2013-06-21 20:45:15 +08:00
|
|
|
// Test that dtors are invoked in the callee.
|
|
|
|
void small_arg_with_dtor(SmallWithDtor s) {}
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(<{ %struct.SmallWithDtor }>* inalloca) {{.*}} {
|
|
|
|
// WIN32: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
|
2013-06-21 20:45:15 +08:00
|
|
|
// WIN32: }
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %s.coerce) {{.*}} {
|
|
|
|
// WIN64: call void @"??1SmallWithDtor@@QEAA@XZ"
|
2013-06-21 20:45:15 +08:00
|
|
|
// WIN64: }
|
|
|
|
|
2016-08-26 02:23:28 +08:00
|
|
|
// FIXME: MSVC incompatible!
|
2018-03-17 04:36:49 +08:00
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(%struct.SmallWithDtor* %s) {{.*}} {
|
|
|
|
// WOA: call arm_aapcs_vfpcc void @"??1SmallWithDtor@@QAA@XZ"(%struct.SmallWithDtor* %s)
|
2016-08-26 02:23:28 +08:00
|
|
|
// WOA: }
|
|
|
|
|
2014-05-03 08:33:28 +08:00
|
|
|
void call_small_arg_with_dtor() {
|
|
|
|
small_arg_with_dtor(SmallWithDtor());
|
|
|
|
}
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN64-LABEL: define dso_local void @"?call_small_arg_with_dtor@@YAXXZ"()
|
|
|
|
// WIN64: call %struct.SmallWithDtor* @"??0SmallWithDtor@@QEAA@XZ"
|
|
|
|
// WIN64: call void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %{{.*}})
|
2014-05-03 08:33:28 +08:00
|
|
|
// WIN64: ret void
|
|
|
|
|
2013-06-21 20:45:15 +08:00
|
|
|
// Test that references aren't destroyed in the callee.
|
|
|
|
void ref_small_arg_with_dtor(const SmallWithDtor &s) { }
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s) {{.*}} {
|
|
|
|
// WIN32-NOT: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
|
2013-06-21 20:45:15 +08:00
|
|
|
// WIN32: }
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN64-LABEL: define dso_local void @"?ref_small_arg_with_dtor@@YAXAEBUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s)
|
2014-05-03 08:33:28 +08:00
|
|
|
|
|
|
|
void big_arg_with_dtor(BigWithDtor s) {}
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN64-LABEL: define dso_local void @"?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %s)
|
|
|
|
// WIN64: call void @"??1BigWithDtor@@QEAA@XZ"
|
2014-05-03 08:33:28 +08:00
|
|
|
// WIN64: }
|
|
|
|
|
|
|
|
void call_big_arg_with_dtor() {
|
|
|
|
big_arg_with_dtor(BigWithDtor());
|
|
|
|
}
|
|
|
|
// We can elide the copy of the temporary in the caller, because this object is
|
|
|
|
// larger than 8 bytes and is passed indirectly.
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN64-LABEL: define dso_local void @"?call_big_arg_with_dtor@@YAXXZ"()
|
|
|
|
// WIN64: call %struct.BigWithDtor* @"??0BigWithDtor@@QEAA@XZ"
|
|
|
|
// WIN64: call void @"?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %{{.*}})
|
|
|
|
// WIN64-NOT: call void @"??1BigWithDtor@@QEAA@XZ"
|
2014-05-03 08:33:28 +08:00
|
|
|
// WIN64: ret void
|
2013-06-21 20:45:15 +08:00
|
|
|
|
|
|
|
// Test that temporaries passed by reference are destroyed in the caller.
|
|
|
|
void temporary_ref_with_dtor() {
|
|
|
|
ref_small_arg_with_dtor(SmallWithDtor());
|
|
|
|
}
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?temporary_ref_with_dtor@@YAXXZ"() {{.*}} {
|
|
|
|
// WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"??0SmallWithDtor@@QAE@XZ"
|
|
|
|
// WIN32: call void @"?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"
|
|
|
|
// WIN32: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
|
2013-06-21 20:45:15 +08:00
|
|
|
// WIN32: }
|
|
|
|
|
|
|
|
void takes_two_by_val_with_dtor(SmallWithDtor a, SmallWithDtor b);
|
|
|
|
void eh_cleanup_arg_with_dtor() {
|
|
|
|
takes_two_by_val_with_dtor(SmallWithDtor(), SmallWithDtor());
|
|
|
|
}
|
|
|
|
// When exceptions are off, we don't have any cleanups. See
|
|
|
|
// microsoft-abi-exceptions.cpp for these cleanups.
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?eh_cleanup_arg_with_dtor@@YAXXZ"() {{.*}} {
|
|
|
|
// WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"??0SmallWithDtor@@QAE@XZ"
|
|
|
|
// WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"??0SmallWithDtor@@QAE@XZ"
|
|
|
|
// WIN32: call void @"?takes_two_by_val_with_dtor@@YAXUSmallWithDtor@@0@Z"
|
|
|
|
// WIN32-NOT: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
|
2013-06-21 20:45:15 +08:00
|
|
|
// WIN32: }
|
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
void small_arg_with_vftable(SmallWithVftable s) {}
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z22small_arg_with_vftable16SmallWithVftable(%struct.SmallWithVftable* %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(<{ %struct.SmallWithVftable }>* inalloca)
|
|
|
|
// WIN64: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* %s)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void medium_arg_with_copy_ctor(MediumWithCopyCtor s) {}
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z25medium_arg_with_copy_ctor18MediumWithCopyCtor(%struct.MediumWithCopyCtor* %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(<{ %struct.MediumWithCopyCtor }>* inalloca)
|
|
|
|
// WIN64: define dso_local void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
|
|
|
|
// WOA: define dso_local arm_aapcs_vfpcc void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void big_arg(Big s) {}
|
2013-08-15 14:47:53 +08:00
|
|
|
// LINUX-LABEL: define void @_Z7big_arg3Big(%struct.Big* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?big_arg@@YAXUBig@@@Z"(%struct.Big* byval align 4 %s)
|
|
|
|
// WIN64: define dso_local void @"?big_arg@@YAXUBig@@@Z"(%struct.Big* %s)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
2016-05-03 06:42:34 +08:00
|
|
|
// PR27607: We would attempt to load i32 value out of the reference instead of
|
|
|
|
// just loading the pointer from the struct during argument expansion.
|
|
|
|
struct RefField {
|
|
|
|
RefField(int &x);
|
|
|
|
int &x;
|
|
|
|
};
|
|
|
|
void takes_ref_field(RefField s) {}
|
|
|
|
// LINUX-LABEL: define void @_Z15takes_ref_field8RefField(%struct.RefField* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?takes_ref_field@@YAXURefField@@@Z"(i32* %s.0)
|
|
|
|
// WIN64: define dso_local void @"?takes_ref_field@@YAXURefField@@@Z"(i64 %s.coerce)
|
2016-05-03 06:42:34 +08:00
|
|
|
|
|
|
|
void pass_ref_field() {
|
|
|
|
int x;
|
|
|
|
takes_ref_field(RefField(x));
|
|
|
|
}
|
|
|
|
// LINUX-LABEL: define void @_Z14pass_ref_fieldv()
|
|
|
|
// LINUX: call void @_Z15takes_ref_field8RefField(%struct.RefField* byval align 4 %{{.*}})
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32-LABEL: define dso_local void @"?pass_ref_field@@YAXXZ"()
|
|
|
|
// WIN32: call void @"?takes_ref_field@@YAXURefField@@@Z"(i32* %{{.*}})
|
|
|
|
// WIN64-LABEL: define dso_local void @"?pass_ref_field@@YAXXZ"()
|
|
|
|
// WIN64: call void @"?takes_ref_field@@YAXURefField@@@Z"(i64 %{{.*}})
|
2016-05-03 06:42:34 +08:00
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
class Class {
|
|
|
|
public:
|
|
|
|
Small thiscall_method_small() { return Small(); }
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class21thiscall_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} x86_thiscallcc void @"?thiscall_method_small@Class@@QAE?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?thiscall_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
SmallWithCtor thiscall_method_small_with_ctor() { return SmallWithCtor(); }
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class31thiscall_method_small_with_ctorEv(%struct.SmallWithCtor* noalias sret %agg.result, %class.Class* %this)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} x86_thiscallcc void @"?thiscall_method_small_with_ctor@Class@@QAE?AUSmallWithCtor@@XZ"(%class.Class* %this, %struct.SmallWithCtor* noalias sret %agg.result)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?thiscall_method_small_with_ctor@Class@@QEAA?AUSmallWithCtor@@XZ"(%class.Class* %this, %struct.SmallWithCtor* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
Small __cdecl cdecl_method_small() { return Small(); }
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class18cdecl_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} void @"?cdecl_method_small@Class@@QAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?cdecl_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
Big __cdecl cdecl_method_big() { return Big(); }
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class16cdecl_method_bigEv(%struct.Big* noalias sret %agg.result, %class.Class* %this)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} void @"?cdecl_method_big@Class@@QAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?cdecl_method_big@Class@@QEAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void thiscall_method_arg(Empty s) {}
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Empty(%class.Class* %this)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUEmpty@@@Z"(%class.Class* %this, %struct.Empty* byval align 4 %s)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUEmpty@@@Z"(%class.Class* %this, i8 %s.coerce)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void thiscall_method_arg(EmptyWithCtor s) {}
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13EmptyWithCtor(%class.Class* %this)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUEmptyWithCtor@@@Z"(%class.Class* %this, %struct.EmptyWithCtor* byval align 4 %s)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUEmptyWithCtor@@@Z"(%class.Class* %this, i8 %s.coerce)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void thiscall_method_arg(Small s) {}
|
2015-04-04 02:10:29 +08:00
|
|
|
// LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Small(%class.Class* %this, i32 %s.0)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUSmall@@@Z"(%class.Class* %this, i32 %s.0)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUSmall@@@Z"(%class.Class* %this, i32 %s.coerce)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void thiscall_method_arg(SmallWithCtor s) {}
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13SmallWithCtor(%class.Class* %this, %struct.SmallWithCtor* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUSmallWithCtor@@@Z"(%class.Class* %this, i32 %s.0)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUSmallWithCtor@@@Z"(%class.Class* %this, i32 %s.coerce)
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
void thiscall_method_arg(Big s) {}
|
|
|
|
// LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE3Big(%class.Class* %this, %struct.Big* byval align 4 %s)
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUBig@@@Z"(%class.Class* %this, %struct.Big* byval align 4 %s)
|
|
|
|
// WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUBig@@@Z"(%class.Class* %this, %struct.Big* %s)
|
2013-04-17 20:54:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void use_class() {
|
|
|
|
Class c;
|
|
|
|
c.thiscall_method_small();
|
|
|
|
c.thiscall_method_small_with_ctor();
|
|
|
|
|
|
|
|
c.cdecl_method_small();
|
|
|
|
c.cdecl_method_big();
|
|
|
|
|
|
|
|
c.thiscall_method_arg(Empty());
|
|
|
|
c.thiscall_method_arg(EmptyWithCtor());
|
|
|
|
c.thiscall_method_arg(Small());
|
|
|
|
c.thiscall_method_arg(SmallWithCtor());
|
|
|
|
c.thiscall_method_arg(Big());
|
|
|
|
}
|
2013-06-21 20:45:15 +08:00
|
|
|
|
|
|
|
struct X {
|
|
|
|
X();
|
|
|
|
~X();
|
|
|
|
};
|
|
|
|
void g(X) {
|
|
|
|
}
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?g@@YAXUX@@@Z"(<{ %struct.X, [3 x i8] }>* inalloca) {{.*}} {
|
|
|
|
// WIN32: call x86_thiscallcc void @"??1X@@QAE@XZ"(%struct.X* {{.*}})
|
2013-06-21 20:45:15 +08:00
|
|
|
// WIN32: }
|
|
|
|
void f() {
|
|
|
|
g(X());
|
|
|
|
}
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: define dso_local void @"?f@@YAXXZ"() {{.*}} {
|
|
|
|
// WIN32-NOT: call {{.*}} @"??1X@@QAE@XZ"
|
2013-06-21 20:45:15 +08:00
|
|
|
// WIN32: }
|
2014-02-01 08:04:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
// We used to crash on this due to the mixture of POD byval and non-trivial
|
|
|
|
// byval.
|
|
|
|
|
|
|
|
struct NonTrivial {
|
|
|
|
NonTrivial();
|
|
|
|
NonTrivial(const NonTrivial &o);
|
|
|
|
~NonTrivial();
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
struct POD { int b; };
|
|
|
|
|
|
|
|
int foo(NonTrivial a, POD b);
|
|
|
|
void bar() {
|
|
|
|
POD b;
|
|
|
|
b.b = 13;
|
|
|
|
int c = foo(NonTrivial(), b);
|
|
|
|
}
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32-LABEL: define dso_local void @"?bar@test2@@YAXXZ"() {{.*}} {
|
2014-03-09 15:09:06 +08:00
|
|
|
// WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty:<{ %"struct.test2::NonTrivial", %"struct.test2::POD" }>]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// WIN32: getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 1
|
2014-02-01 08:04:45 +08:00
|
|
|
// WIN32: call void @llvm.memcpy
|
2015-02-28 03:18:17 +08:00
|
|
|
// WIN32: getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 0
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: call x86_thiscallcc %"struct.test2::NonTrivial"* @"??0NonTrivial@test2@@QAE@XZ"
|
|
|
|
// WIN32: call i32 @"?foo@test2@@YAHUNonTrivial@1@UPOD@1@@Z"([[argmem_ty]]* inalloca %argmem)
|
2014-02-01 08:04:45 +08:00
|
|
|
// WIN32: ret void
|
|
|
|
// WIN32: }
|
|
|
|
|
|
|
|
}
|
2014-04-01 00:12:47 +08:00
|
|
|
|
2014-04-11 03:09:43 +08:00
|
|
|
namespace test3 {
|
|
|
|
|
|
|
|
// Check that we padded the inalloca struct to a multiple of 4.
|
|
|
|
struct NonTrivial {
|
|
|
|
NonTrivial();
|
|
|
|
NonTrivial(const NonTrivial &o);
|
|
|
|
~NonTrivial();
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
void foo(NonTrivial a, bool b) { }
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32-LABEL: define dso_local void @"?foo@test3@@YAXUNonTrivial@1@_N@Z"(<{ %"struct.test3::NonTrivial", i8, [3 x i8] }>* inalloca)
|
2014-04-11 03:09:43 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-01 00:12:47 +08:00
|
|
|
// We would crash here because the later definition of ForwardDeclare1 results
|
|
|
|
// in a different IR type for the value we want to store. However, the alloca's
|
|
|
|
// type will use the argument type selected by fn1.
|
|
|
|
struct ForwardDeclare1;
|
|
|
|
|
|
|
|
typedef void (*FnPtr1)(ForwardDeclare1);
|
2014-04-02 08:16:53 +08:00
|
|
|
void fn1(FnPtr1 a, SmallWithDtor b) { }
|
2014-04-01 00:12:47 +08:00
|
|
|
|
|
|
|
struct ForwardDeclare1 {};
|
|
|
|
|
2014-04-02 08:16:53 +08:00
|
|
|
void fn2(FnPtr1 a, SmallWithDtor b) { fn1(a, b); };
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32-LABEL: define dso_local void @"?fn2@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"
|
2015-02-28 03:18:17 +08:00
|
|
|
// WIN32: %[[a:[^ ]*]] = getelementptr inbounds [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]], [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]]* %{{.*}}, i32 0, i32 0
|
2014-04-02 08:16:53 +08:00
|
|
|
// WIN32: %[[a1:[^ ]*]] = bitcast {}** %[[a]] to void [[dst_ty:\(%struct.ForwardDeclare1\*\)\*]]*
|
|
|
|
// WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// WIN32: %[[gep1:[^ ]*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 1
|
2014-04-02 08:16:53 +08:00
|
|
|
// WIN32: %[[bc1:[^ ]*]] = bitcast %struct.SmallWithDtor* %[[gep1]] to i8*
|
Change memcpy/memove/memset to have dest and source alignment attributes (Step 1).
Summary:
Upstream LLVM is changing the the prototypes of the @llvm.memcpy/memmove/memset
intrinsics. This change updates the Clang tests for this change.
The @llvm.memcpy/memmove/memset intrinsics currently have an explicit argument
which is required to be a constant integer. It represents the alignment of the
dest (and source), and so must be the minimum of the actual alignment of the
two.
This change removes the alignment argument in favour of placing the alignment
attribute on the source and destination pointers of the memory intrinsic call.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 100, i32 4, i1 false)
will now read
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %dest, i8* align 4 %src, i32 100, i1 false)
At this time the source and destination alignments must be the same (Step 1).
Step 2 of the change, to be landed shortly, will relax that contraint and allow
the source and destination to have different alignments.
llvm-svn: 322964
2018-01-20 01:12:54 +08:00
|
|
|
// WIN32: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %[[bc1]], i8* align 4 {{.*}}, i32 4, i1 false)
|
2015-02-28 05:19:58 +08:00
|
|
|
// WIN32: %[[a2:[^ ]*]] = load void [[dst_ty]], void [[dst_ty]]* %[[a1]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// WIN32: %[[gep2:[^ ]*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 0
|
2014-04-02 08:16:53 +08:00
|
|
|
// WIN32: %[[addr:[^ ]*]] = bitcast {}** %[[gep2]] to void [[dst_ty]]*
|
|
|
|
// WIN32: store void [[dst_ty]] %[[a2]], void [[dst_ty]]* %[[addr]], align 4
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32: call void @"?fn1@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"([[argmem_ty]]* inalloca %[[argmem]])
|
2016-09-07 23:15:51 +08:00
|
|
|
|
|
|
|
namespace pr30293 {
|
|
|
|
// Virtual methods living in a secondary vtable take i8* as their 'this'
|
|
|
|
// parameter because the 'this' parameter on entry points to the secondary
|
|
|
|
// vptr. We used to have a bug where we didn't apply this rule consistently,
|
|
|
|
// and it would cause assertion failures when used with inalloca.
|
|
|
|
struct A {
|
|
|
|
virtual void f();
|
|
|
|
};
|
|
|
|
struct B {
|
|
|
|
virtual void __cdecl h(SmallWithDtor);
|
|
|
|
};
|
|
|
|
struct C final : A, B {
|
|
|
|
void g();
|
|
|
|
void __cdecl h(SmallWithDtor);
|
|
|
|
void f();
|
|
|
|
};
|
|
|
|
void C::g() { return h(SmallWithDtor()); }
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN32-LABEL: define dso_local x86_thiscallcc void @"?g@C@pr30293@@QAEXXZ"(%"struct.pr30293::C"* %this)
|
|
|
|
// WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"??0SmallWithDtor@@QAE@XZ"
|
|
|
|
// WIN32: call void @"?h@C@pr30293@@UAAXUSmallWithDtor@@@Z"(<{ i8*, %struct.SmallWithDtor }>* inalloca %{{[^,)]*}})
|
|
|
|
// WIN32: declare dso_local void @"?h@C@pr30293@@UAAXUSmallWithDtor@@@Z"(<{ i8*, %struct.SmallWithDtor }>* inalloca)
|
2016-09-07 23:15:51 +08:00
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// WIN64-LABEL: define dso_local void @"?g@C@pr30293@@QEAAXXZ"(%"struct.pr30293::C"* %this)
|
|
|
|
// WIN64: declare dso_local void @"?h@C@pr30293@@UEAAXUSmallWithDtor@@@Z"(i8*, i32)
|
2016-09-07 23:15:51 +08:00
|
|
|
}
|