1// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
2
3// Check the line numbers for cleanup code with EH in combination with
4// simple return expressions.
5
6// CHECK: define {{.*}}foo
7// CHECK: call void @_ZN1CD1Ev(%class.C* {{.*}}), !dbg ![[RET:[0-9]+]]
8// CHECK: ret i32 0, !dbg ![[RET]]
9
10// CHECK: define {{.*}}bar
11// CHECK: ret void, !dbg ![[RETBAR:[0-9]+]]
12
13// CHECK: define {{.*}}baz
14// CHECK: ret void, !dbg ![[RETBAZ:[0-9]+]]
15
16class C {
17public:
18  ~C() {}
19  int i;
20};
21
22int foo()
23{
24  C c;
25  c.i = 42;
26  return 0;
27  // This breakpoint should be at/before the cleanup code.
28  // CHECK: ![[RET]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}})
29}
30
31void bar()
32{
33  if (!foo())
34    // CHECK: {{.*}} = !DILocation(line: [[@LINE+1]], scope: !{{.*}})
35    return;
36
37  if (foo()) {
38    C c;
39    c.i = foo();
40  }
41  // Clang creates only a single ret instruction. Make sure it is at a useful line.
42  // CHECK: ![[RETBAR]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}})
43}
44
45void baz()
46{
47  if (!foo())
48    // CHECK: ![[SCOPE1:.*]] = distinct !DILexicalBlock({{.*}}, line: [[@LINE-1]])
49    // CHECK: {{.*}} = !DILocation(line: [[@LINE+1]], scope: ![[SCOPE1]])
50    return;
51
52  if (foo()) {
53    // no cleanup
54    // CHECK: {{.*}} = !DILocation(line: [[@LINE+2]], scope: ![[SCOPE2:.*]])
55    // CHECK: ![[SCOPE2]] = distinct !DILexicalBlock({{.*}}, line: [[@LINE-3]])
56    return;
57  }
58  // CHECK: ![[RETBAZ]] = !DILocation(line: [[@LINE+1]], scope: !{{.*}})
59}
60