1 // RUN: %clang_cc1 -debug-info-kind=limited -gno-column-info -std=c++11 -emit-llvm %s -o -| FileCheck %s
2 //
3 // Two variables with the same name in subsequent if staments need to be in separate scopes.
4 //
5 // rdar://problem/14024005
6 
7 int src();
8 
9 void f();
10 
func()11 void func() {
12   // CHECK: = !DILocalVariable(name: "i"
13   // CHECK-SAME:               scope: [[IF1:![0-9]*]]
14   // CHECK-SAME:               line: [[@LINE+2]]
15   // CHECK: [[IF1]] = distinct !DILexicalBlock({{.*}}line: [[@LINE+1]])
16   if (int i = src())
17     f();
18 
19   // CHECK: = !DILocalVariable(name: "i"
20   // CHECK-SAME:               scope: [[IF2:![0-9]*]]
21   // CHECK-SAME:               line: [[@LINE+2]]
22   // CHECK: [[IF2]] = distinct !DILexicalBlock({{.*}}line: [[@LINE+1]])
23   if (int i = src()) {
24     f();
25   } else
26     f();
27 
28   // CHECK: = !DILocalVariable(name: "i"
29   // CHECK-SAME:               scope: [[FOR:![0-9]*]]
30   // CHECK-SAME:               line: [[@LINE+2]]
31   // CHECK: [[FOR]] = distinct !DILexicalBlock({{.*}}line: [[@LINE+1]])
32   for (int i = 0;
33   // CHECK: = !DILocalVariable(name: "b"
34   // CHECK-SAME:               scope: [[FOR_BODY:![0-9]*]]
35   // CHECK-SAME:               line: [[@LINE+6]]
36   // CHECK: [[FOR_BODY]] = distinct !DILexicalBlock({{.*}}line: [[@LINE-4]])
37   // 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.
41        bool b = i != 10; ++i)
42     f();
43 
44   // CHECK: = !DILocalVariable(name: "i"
45   // CHECK-SAME:               scope: [[FOR:![0-9]*]]
46   // CHECK-SAME:               line: [[@LINE+2]]
47   // CHECK: [[FOR]] = distinct !DILexicalBlock({{.*}}line: [[@LINE+1]])
48   for (int i = 0; i != 10; ++i) {
49     // 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.
52     // CHECK: [[FOR_LOOP_INCLUDING_COND:!.*]] = distinct !DILexicalBlock(scope: [[FOR]],{{.*}} line: [[@LINE-4]])
53     // CHECK: = !DILocalVariable(name: "b"
54     // CHECK-SAME:               scope: [[FOR_COMPOUND:![0-9]*]]
55     // CHECK-SAME:               line: [[@LINE+2]]
56     // CHECK: [[FOR_COMPOUND]] = distinct !DILexicalBlock(scope: [[FOR_LOOP_INCLUDING_COND]],{{.*}} line: [[@LINE-8]])
57     bool b = i % 2;
58   }
59 
60   int x[] = {1, 2};
61   // CHECK: = !DILocalVariable(name: "__range1"
62   // CHECK-SAME:               scope: [[RANGE_FOR:![0-9]*]]
63   // CHECK-NOT:                line:
64   // CHECK-SAME:               ){{$}}
65   // CHECK: [[RANGE_FOR]] = distinct !DILexicalBlock({{.*}}, line: [[@LINE+1]])
66   for (int i : x) {
67     // CHECK: = !DILocalVariable(name: "i"
68     // CHECK-SAME:               scope: [[RANGE_FOR_BODY:![0-9]*]]
69     // CHECK-SAME:               line: [[@LINE-3]]
70     // CHECK: [[RANGE_FOR_BODY]] = distinct !DILexicalBlock(scope: [[RANGE_FOR]],{{.*}} line: [[@LINE-4]])
71   }
72 }
73