2020-02-04 02:09:39 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
|
2009-09-16 23:53:40 +08:00
|
|
|
|
2009-11-23 07:01:23 +08:00
|
|
|
// Basic base class test.
|
|
|
|
struct f0_s0 { unsigned a; };
|
|
|
|
struct f0_s1 : public f0_s0 { void *b; };
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_Z2f05f0_s1(i32 %a0.coerce0, i8* %a0.coerce1)
|
2009-11-23 07:01:23 +08:00
|
|
|
void f0(f0_s1 a0) { }
|
|
|
|
|
|
|
|
// Check with two eight-bytes in base class.
|
|
|
|
struct f1_s0 { unsigned a; unsigned b; float c; };
|
|
|
|
struct f1_s1 : public f1_s0 { float d;};
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_Z2f15f1_s1(i64 %a0.coerce0, <2 x float> %a0.coerce1)
|
2009-11-23 07:01:23 +08:00
|
|
|
void f1(f1_s1 a0) { }
|
|
|
|
|
|
|
|
// Check with two eight-bytes in base class and merge.
|
|
|
|
struct f2_s0 { unsigned a; unsigned b; float c; };
|
|
|
|
struct f2_s1 : public f2_s0 { char d;};
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_Z2f25f2_s1(i64 %a0.coerce0, i64 %a0.coerce1)
|
2009-11-23 07:01:23 +08:00
|
|
|
void f2(f2_s1 a0) { }
|
2009-09-16 23:53:40 +08:00
|
|
|
|
2009-12-22 09:19:25 +08:00
|
|
|
// PR5831
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_Z2f34s3_1(i64 %x.coerce)
|
2009-12-22 09:19:25 +08:00
|
|
|
struct s3_0 {};
|
|
|
|
struct s3_1 { struct s3_0 a; long b; };
|
|
|
|
void f3(struct s3_1 x) {}
|
2010-05-15 08:00:37 +08:00
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define i64 @_Z4f4_0M2s4i(i64 %a)
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
// CHECK: define {{.*}} @_Z4f4_1M2s4FivE(i64 %a.coerce0, i64 %a.coerce1)
|
2010-05-15 08:00:37 +08:00
|
|
|
struct s4 {};
|
|
|
|
typedef int s4::* s4_mdp;
|
|
|
|
typedef int (s4::*s4_mfp)();
|
|
|
|
s4_mdp f4_0(s4_mdp a) { return a; }
|
|
|
|
s4_mfp f4_1(s4_mfp a) { return a; }
|
2010-07-01 03:14:05 +08:00
|
|
|
|
2014-10-03 00:56:57 +08:00
|
|
|
// A struct with <= one eightbyte before a member data pointer should still
|
|
|
|
// be allowed in registers.
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @{{.*}}f_struct_with_mdp{{.*}}(i8* %a.coerce0, i64 %a.coerce1)
|
2014-10-03 00:56:57 +08:00
|
|
|
struct struct_with_mdp { char *a; s4_mdp b; };
|
|
|
|
void f_struct_with_mdp(struct_with_mdp a) { (void)a; }
|
|
|
|
|
|
|
|
// A struct with anything before a member function will be too big and
|
|
|
|
// goes in memory.
|
2019-06-06 05:12:14 +08:00
|
|
|
// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_0{{.*}}(%struct{{.*}} byval(%struct{{.*}}) align 8 %a)
|
2014-10-03 00:56:57 +08:00
|
|
|
struct struct_with_mfp_0 { char a; s4_mfp b; };
|
|
|
|
void f_struct_with_mfp_0(struct_with_mfp_0 a) { (void)a; }
|
|
|
|
|
2019-06-06 05:12:14 +08:00
|
|
|
// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_1{{.*}}(%struct{{.*}} byval(%struct{{.*}}) align 8 %a)
|
2014-10-03 00:56:57 +08:00
|
|
|
struct struct_with_mfp_1 { void *a; s4_mfp b; };
|
|
|
|
void f_struct_with_mfp_1(struct_with_mfp_1 a) { (void)a; }
|
2010-07-01 03:14:05 +08:00
|
|
|
|
|
|
|
namespace PR7523 {
|
|
|
|
struct StringRef {
|
|
|
|
char *a;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AddKeyword(StringRef, int x);
|
|
|
|
|
|
|
|
void foo() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6PR75233fooEv()
|
2010-07-01 03:14:05 +08:00
|
|
|
// CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4)
|
|
|
|
AddKeyword(StringRef(), 4);
|
|
|
|
}
|
2010-07-30 01:04:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace PR7742 { // Also rdar://8250764
|
|
|
|
struct s2 {
|
|
|
|
float a[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct c2 : public s2 {};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define <2 x float> @_ZN6PR77423fooEPNS_2c2E(%"struct.PR7742::c2"* %P)
|
2010-07-30 01:04:54 +08:00
|
|
|
c2 foo(c2 *P) {
|
2012-05-03 09:34:46 +08:00
|
|
|
return c2();
|
2010-07-30 01:04:54 +08:00
|
|
|
}
|
|
|
|
|
2010-07-30 12:02:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace PR5179 {
|
|
|
|
struct B {};
|
|
|
|
|
|
|
|
struct B1 : B {
|
|
|
|
int* pa;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B2 : B {
|
|
|
|
B1 b1;
|
|
|
|
};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i8* @_ZN6PR51793barENS_2B2E(i32* %b2.coerce)
|
2010-07-30 12:02:24 +08:00
|
|
|
const void *bar(B2 b2) {
|
|
|
|
return b2.b1.pa;
|
|
|
|
}
|
|
|
|
}
|
2010-08-23 13:26:13 +08:00
|
|
|
|
|
|
|
namespace test5 {
|
|
|
|
struct Xbase { };
|
|
|
|
struct Empty { };
|
|
|
|
struct Y;
|
|
|
|
struct X : public Xbase {
|
|
|
|
Empty empty;
|
|
|
|
Y f();
|
|
|
|
};
|
|
|
|
struct Y : public X {
|
|
|
|
Empty empty;
|
|
|
|
};
|
|
|
|
X getX();
|
|
|
|
int takeY(const Y&, int y);
|
|
|
|
void g() {
|
|
|
|
// rdar://8340348 - The temporary for the X object needs to have a defined
|
|
|
|
// address when passed into X::f as 'this'.
|
|
|
|
takeY(getX().f(), 42);
|
|
|
|
}
|
|
|
|
// CHECK: void @_ZN5test51gEv()
|
|
|
|
// CHECK: alloca %"struct.test5::Y"
|
|
|
|
// CHECK: alloca %"struct.test5::X"
|
|
|
|
// CHECK: alloca %"struct.test5::Y"
|
|
|
|
}
|
2010-09-01 08:50:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
// rdar://8360877
|
|
|
|
namespace test6 {
|
|
|
|
struct outer {
|
|
|
|
int x;
|
|
|
|
struct epsilon_matcher {} e;
|
|
|
|
int f;
|
|
|
|
};
|
|
|
|
|
|
|
|
int test(outer x) {
|
|
|
|
return x.x + x.f;
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @_ZN5test64testENS_5outerE(i64 %x.coerce0, i32 %x.coerce1)
|
2010-09-01 08:50:20 +08:00
|
|
|
}
|
2011-06-29 15:04:55 +08:00
|
|
|
|
|
|
|
namespace test7 {
|
|
|
|
struct StringRef {char* ptr; long len; };
|
|
|
|
class A { public: ~A(); };
|
|
|
|
A x(A, A, long, long, StringRef) { return A(); }
|
|
|
|
// Check that the StringRef is passed byval instead of expanded
|
|
|
|
// (which would split it between registers and memory).
|
|
|
|
// rdar://problem/9686430
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK: define void @_ZN5test71xENS_1AES0_llNS_9StringRefE({{.*}} byval({{.*}}) align 8 {{%.*}})
|
2011-06-29 15:04:55 +08:00
|
|
|
|
|
|
|
// And a couple extra related tests:
|
|
|
|
A y(A, long double, long, long, StringRef) { return A(); }
|
|
|
|
// CHECK: define void @_ZN5test71yENS_1AEellNS_9StringRefE({{.*}} i8*
|
|
|
|
struct StringDouble {char * ptr; double d;};
|
|
|
|
A z(A, A, A, A, A, StringDouble) { return A(); }
|
|
|
|
A zz(A, A, A, A, StringDouble) { return A(); }
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK: define void @_ZN5test71zENS_1AES0_S0_S0_S0_NS_12StringDoubleE({{.*}} byval({{.*}}) align 8 {{%.*}})
|
2011-06-29 15:04:55 +08:00
|
|
|
// CHECK: define void @_ZN5test72zzENS_1AES0_S0_S0_NS_12StringDoubleE({{.*}} i8*
|
|
|
|
}
|
2011-07-14 05:58:55 +08:00
|
|
|
|
|
|
|
namespace test8 {
|
2019-06-06 05:12:14 +08:00
|
|
|
// CHECK: declare void @_ZN5test83fooENS_1BE(%"class.test8::B"* byval(%"class.test8::B") align 8)
|
2011-07-14 05:58:55 +08:00
|
|
|
class A {
|
|
|
|
char big[17];
|
|
|
|
};
|
|
|
|
|
|
|
|
class B : public A {};
|
|
|
|
|
|
|
|
void foo(B b);
|
|
|
|
void bar() {
|
|
|
|
B b;
|
|
|
|
foo(b);
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 09:34:46 +08:00
|
|
|
|
|
|
|
// PR4242
|
|
|
|
namespace test9 {
|
|
|
|
// Large enough to be passed indirectly.
|
|
|
|
struct S { void *data[3]; };
|
|
|
|
|
|
|
|
struct T { void *data[2]; };
|
|
|
|
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK: define void @_ZN5test93fooEPNS_1SEPNS_1TE([[S:%.*]]* %0, [[T:%.*]]* %1)
|
2012-05-03 09:34:46 +08:00
|
|
|
void foo(S*, T*) {}
|
|
|
|
|
2020-03-25 00:36:19 +08:00
|
|
|
// CHECK: define void @_ZN5test91aEiiiiNS_1TEPv([[S]]* noalias sret align 8 {{%.*}}, i32 %0, i32 %1, i32 %2, i32 %3, [[T]]* byval([[T]]) align 8 %4, i8* %5)
|
2012-05-03 09:34:46 +08:00
|
|
|
S a(int, int, int, int, T, void*) {
|
|
|
|
return S();
|
|
|
|
}
|
|
|
|
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK: define [[S]]* @_ZN5test91bEPNS_1SEiiiiNS_1TEPv([[S]]* {{%.*}}, i32 %0, i32 %1, i32 %2, i32 %3, [[T:%.*]]* byval([[T]]) align 8 %4, i8* %5)
|
2012-05-03 09:34:46 +08:00
|
|
|
S* b(S* sret, int, int, int, int, T, void*) {
|
|
|
|
return sret;
|
|
|
|
}
|
|
|
|
|
2020-03-25 00:36:19 +08:00
|
|
|
// CHECK: define void @_ZN5test91cEiiiNS_1TEPv([[S]]* noalias sret align 8 {{%.*}}, i32 %0, i32 %1, i32 %2, i8* {{%.*}}, i8* {{%.*}}, i8* %3)
|
2012-05-03 09:34:46 +08:00
|
|
|
S c(int, int, int, T, void*) {
|
|
|
|
return S();
|
|
|
|
}
|
|
|
|
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK: define [[S]]* @_ZN5test91dEPNS_1SEiiiNS_1TEPv([[S]]* {{%.*}}, i32 %0, i32 %1, i32 %2, i8* {{%.*}}, i8* {{%.*}}, i8* %3)
|
2012-05-03 09:34:46 +08:00
|
|
|
S* d(S* sret, int, int, int, T, void*) {
|
|
|
|
return sret;
|
|
|
|
}
|
|
|
|
}
|
2015-07-08 13:14:29 +08:00
|
|
|
|
|
|
|
namespace test10 {
|
|
|
|
#pragma pack(1)
|
|
|
|
struct BasePacked {
|
|
|
|
char one;
|
|
|
|
short two;
|
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
struct DerivedPacked : public BasePacked {
|
|
|
|
int three;
|
|
|
|
};
|
2019-06-06 05:12:14 +08:00
|
|
|
// CHECK-LABEL: define i32 @_ZN6test1020FuncForDerivedPackedENS_13DerivedPackedE({{.*}}* byval({{.*}}) align 8
|
2015-07-08 13:14:29 +08:00
|
|
|
int FuncForDerivedPacked(DerivedPacked d) {
|
|
|
|
return d.three;
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 13:49:13 +08:00
|
|
|
|
|
|
|
namespace test11 {
|
|
|
|
union U {
|
|
|
|
float f1;
|
|
|
|
char __attribute__((__vector_size__(1))) f2;
|
|
|
|
};
|
|
|
|
int f(union U u) { return u.f2[1]; }
|
|
|
|
// CHECK-LABEL: define i32 @_ZN6test111fENS_1UE(i32
|
|
|
|
}
|