reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s

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};

    using T = A&;
    // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
    A &ra1b = T{a};

    // CHECK-NEXT: ret
  }

  void reference_to_aggregate(int i) {
    // CHECK: getelementptr {{.*}}, i32 0, i32 0
    // CHECK-NEXT: store i32 1
    // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
    // CHECK-NEXT: %[[I1:.*]] = load i32, i32*
    // CHECK-NEXT: store i32 %[[I1]]
    // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align
    const A &ra1{1, i};

    // CHECK-NEXT: getelementptr inbounds [3 x i32], [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0
    // CHECK-NEXT: store i32 1
    // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
    // CHECK-NEXT: store i32 2
    // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
    // CHECK-NEXT: %[[I2:.*]] = load i32, i32*
    // CHECK-NEXT: store i32 %[[I2]]
    // CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align
    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};

    // CHECK-NEXT: ret
  }

  struct B {
    B();
    ~B();
  };

  void single_init_temp_cleanup()
  {
    // Ensure lifetime extension.

    // CHECK: call %"struct.reference::B"* @_ZN9reference1BC1Ev
    // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
    const B &rb{ B() };
    // CHECK: call %"struct.reference::B"* @_ZN9reference1BD1Ev
  }

}

namespace PR23165 {
struct AbstractClass {
  virtual void foo() const = 0;
};

struct ChildClass : public AbstractClass {
  virtual void foo() const {}
};

void helper(const AbstractClass &param) {
  param.foo();
}

void foo() {
// CHECK-LABEL: @_ZN7PR231653fooEv
// CHECK: call {{.*}} @_ZN7PR2316510ChildClassC1Ev
// CHECK: call void @_ZN7PR231656helperERKNS_13AbstractClassE
  helper(ChildClass());
}

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;
}
}