2018-04-05 23:29:52 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2020-09-22 05:52:06 +08:00
|
|
|
// This creates and lifetime-extends a 'const char[5]' temporary.
|
|
|
|
// CHECK: @_ZGR19extended_string_ref_ = internal constant [5 x i8] c"hi\00\00\00",
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK: @extended_string_ref ={{.*}} constant [5 x i8]* @_ZGR19extended_string_ref_,
|
2020-09-22 05:52:06 +08:00
|
|
|
const char (&extended_string_ref)[5] = {"hi"};
|
|
|
|
|
|
|
|
// This binds directly to a string literal object.
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK: @nonextended_string_ref ={{.*}} constant [3 x i8]* @.str
|
2020-09-22 05:52:06 +08:00
|
|
|
const char (&nonextended_string_ref)[3] = {"hi"};
|
|
|
|
|
2011-11-28 00:50:07 +08:00
|
|
|
namespace reference {
|
|
|
|
struct A {
|
|
|
|
int i1, i2;
|
|
|
|
};
|
|
|
|
|
|
|
|
void single_init() {
|
|
|
|
// No superfluous instructions allowed here, they could be
|
|
|
|
// hiding extra temporaries.
|
|
|
|
|
|
|
|
// CHECK: store i32 1, i32*
|
|
|
|
// CHECK-NEXT: store i32* %{{.*}}, i32**
|
|
|
|
const int &cri2a = 1;
|
|
|
|
|
|
|
|
// CHECK-NEXT: store i32 1, i32*
|
|
|
|
// CHECK-NEXT: store i32* %{{.*}}, i32**
|
|
|
|
const int &cri1a = {1};
|
|
|
|
|
|
|
|
// CHECK-NEXT: store i32 1, i32*
|
|
|
|
int i = 1;
|
|
|
|
// CHECK-NEXT: store i32* %{{.*}}, i32**
|
|
|
|
int &ri1a = {i};
|
|
|
|
|
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
// CHECK-NEXT: memcpy
|
|
|
|
A a{1, 2};
|
|
|
|
// CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
|
|
|
|
A &ra1a = {a};
|
|
|
|
|
2012-05-15 05:57:21 +08:00
|
|
|
using T = A&;
|
|
|
|
// CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
|
|
|
|
A &ra1b = T{a};
|
|
|
|
|
2011-11-28 00:50:07 +08:00
|
|
|
// CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
2015-03-07 21:37:13 +08:00
|
|
|
void reference_to_aggregate(int i) {
|
2011-11-28 00:50:07 +08:00
|
|
|
// CHECK: getelementptr {{.*}}, i32 0, i32 0
|
|
|
|
// CHECK-NEXT: store i32 1
|
|
|
|
// CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
|
2015-03-07 21:37:13 +08:00
|
|
|
// CHECK-NEXT: %[[I1:.*]] = load i32, i32*
|
|
|
|
// CHECK-NEXT: store i32 %[[I1]]
|
2011-11-28 00:50:07 +08:00
|
|
|
// CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align
|
2015-03-07 21:37:13 +08:00
|
|
|
const A &ra1{1, i};
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: getelementptr inbounds [3 x i32], [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0
|
2011-11-28 00:50:07 +08:00
|
|
|
// CHECK-NEXT: store i32 1
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
|
2011-11-28 00:50:07 +08:00
|
|
|
// CHECK-NEXT: store i32 2
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
|
2015-03-07 21:37:13 +08:00
|
|
|
// CHECK-NEXT: %[[I2:.*]] = load i32, i32*
|
|
|
|
// CHECK-NEXT: store i32 %[[I2]]
|
2011-11-28 00:50:07 +08:00
|
|
|
// CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align
|
2015-03-07 21:37:13 +08:00
|
|
|
const int (&arrayRef)[] = {1, 2, i};
|
|
|
|
|
|
|
|
// CHECK: store %{{.*}}* @{{.*}}, %{{.*}}** %{{.*}}, align
|
|
|
|
const A &constra1{1, 2};
|
|
|
|
|
|
|
|
// CHECK-NEXT: store [3 x i32]* @{{.*}}, [3 x i32]** %{{.*}}, align
|
|
|
|
const int (&constarrayRef)[] = {1, 2, 3};
|
2011-11-28 00:50:07 +08:00
|
|
|
|
|
|
|
// CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
B();
|
|
|
|
~B();
|
|
|
|
};
|
|
|
|
|
|
|
|
void single_init_temp_cleanup()
|
|
|
|
{
|
|
|
|
// Ensure lifetime extension.
|
|
|
|
|
2021-10-15 18:45:30 +08:00
|
|
|
// CHECK: call noundef %"struct.reference::B"* @_ZN9reference1BC1Ev
|
2011-11-28 00:50:07 +08:00
|
|
|
// CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
|
|
|
|
const B &rb{ B() };
|
2021-10-15 18:45:30 +08:00
|
|
|
// CHECK: call noundef %"struct.reference::B"* @_ZN9reference1BD1Ev
|
2011-11-28 00:50:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-04-10 00:09:29 +08:00
|
|
|
|
|
|
|
namespace PR23165 {
|
|
|
|
struct AbstractClass {
|
|
|
|
virtual void foo() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChildClass : public AbstractClass {
|
|
|
|
virtual void foo() const {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void helper(const AbstractClass ¶m) {
|
|
|
|
param.foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void foo() {
|
2015-04-10 06:50:07 +08:00
|
|
|
// CHECK-LABEL: @_ZN7PR231653fooEv
|
|
|
|
// CHECK: call {{.*}} @_ZN7PR2316510ChildClassC1Ev
|
|
|
|
// CHECK: call void @_ZN7PR231656helperERKNS_13AbstractClassE
|
2015-04-10 00:09:29 +08:00
|
|
|
helper(ChildClass());
|
|
|
|
}
|
2015-04-10 06:50:07 +08:00
|
|
|
|
|
|
|
struct S { struct T { int a; } t; mutable int b; };
|
|
|
|
void f() {
|
|
|
|
// CHECK-LABEL: _ZN7PR231651fEv
|
|
|
|
// CHECK: alloca
|
|
|
|
// CHECK: alloca
|
|
|
|
// CHECK: store
|
|
|
|
const S::T &r = S().t;
|
|
|
|
}
|
2015-04-10 00:09:29 +08:00
|
|
|
}
|