• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2// Basic C++ test for update_cc_test_checks
3// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
4
5class Foo {
6  int x;
7
8public:
9  explicit Foo(int x);
10  ~Foo();
11// CHECK-LABEL: @_ZNK3Foo23function_defined_inlineEi(
12// CHECK-NEXT:  entry:
13// CHECK-NEXT:    [[THIS_ADDR:%.*]] = alloca %class.Foo*, align 8
14// CHECK-NEXT:    [[ARG_ADDR:%.*]] = alloca i32, align 4
15// CHECK-NEXT:    store %class.Foo* [[THIS:%.*]], %class.Foo** [[THIS_ADDR]], align 8
16// CHECK-NEXT:    store i32 [[ARG:%.*]], i32* [[ARG_ADDR]], align 4
17// CHECK-NEXT:    [[THIS1:%.*]] = load %class.Foo*, %class.Foo** [[THIS_ADDR]], align 8
18// CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[ARG_ADDR]], align 4
19// CHECK-NEXT:    [[X:%.*]] = getelementptr inbounds [[CLASS_FOO:%.*]], %class.Foo* [[THIS1]], i32 0, i32 0
20// CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[X]], align 4
21// CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP0]], [[TMP1]]
22// CHECK-NEXT:    ret i32 [[ADD]]
23//
24  inline int function_defined_inline(int arg) const {
25    return arg + x;
26  }
27  inline int function_defined_out_of_line(int arg) const;
28};
29
30// CHECK-LABEL: @_ZN3FooC1Ei(
31// CHECK-NEXT:  entry:
32// CHECK-NEXT:    [[THIS_ADDR:%.*]] = alloca %class.Foo*, align 8
33// CHECK-NEXT:    [[X_ADDR:%.*]] = alloca i32, align 4
34// CHECK-NEXT:    store %class.Foo* [[THIS:%.*]], %class.Foo** [[THIS_ADDR]], align 8
35// CHECK-NEXT:    store i32 [[X:%.*]], i32* [[X_ADDR]], align 4
36// CHECK-NEXT:    [[THIS1:%.*]] = load %class.Foo*, %class.Foo** [[THIS_ADDR]], align 8
37// CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[X_ADDR]], align 4
38// CHECK-NEXT:    call void @_ZN3FooC2Ei(%class.Foo* nonnull dereferenceable(4) [[THIS1]], i32 [[TMP0]])
39// CHECK-NEXT:    ret void
40//
41Foo::Foo(int x) : x(x) {}
42// CHECK-LABEL: @_ZN3FooD1Ev(
43// CHECK-NEXT:  entry:
44// CHECK-NEXT:    [[THIS_ADDR:%.*]] = alloca %class.Foo*, align 8
45// CHECK-NEXT:    store %class.Foo* [[THIS:%.*]], %class.Foo** [[THIS_ADDR]], align 8
46// CHECK-NEXT:    [[THIS1:%.*]] = load %class.Foo*, %class.Foo** [[THIS_ADDR]], align 8
47// CHECK-NEXT:    call void @_ZN3FooD2Ev(%class.Foo* nonnull dereferenceable(4) [[THIS1]]) [[ATTR3:#.*]]
48// CHECK-NEXT:    ret void
49//
50Foo::~Foo() {}
51// CHECK-LABEL: @_ZNK3Foo28function_defined_out_of_lineEi(
52// CHECK-NEXT:  entry:
53// CHECK-NEXT:    [[THIS_ADDR:%.*]] = alloca %class.Foo*, align 8
54// CHECK-NEXT:    [[ARG_ADDR:%.*]] = alloca i32, align 4
55// CHECK-NEXT:    store %class.Foo* [[THIS:%.*]], %class.Foo** [[THIS_ADDR]], align 8
56// CHECK-NEXT:    store i32 [[ARG:%.*]], i32* [[ARG_ADDR]], align 4
57// CHECK-NEXT:    [[THIS1:%.*]] = load %class.Foo*, %class.Foo** [[THIS_ADDR]], align 8
58// CHECK-NEXT:    [[X:%.*]] = getelementptr inbounds [[CLASS_FOO:%.*]], %class.Foo* [[THIS1]], i32 0, i32 0
59// CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[X]], align 4
60// CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[ARG_ADDR]], align 4
61// CHECK-NEXT:    [[SUB:%.*]] = sub nsw i32 [[TMP0]], [[TMP1]]
62// CHECK-NEXT:    ret i32 [[SUB]]
63//
64int Foo::function_defined_out_of_line(int arg) const { return x - arg; }
65
66// Call the inline methods to ensure the LLVM IR is generated:
67// CHECK-LABEL: @main(
68// CHECK-NEXT:  entry:
69// CHECK-NEXT:    [[F:%.*]] = alloca [[CLASS_FOO:%.*]], align 4
70// CHECK-NEXT:    call void @_ZN3FooC1Ei(%class.Foo* nonnull dereferenceable(4) [[F]], i32 1)
71// CHECK-NEXT:    [[CALL:%.*]] = call i32 @_ZNK3Foo23function_defined_inlineEi(%class.Foo* nonnull dereferenceable(4) [[F]], i32 2)
72// CHECK-NEXT:    [[CALL1:%.*]] = call i32 @_ZNK3Foo28function_defined_out_of_lineEi(%class.Foo* nonnull dereferenceable(4) [[F]], i32 3)
73// CHECK-NEXT:    call void @_ZN3FooD1Ev(%class.Foo* nonnull dereferenceable(4) [[F]]) [[ATTR3]]
74// CHECK-NEXT:    ret i32 0
75//
76int main() {
77  Foo f(1);
78  f.function_defined_inline(2);
79  f.function_defined_out_of_line(3);
80}
81