blob: 9221ff7546b0999b7f3ee699517d9a54c321dd5d [file] [log] [blame]
David Blaikieac0a5c42014-08-22 21:54:29 +00001// RUN: %clang_cc1 -g -std=c++11 -emit-llvm %s -o -| FileCheck %s
Adrian Prantl0ffce6e2013-06-08 00:16:55 +00002//
3// Two variables with the same name in subsequent if staments need to be in separate scopes.
4//
5// rdar://problem/14024005
Adrian Prantl0ffce6e2013-06-08 00:16:55 +00006
David Blaikie93be0b22014-08-22 21:37:04 +00007int src();
Adrian Prantl0ffce6e2013-06-08 00:16:55 +00008
David Blaikie93be0b22014-08-22 21:37:04 +00009void f();
Adrian Prantl0ffce6e2013-06-08 00:16:55 +000010
David Blaikie93be0b22014-08-22 21:37:04 +000011void func() {
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000012 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "i"
13 // CHECK-SAME: scope: [[IF1:![0-9]*]]
14 // CHECK-SAME: line: [[@LINE+2]]
15 // CHECK: [[IF1]] = distinct !MDLexicalBlock({{.*}}line: [[@LINE+1]])
David Blaikie93be0b22014-08-22 21:37:04 +000016 if (int i = src())
17 f();
18
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000019 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "i"
20 // CHECK-SAME: scope: [[IF2:![0-9]*]]
21 // CHECK-SAME: line: [[@LINE+2]]
22 // CHECK: [[IF2]] = distinct !MDLexicalBlock({{.*}}line: [[@LINE+1]])
David Blaikie93be0b22014-08-22 21:37:04 +000023 if (int i = src()) {
24 f();
25 } else
26 f();
27
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000028 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "i"
29 // CHECK-SAME: scope: [[FOR:![0-9]*]]
30 // CHECK-SAME: line: [[@LINE+2]]
31 // CHECK: [[FOR]] = distinct !MDLexicalBlock({{.*}}line: [[@LINE+1]])
David Blaikie93be0b22014-08-22 21:37:04 +000032 for (int i = 0;
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000033 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "b"
34 // CHECK-SAME: scope: [[FOR_BODY:![0-9]*]]
35 // CHECK-SAME: line: [[@LINE+6]]
36 // CHECK: [[FOR_BODY]] = distinct !MDLexicalBlock({{.*}}line: [[@LINE-4]])
David Blaikie93be0b22014-08-22 21:37:04 +000037 // The scope could be located at 'bool b', but LLVM drops line information for
38 // scopes anyway, so it's not terribly important.
39 // FIXME: change the debug info schema to not include locations of scopes,
40 // since they're not used.
David Blaikie93be0b22014-08-22 21:37:04 +000041 bool b = i != 10; ++i)
42 f();
43
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000044 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "i"
45 // CHECK-SAME: scope: [[FOR:![0-9]*]]
46 // CHECK-SAME: line: [[@LINE+2]]
47 // CHECK: [[FOR]] = distinct !MDLexicalBlock({{.*}}line: [[@LINE+1]])
David Blaikie93be0b22014-08-22 21:37:04 +000048 for (int i = 0; i != 10; ++i) {
David Blaikie66e41972015-01-14 07:38:27 +000049 // FIXME: Do not include scopes that have only other scopes (and no variables
50 // or using declarations) as direct children, they just waste
51 // space/relocations/etc.
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000052 // CHECK: [[FOR_LOOP_INCLUDING_COND:!.*]] = distinct !MDLexicalBlock(scope: [[FOR]],{{.*}} line: [[@LINE-4]])
53 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "b"
54 // CHECK-SAME: scope: [[FOR_COMPOUND:![0-9]*]]
55 // CHECK-SAME: line: [[@LINE+2]]
56 // CHECK: [[FOR_COMPOUND]] = distinct !MDLexicalBlock(scope: [[FOR_LOOP_INCLUDING_COND]],{{.*}} line: [[@LINE-8]])
David Blaikie93be0b22014-08-22 21:37:04 +000057 bool b = i % 2;
Adrian Prantl0ffce6e2013-06-08 00:16:55 +000058 }
David Blaikieac0a5c42014-08-22 21:54:29 +000059
60 int x[] = {1, 2};
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000061 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "__range"
62 // CHECK-SAME: scope: [[RANGE_FOR:![0-9]*]]
63 // CHECK-NOT: line:
64 // CHECK-SAME: ){{$}}
65 // CHECK: [[RANGE_FOR]] = distinct !MDLexicalBlock({{.*}}, line: [[@LINE+1]])
David Blaikieac0a5c42014-08-22 21:54:29 +000066 for (int i : x) {
Duncan P. N. Exon Smithf04be1f2015-03-03 17:25:55 +000067 // CHECK: = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "i"
68 // CHECK-SAME: scope: [[RANGE_FOR_BODY:![0-9]*]]
69 // CHECK-SAME: line: [[@LINE-3]]
70 // CHECK: [[RANGE_FOR_BODY]] = distinct !MDLexicalBlock(scope: [[RANGE_FOR]],{{.*}} line: [[@LINE-4]])
David Blaikieac0a5c42014-08-22 21:54:29 +000071 }
Adrian Prantl0ffce6e2013-06-08 00:16:55 +000072}