blob: 67ceecb04ae6975896400f5d786d78114dfe2837 [file] [log] [blame]
Adrian Prantld072e592013-05-03 20:11:48 +00001// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
2
Adrian Prantl6fd131c2013-07-24 20:44:20 +00003// Check the line numbers for cleanup code with EH in combination with
Adrian Prantld072e592013-05-03 20:11:48 +00004// simple return expressions.
5
6// CHECK: define {{.*}}foo
Stephen Hines0e2c34f2015-03-23 12:09:02 -07007// CHECK: call void @_ZN1CD1Ev(%class.C* {{.*}}), !dbg ![[RET:[0-9]+]]
8// CHECK: ret i32 0, !dbg ![[RET]]
Adrian Prantld072e592013-05-03 20:11:48 +00009
Adrian Prantl3b477592013-07-25 00:23:42 +000010// 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
Adrian Prantld072e592013-05-03 20:11:48 +000016class C {
17public:
18 ~C() {}
19 int i;
20};
21
22int foo()
23{
24 C c;
25 c.i = 42;
Adrian Prantld072e592013-05-03 20:11:48 +000026 return 0;
Stephen Hines0e2c34f2015-03-23 12:09:02 -070027 // This breakpoint should be at/before the cleanup code.
28 // CHECK: ![[RET]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
Adrian Prantld072e592013-05-03 20:11:48 +000029}
Adrian Prantl3b477592013-07-25 00:23:42 +000030
31void bar()
32{
33 if (!foo())
Stephen Hines0e2c34f2015-03-23 12:09:02 -070034 // CHECK: {{.*}} = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
Adrian Prantl3b477592013-07-25 00:23:42 +000035 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.
Stephen Hines0e2c34f2015-03-23 12:09:02 -070042 // CHECK: ![[RETBAR]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
Adrian Prantl3b477592013-07-25 00:23:42 +000043}
44
45void baz()
46{
47 if (!foo())
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070048 // CHECK: ![[SCOPE1:.*]] = distinct !MDLexicalBlock({{.*}}, line: [[@LINE-1]])
Stephen Hines0e2c34f2015-03-23 12:09:02 -070049 // CHECK: {{.*}} = !MDLocation(line: [[@LINE+1]], scope: ![[SCOPE1]])
Adrian Prantl3b477592013-07-25 00:23:42 +000050 return;
51
52 if (foo()) {
53 // no cleanup
Stephen Hines0e2c34f2015-03-23 12:09:02 -070054 // CHECK: {{.*}} = !MDLocation(line: [[@LINE+2]], scope: ![[SCOPE2:.*]])
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070055 // CHECK: ![[SCOPE2]] = distinct !MDLexicalBlock({{.*}}, line: [[@LINE-3]])
Adrian Prantl3b477592013-07-25 00:23:42 +000056 return;
57 }
Stephen Hines0e2c34f2015-03-23 12:09:02 -070058 // CHECK: ![[RETBAZ]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
Adrian Prantl3b477592013-07-25 00:23:42 +000059}