David Blaikie | ac0a5c4 | 2014-08-22 21:54:29 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -g -std=c++11 -emit-llvm %s -o -| FileCheck %s |
Adrian Prantl | 0ffce6e | 2013-06-08 00:16:55 +0000 | [diff] [blame] | 2 | // |
| 3 | // Two variables with the same name in subsequent if staments need to be in separate scopes. |
| 4 | // |
| 5 | // rdar://problem/14024005 |
Adrian Prantl | 0ffce6e | 2013-06-08 00:16:55 +0000 | [diff] [blame] | 6 | |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 7 | int src(); |
Adrian Prantl | 0ffce6e | 2013-06-08 00:16:55 +0000 | [diff] [blame] | 8 | |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 9 | void f(); |
Adrian Prantl | 0ffce6e | 2013-06-08 00:16:55 +0000 | [diff] [blame] | 10 | |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 11 | void func() { |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 12 | // CHECK: = !{!"0x100\00{{.*}}", [[IF1:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]] |
| 13 | // CHECK: [[IF1]] = !{!"0xb\00[[@LINE+1]]\00{{.*}}", !{{.*}}} ; [ DW_TAG_lexical_block ] |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 14 | if (int i = src()) |
| 15 | f(); |
| 16 | |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 17 | // CHECK: = !{!"0x100\00{{.*}}", [[IF2:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]] |
| 18 | // CHECK: [[IF2]] = !{!"0xb\00[[@LINE+1]]\00{{.*}}", !{{.*}}} ; [ DW_TAG_lexical_block ] |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 19 | if (int i = src()) { |
| 20 | f(); |
| 21 | } else |
| 22 | f(); |
| 23 | |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 24 | // CHECK: = !{!"0x100\00{{.*}}", [[FOR:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]] |
| 25 | // CHECK: [[FOR]] = !{!"0xb\00[[@LINE+1]]\00{{.*}}", !{{.*}}} ; [ DW_TAG_lexical_block ] |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 26 | for (int i = 0; |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 27 | // CHECK: = !{!"0x100\00{{.*}}", [[FOR_BODY:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+6]]] |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 28 | // The scope could be located at 'bool b', but LLVM drops line information for |
| 29 | // scopes anyway, so it's not terribly important. |
| 30 | // FIXME: change the debug info schema to not include locations of scopes, |
| 31 | // since they're not used. |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 32 | // CHECK: [[FOR_BODY]] = !{!"0xb\00[[@LINE-6]]\00{{.*}}", !{{.*}}} ; [ DW_TAG_lexical_block ] |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 33 | bool b = i != 10; ++i) |
| 34 | f(); |
| 35 | |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 36 | // CHECK: = !{!"0x100\00{{.*}}", [[FOR:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]] |
| 37 | // CHECK: [[FOR]] = !{!"0xb\00[[@LINE+1]]\00{{.*}}", !{{.*}}} ; [ DW_TAG_lexical_block ] |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 38 | for (int i = 0; i != 10; ++i) { |
David Blaikie | 66e4197 | 2015-01-14 07:38:27 +0000 | [diff] [blame] | 39 | // FIXME: Do not include scopes that have only other scopes (and no variables |
| 40 | // or using declarations) as direct children, they just waste |
| 41 | // space/relocations/etc. |
| 42 | // CHECK: [[FOR_LOOP_INCLUDING_COND:!.*]] = !{!"0xb\00[[@LINE-4]]\00{{.*}}", !{{[0-9]+}}, [[FOR]]} ; [ DW_TAG_lexical_block ] |
| 43 | // CHECK: = !{!"0x100\00{{.*}}", [[FOR_COMPOUND:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+2]]] |
| 44 | // CHECK: [[FOR_COMPOUND]] = !{!"0xb\00[[@LINE-6]]\00{{.*}}", !{{[0-9]+}}, [[FOR_LOOP_INCLUDING_COND]]} ; [ DW_TAG_lexical_block ] |
David Blaikie | 93be0b2 | 2014-08-22 21:37:04 +0000 | [diff] [blame] | 45 | bool b = i % 2; |
Adrian Prantl | 0ffce6e | 2013-06-08 00:16:55 +0000 | [diff] [blame] | 46 | } |
David Blaikie | ac0a5c4 | 2014-08-22 21:54:29 +0000 | [diff] [blame] | 47 | |
| 48 | int x[] = {1, 2}; |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 49 | // CHECK: = !{!"0x100\00{{.*}}", [[RANGE_FOR:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [__range] [line 0] |
| 50 | // CHECK: [[RANGE_FOR]] = !{!"0xb\00[[@LINE+1]]\00{{.*}}", !{{.*}}} ; [ DW_TAG_lexical_block ] |
David Blaikie | ac0a5c4 | 2014-08-22 21:54:29 +0000 | [diff] [blame] | 51 | for (int i : x) { |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 52 | // CHECK: = !{!"0x100\00{{.*}}", [[RANGE_FOR_BODY:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE-1]]] |
| 53 | // CHECK: [[RANGE_FOR_BODY]] = !{!"0xb\00[[@LINE-2]]\00{{.*}}", !{{[0-9]+}}, [[RANGE_FOR]]} ; [ DW_TAG_lexical_block ] |
David Blaikie | ac0a5c4 | 2014-08-22 21:54:29 +0000 | [diff] [blame] | 54 | } |
Adrian Prantl | 0ffce6e | 2013-06-08 00:16:55 +0000 | [diff] [blame] | 55 | } |