brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 419525d Raw
119 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s2 3// This creates and lifetime-extends a 'const char[5]' temporary.4// CHECK: @_ZGR19extended_string_ref_ = internal constant [5 x i8] c"hi\00\00\00",5// CHECK: @extended_string_ref ={{.*}} constant ptr @_ZGR19extended_string_ref_,6const char (&extended_string_ref)[5] = {"hi"};7 8// This binds directly to a string literal object.9// CHECK: @nonextended_string_ref ={{.*}} constant ptr @.str10const char (&nonextended_string_ref)[3] = {"hi"};11 12namespace reference {13  struct A {14    int i1, i2;15  };16 17  void single_init() {18    // No superfluous instructions allowed here, they could be19    // hiding extra temporaries.20 21    // CHECK: store i32 1, ptr22    // CHECK-NEXT: store ptr %{{.*}}, ptr23    const int &cri2a = 1;24 25    // CHECK-NEXT: store i32 1, ptr26    // CHECK-NEXT: store ptr %{{.*}}, ptr27    const int &cri1a = {1};28 29    // CHECK-NEXT: store i32 1, ptr30    int i = 1;31    // CHECK-NEXT: store ptr %{{.*}}, ptr32    int &ri1a = {i};33 34    // CHECK-NEXT: memcpy35    A a{1, 2};36    // CHECK-NEXT: store ptr %{{.*}}, ptr %37    A &ra1a = {a};38 39    using T = A&;40    // CHECK-NEXT: store ptr %{{.*}}, ptr %41    A &ra1b = T{a};42 43    // CHECK-NEXT: ret44  }45 46  void reference_to_aggregate(int i) {47    // CHECK: getelementptr {{.*}}, i32 0, i32 048    // CHECK-NEXT: store i32 149    // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 150    // CHECK-NEXT: %[[I1:.*]] = load i32, ptr51    // CHECK-NEXT: store i32 %[[I1]]52    // CHECK-NEXT: store ptr %{{.*}}, ptr %{{.*}}, align53    const A &ra1{1, i};54 55    // CHECK-NEXT: store i32 156    // CHECK-NEXT: getelementptr inbounds i32, ptr %{{.*}}, i{{32|64}} 157    // CHECK-NEXT: store i32 258    // CHECK-NEXT: getelementptr inbounds i32, ptr %{{.*}}, i{{32|64}} 259    // CHECK-NEXT: %[[I2:.*]] = load i32, ptr60    // CHECK-NEXT: store i32 %[[I2]]61    // CHECK-NEXT: store ptr %{{.*}}, ptr %{{.*}}, align62    const int (&arrayRef)[] = {1, 2, i};63 64    // CHECK: store ptr @{{.*}}, ptr %{{.*}}, align65    const A &constra1{1, 2};66 67    // CHECK-NEXT: store ptr @{{.*}}, ptr %{{.*}}, align68    const int (&constarrayRef)[] = {1, 2, 3};69 70    // CHECK-NEXT: ret71  }72 73  struct B {74    B();75    ~B();76  };77 78  void single_init_temp_cleanup()79  {80    // Ensure lifetime extension.81 82    // CHECK: call noundef ptr @_ZN9reference1BC1Ev83    // CHECK-NEXT: store ptr %{{.*}}, ptr %84    const B &rb{ B() };85    // CHECK: call noundef ptr @_ZN9reference1BD1Ev86  }87 88}89 90namespace PR23165 {91struct AbstractClass {92  virtual void foo() const = 0;93};94 95struct ChildClass : public AbstractClass {96  virtual void foo() const {}97};98 99void helper(const AbstractClass &param) {100  param.foo();101}102 103void foo() {104// CHECK-LABEL: @_ZN7PR231653fooEv105// CHECK: call {{.*}} @_ZN7PR2316510ChildClassC1Ev106// CHECK: call void @_ZN7PR231656helperERKNS_13AbstractClassE107  helper(ChildClass());108}109 110struct S { struct T { int a; } t; mutable int b; };111void f() {112// CHECK-LABEL: _ZN7PR231651fEv113// CHECK: alloca114// CHECK: alloca115// CHECK: store116  const S::T &r = S().t;117}118}119