Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -g -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 
     11 void func() {
     12   // 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]])
     16   if (int i = src())
     17     f();
     18 
     19   // 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]])
     23   if (int i = src()) {
     24     f();
     25   } else
     26     f();
     27 
     28   // 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]])
     32   for (int i = 0;
     33   // 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]])
     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: = !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]])
     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 !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]])
     57     bool b = i % 2;
     58   }
     59 
     60   int x[] = {1, 2};
     61   // 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]])
     66   for (int i : x) {
     67     // 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]])
     71   }
     72 }
     73