1 // RUN: %clang_cc1 -emit-llvm -g -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 ![[CLEANUP:[0-9]+]]
8 // CHECK: ret i32 0, !dbg ![[RET:[0-9]+]]
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 
16 class C {
17 public:
~C()18   ~C() {}
19   int i;
20 };
21 
foo()22 int foo()
23 {
24   C c;
25   c.i = 42;
26   // This breakpoint should be at/before the cleanup code.
27   // CHECK: ![[CLEANUP]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
28   return 0;
29   // CHECK: ![[RET]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
30 }
31 
bar()32 void bar()
33 {
34   if (!foo())
35     // CHECK: {{.*}} = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
36     return;
37 
38   if (foo()) {
39     C c;
40     c.i = foo();
41   }
42   // Clang creates only a single ret instruction. Make sure it is at a useful line.
43   // CHECK: ![[RETBAR]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
44 }
45 
baz()46 void baz()
47 {
48   if (!foo())
49     // CHECK: ![[SCOPE1:.*]] = !{!"0xb\00[[@LINE-1]]\00{{.*}}", {{.*}} ; [ DW_TAG_lexical_block ]
50     // CHECK: {{.*}} = !MDLocation(line: [[@LINE+1]], scope: ![[SCOPE1]])
51     return;
52 
53   if (foo()) {
54     // no cleanup
55     // CHECK: {{.*}} = !MDLocation(line: [[@LINE+2]], scope: ![[SCOPE2:.*]])
56     // CHECK: ![[SCOPE2]] = !{!"0xb\00[[@LINE-3]]\00{{.*}}", {{.*}} ; [ DW_TAG_lexical_block ]
57     return;
58   }
59   // CHECK: ![[RETBAZ]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
60 }
61