1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s 20a8f847e97f40cce51dc69051b964732333dc028Anders Carlsson 3ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbar// Basic base class test. 4ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarstruct f0_s0 { unsigned a; }; 5ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarstruct f0_s1 : public f0_s0 { void *b; }; 6eb9d81dff99d4996f41c93ce71b08aaf753cbae8Anders Carlsson// CHECK: define void @_Z2f05f0_s1(i32 %a0.coerce0, i8* %a0.coerce1) 7ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarvoid f0(f0_s1 a0) { } 8ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbar 9ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbar// Check with two eight-bytes in base class. 10ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarstruct f1_s0 { unsigned a; unsigned b; float c; }; 11ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarstruct f1_s1 : public f1_s0 { float d;}; 12eb9d81dff99d4996f41c93ce71b08aaf753cbae8Anders Carlsson// CHECK: define void @_Z2f15f1_s1(i64 %a0.coerce0, <2 x float> %a0.coerce1) 13ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarvoid f1(f1_s1 a0) { } 14ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbar 15ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbar// Check with two eight-bytes in base class and merge. 16ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarstruct f2_s0 { unsigned a; unsigned b; float c; }; 17ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarstruct f2_s1 : public f2_s0 { char d;}; 18225e286110bcc8b7b1ff8b35f0d51a10a158b18cChris Lattner// CHECK: define void @_Z2f25f2_s1(i64 %a0.coerce0, i64 %a0.coerce1) 19ce9f423d2ce4b8699d9f6c7623053f645ac4dc6dDaniel Dunbarvoid f2(f2_s1 a0) { } 200a8f847e97f40cce51dc69051b964732333dc028Anders Carlsson 214971ff8eea7800bd2a73652add6dcf7a4adf5f74Daniel Dunbar// PR5831 22117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner// CHECK: define void @_Z2f34s3_1(i64 %x.coerce) 234971ff8eea7800bd2a73652add6dcf7a4adf5f74Daniel Dunbarstruct s3_0 {}; 244971ff8eea7800bd2a73652add6dcf7a4adf5f74Daniel Dunbarstruct s3_1 { struct s3_0 a; long b; }; 254971ff8eea7800bd2a73652add6dcf7a4adf5f74Daniel Dunbarvoid f3(struct s3_1 x) {} 2667d438d39a1cc37c372a2684dc354f58d0169bb1Daniel Dunbar 27800588fd230d2c37ddce8fbf4a3881352715d700Chris Lattner// CHECK: define i64 @_Z4f4_0M2s4i(i64 %a) 289c254f0415bef9a0bafe5b5026ddb54b727597b1Chris Lattner// CHECK: define {{.*}} @_Z4f4_1M2s4FivE(i64 %a.coerce0, i64 %a.coerce1) 2967d438d39a1cc37c372a2684dc354f58d0169bb1Daniel Dunbarstruct s4 {}; 3067d438d39a1cc37c372a2684dc354f58d0169bb1Daniel Dunbartypedef int s4::* s4_mdp; 3167d438d39a1cc37c372a2684dc354f58d0169bb1Daniel Dunbartypedef int (s4::*s4_mfp)(); 3267d438d39a1cc37c372a2684dc354f58d0169bb1Daniel Dunbars4_mdp f4_0(s4_mdp a) { return a; } 3367d438d39a1cc37c372a2684dc354f58d0169bb1Daniel Dunbars4_mfp f4_1(s4_mfp a) { return a; } 34bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner 35bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner 36bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattnernamespace PR7523 { 37bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattnerstruct StringRef { 38bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner char *a; 39bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner}; 40bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner 41bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattnervoid AddKeyword(StringRef, int x); 42bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner 43bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattnervoid foo() { 44bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner // CHECK: define void @_ZN6PR75233fooEv() 45bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner // CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4) 46bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner AddKeyword(StringRef(), 4); 47bcaedaed309ce453a992fdeef4a4c908cc7d9dfbChris Lattner} 48a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner} 49a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner 50a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattnernamespace PR7742 { // Also rdar://8250764 51a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner struct s2 { 52a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner float a[2]; 53a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner }; 54a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner 55a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner struct c2 : public s2 {}; 56a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner 57eb9d81dff99d4996f41c93ce71b08aaf753cbae8Anders Carlsson // CHECK: define <2 x float> @_ZN6PR77423fooEPNS_2c2E(%"struct.PR7742::c2"* %P) 58a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner c2 foo(c2 *P) { 5992c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall return c2(); 60a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner } 61a7206c5367c2e5879fe6d9a07ed50aa003a56976Chris Lattner 62117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner} 63117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner 64117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattnernamespace PR5179 { 65117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner struct B {}; 66117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner 67117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner struct B1 : B { 68117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner int* pa; 69117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner }; 70117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner 71117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner struct B2 : B { 72117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner B1 b1; 73117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner }; 74117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner 75117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner // CHECK: define i8* @_ZN6PR51793barENS_2B2E(i32* %b2.coerce) 76117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner const void *bar(B2 b2) { 77117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner return b2.b1.pa; 78117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner } 79117e3f4cd4d6ea41c3202da8729f94168c5c8239Chris Lattner} 80b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner 81b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattnernamespace test5 { 82b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner struct Xbase { }; 83b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner struct Empty { }; 84b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner struct Y; 85b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner struct X : public Xbase { 86b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner Empty empty; 87b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner Y f(); 88b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner }; 89b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner struct Y : public X { 90b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner Empty empty; 91b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner }; 92b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner X getX(); 93b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner int takeY(const Y&, int y); 94b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner void g() { 95b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner // rdar://8340348 - The temporary for the X object needs to have a defined 96b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner // address when passed into X::f as 'this'. 97b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner takeY(getX().f(), 42); 98b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner } 99b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner // CHECK: void @_ZN5test51gEv() 100b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner // CHECK: alloca %"struct.test5::Y" 101b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner // CHECK: alloca %"struct.test5::X" 102b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner // CHECK: alloca %"struct.test5::Y" 103b6c504b9101251bcb364dd9becbb887c97db27d3Chris Lattner} 10466e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner 10566e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner 10666e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner// rdar://8360877 10766e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattnernamespace test6 { 10866e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner struct outer { 10966e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner int x; 11066e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner struct epsilon_matcher {} e; 11166e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner int f; 11266e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner }; 11366e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner 11466e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner int test(outer x) { 11566e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner return x.x + x.f; 11666e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner } 11766e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner // CHECK: define i32 @_ZN5test64testENS_5outerE(i64 %x.coerce0, i32 %x.coerce1) 11866e7b68b0016aeebe349e21ace93ff0178665d69Chris Lattner} 119ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman 120ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedmannamespace test7 { 121ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman struct StringRef {char* ptr; long len; }; 122ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman class A { public: ~A(); }; 123ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman A x(A, A, long, long, StringRef) { return A(); } 124ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // Check that the StringRef is passed byval instead of expanded 125ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // (which would split it between registers and memory). 126ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // rdar://problem/9686430 127ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // CHECK: define void @_ZN5test71xENS_1AES0_llNS_9StringRefE({{.*}} byval align 8) 128ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman 129ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // And a couple extra related tests: 130ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman A y(A, long double, long, long, StringRef) { return A(); } 131ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // CHECK: define void @_ZN5test71yENS_1AEellNS_9StringRefE({{.*}} i8* 132ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman struct StringDouble {char * ptr; double d;}; 133ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman A z(A, A, A, A, A, StringDouble) { return A(); } 134ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman A zz(A, A, A, A, StringDouble) { return A(); } 135ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // CHECK: define void @_ZN5test71zENS_1AES0_S0_S0_S0_NS_12StringDoubleE({{.*}} byval align 8) 136ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman // CHECK: define void @_ZN5test72zzENS_1AES0_S0_S0_NS_12StringDoubleE({{.*}} i8* 137ded137fcab19f0aace08a28b5c91574e6b23debcEli Friedman} 138b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes 139b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopesnamespace test8 { 140b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes // CHECK: declare void @_ZN5test83fooENS_1BE(%"class.test8::B"* byval align 8) 141b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes class A { 142b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes char big[17]; 143b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes }; 144b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes 145b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes class B : public A {}; 146b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes 147b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes void foo(B b); 148b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes void bar() { 149b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes B b; 150b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes foo(b); 151b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes } 152b8981df0ed2886dfa221f2fad6d86872c39d3549Bruno Cardoso Lopes} 15392c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall 15492c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall// PR4242 15592c6c90e9099b7e27073056b154b2d5e7d5449b1John McCallnamespace test9 { 15692c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall // Large enough to be passed indirectly. 15792c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall struct S { void *data[3]; }; 15892c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall 15992c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall struct T { void *data[2]; }; 16092c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall 16192c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall // CHECK: define void @_ZN5test93fooEPNS_1SEPNS_1TE([[S:%.*]]*, [[T:%.*]]*) 16292c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall void foo(S*, T*) {} 16392c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall 16492c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall // CHECK: define void @_ZN5test91aEiiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i32, [[T]]* byval align 8, i8*) 16592c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall S a(int, int, int, int, T, void*) { 16692c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall return S(); 16792c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall } 16892c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall 16992c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall // CHECK: define [[S]]* @_ZN5test91bEPNS_1SEiiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i32, [[T:%.*]]* byval align 8, i8*) 17092c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall S* b(S* sret, int, int, int, int, T, void*) { 17192c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall return sret; 17292c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall } 17392c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall 17492c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall // CHECK: define void @_ZN5test91cEiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*) 17592c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall S c(int, int, int, T, void*) { 17692c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall return S(); 17792c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall } 17892c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall 17992c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall // CHECK: define [[S]]* @_ZN5test91dEPNS_1SEiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*) 18092c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall S* d(S* sret, int, int, int, T, void*) { 18192c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall return sret; 18292c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall } 18392c6c90e9099b7e27073056b154b2d5e7d5449b1John McCall} 184