From 8d378585f66c0562a818f60d3b003a6f55054dbe Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Sat, 8 Jun 2013 00:16:55 +0000 Subject: [PATCH] Debug info: An if condition now creates a lexical scope of its own. Two variables with the same name declared in two if conditions in the same scope are no longer coalesced into one. rdar://problem/14024005 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183597 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGStmt.cpp | 10 ++++++++ test/CodeGenCXX/debug-info-namespace.cpp | 5 ++-- test/CodeGenCXX/debug-info-scope.cpp | 32 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/CodeGenCXX/debug-info-scope.cpp diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 3e9b8d47ea..0db31ac49c 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -419,6 +419,11 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { // unequal to 0. The condition must be a scalar type. RunCleanupsScope ConditionScope(*this); + // Also open a debugger-visible lexical scope for the condition. + CGDebugInfo *DI = getDebugInfo(); + if (DI) + DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin()); + if (S.getConditionVariable()) EmitAutoVarDecl(*S.getConditionVariable()); @@ -439,6 +444,8 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { RunCleanupsScope ExecutedScope(*this); EmitStmt(Executed); } + if (DI) + DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd()); return; } } @@ -476,6 +483,9 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { EmitBranch(ContBlock); } + if (DI) + DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd()); + // Emit the continuation block for code after the if. EmitBlock(ContBlock, true); } diff --git a/test/CodeGenCXX/debug-info-namespace.cpp b/test/CodeGenCXX/debug-info-namespace.cpp index aa739ab933..623005b068 100644 --- a/test/CodeGenCXX/debug-info-namespace.cpp +++ b/test/CodeGenCXX/debug-info-namespace.cpp @@ -50,8 +50,9 @@ int func(bool b) { // CHECK: [[M1]] = metadata !{i32 {{[0-9]*}}, metadata [[CTXT]], metadata [[NS]], i32 9} ; [ DW_TAG_imported_module ] // CHECK: [[M2]] = metadata !{i32 {{[0-9]*}}, metadata [[CU]], metadata [[CTXT]], i32 12} ; [ DW_TAG_imported_module ] // CHECK: [[M3]] = metadata !{i32 {{[0-9]*}}, metadata [[CU]], metadata [[CTXT]], i32 13, metadata !"E"} ; [ DW_TAG_imported_module ] -// CHECK: [[M4]] = metadata !{i32 {{[0-9]*}}, metadata [[LEX:![0-9]*]], metadata [[NS]], i32 17} ; [ DW_TAG_imported_module ] -// CHECK: [[LEX]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[FUNC]], i32 16, i32 0, i32 0} ; [ DW_TAG_lexical_block ] +// CHECK: [[M4]] = metadata !{i32 {{[0-9]*}}, metadata [[LEX2:![0-9]*]], metadata [[NS]], i32 17} ; [ DW_TAG_imported_module ] +// CHECK: [[LEX2]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[LEX1:![0-9]+]], i32 16, i32 0, i32 {{.*}}} ; [ DW_TAG_lexical_block ] +// CHECK: [[LEX1]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[FUNC]], i32 16, i32 0, i32 {{.*}}} ; [ DW_TAG_lexical_block ] // CHECK: [[M5]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[CTXT]], i32 20} ; [ DW_TAG_imported_module ] // CHECK: [[M6]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[FOO:![0-9]*]], i32 21} ; [ DW_TAG_imported_declaration ] // CHECK: [[FOO]] {{.*}} ; [ DW_TAG_structure_type ] [foo] [line 5, size 0, align 0, offset 0] [fwd] [from ] diff --git a/test/CodeGenCXX/debug-info-scope.cpp b/test/CodeGenCXX/debug-info-scope.cpp new file mode 100644 index 0000000000..557ee31783 --- /dev/null +++ b/test/CodeGenCXX/debug-info-scope.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -g -emit-llvm %s -o -| FileCheck %s +// +// Two variables with the same name in subsequent if staments need to be in separate scopes. +// +// rdar://problem/14024005 +// + +int printf(const char*, ...); + +char *return_char (int input) +{ + if (input%2 == 0) + return "I am even.\n"; + else + return "I am odd.\n"; +} + +int main2() { +// CHECK: [ DW_TAG_auto_variable ] [ptr] [line [[@LINE+2]]] +// CHECK metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ] + if (char *ptr = return_char(1)) { + printf ("%s", ptr); + } +// CHECK: [ DW_TAG_auto_variable ] [ptr] [line [[@LINE+2]]] +// CHECK metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ] + if (char *ptr = return_char(2)) { + printf ("%s", ptr); + } + else printf ("%s", ptr); + + return 0; +} -- 2.40.0