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
11 // CHECK-LABEL: @_ZNK3Foo23function_defined_inlineEi(
13 // CHECK-NEXT: [[THIS_ADDR:%.*]] = alloca ptr, align 8
14 // CHECK-NEXT: [[ARG_ADDR:%.*]] = alloca i32, align 4
15 // CHECK-NEXT: store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
16 // CHECK-NEXT: store i32 [[ARG:%.*]], ptr [[ARG_ADDR]], align 4
17 // CHECK-NEXT: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
18 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARG_ADDR]], align 4
19 // CHECK-NEXT: [[X:%.*]] = getelementptr inbounds [[CLASS_FOO:%.*]], ptr [[THIS1]], i32 0, i32 0
20 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[X]], align 4
21 // CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], [[TMP1]]
22 // CHECK-NEXT: ret i32 [[ADD]]
24 inline int function_defined_inline(int arg) const {
27 inline int function_defined_out_of_line(int arg) const;
30 // CHECK-LABEL: @_ZN3FooC1Ei(
32 // CHECK-NEXT: [[THIS_ADDR:%.*]] = alloca ptr, align 8
33 // CHECK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
34 // CHECK-NEXT: store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
35 // CHECK-NEXT: store i32 [[X:%.*]], ptr [[X_ADDR]], align 4
36 // CHECK-NEXT: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
37 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
38 // CHECK-NEXT: call void @_ZN3FooC2Ei(ptr noundef nonnull align 4 dereferenceable(4) [[THIS1]], i32 noundef [[TMP0]])
39 // CHECK-NEXT: ret void
41 Foo::Foo(int x) : x(x) {}
42 // CHECK-LABEL: @_ZN3FooD1Ev(
44 // CHECK-NEXT: [[THIS_ADDR:%.*]] = alloca ptr, align 8
45 // CHECK-NEXT: store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
46 // CHECK-NEXT: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
47 // CHECK-NEXT: call void @_ZN3FooD2Ev(ptr noundef nonnull align 4 dereferenceable(4) [[THIS1]]) #[[ATTR3:[0-9]+]]
48 // CHECK-NEXT: ret void
51 // CHECK-LABEL: @_ZNK3Foo28function_defined_out_of_lineEi(
53 // CHECK-NEXT: [[THIS_ADDR:%.*]] = alloca ptr, align 8
54 // CHECK-NEXT: [[ARG_ADDR:%.*]] = alloca i32, align 4
55 // CHECK-NEXT: store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
56 // CHECK-NEXT: store i32 [[ARG:%.*]], ptr [[ARG_ADDR]], align 4
57 // CHECK-NEXT: [[THIS1:%.*]] = load ptr, ptr [[THIS_ADDR]], align 8
58 // CHECK-NEXT: [[X:%.*]] = getelementptr inbounds [[CLASS_FOO:%.*]], ptr [[THIS1]], i32 0, i32 0
59 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X]], align 4
60 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARG_ADDR]], align 4
61 // CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[TMP0]], [[TMP1]]
62 // CHECK-NEXT: ret i32 [[SUB]]
64 int Foo::function_defined_out_of_line(int arg) const { return x - arg; }
66 // Call the inline methods to ensure the LLVM IR is generated:
67 // CHECK-LABEL: @main(
69 // CHECK-NEXT: [[F:%.*]] = alloca [[CLASS_FOO:%.*]], align 4
70 // CHECK-NEXT: call void @_ZN3FooC1Ei(ptr noundef nonnull align 4 dereferenceable(4) [[F]], i32 noundef 1)
71 // CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK3Foo23function_defined_inlineEi(ptr noundef nonnull align 4 dereferenceable(4) [[F]], i32 noundef 2)
72 // CHECK-NEXT: [[CALL1:%.*]] = call noundef i32 @_ZNK3Foo28function_defined_out_of_lineEi(ptr noundef nonnull align 4 dereferenceable(4) [[F]], i32 noundef 3)
73 // CHECK-NEXT: call void @_ZN3FooD1Ev(ptr noundef nonnull align 4 dereferenceable(4) [[F]]) #[[ATTR3]]
74 // CHECK-NEXT: ret i32 0
78 f.function_defined_inline(2);
79 f.function_defined_out_of_line(3);