summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-08-22 21:37:04 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-08-22 21:37:04 +0000
commit93be0b24b85dd57cc1ec5e46aa657668f90829e4 (patch)
tree221ee40cfef2b7e071b6bd0e39411e482e44c207
parentcfe910b9d45a1e1a6af7fa85706fe464497f2b73 (diff)
downloadbcm5719-llvm-93be0b24b85dd57cc1ec5e46aa657668f90829e4.tar.gz
bcm5719-llvm-93be0b24b85dd57cc1ec5e46aa657668f90829e4.zip
DebugInfo: Scope for condition variables more narrowly than the loop variable.
for loops introduce two scopes - one for the outer loop variable and its initialization, and another for the body of the loop, including any variable declared inside the loop condition. llvm-svn: 216288
-rw-r--r--clang/lib/CodeGen/CGStmt.cpp11
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h2
-rw-r--r--clang/test/CodeGenCXX/debug-info-scope.cpp59
3 files changed, 40 insertions, 32 deletions
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 1395d60ab07..de3b795fc2b 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -810,11 +810,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
const ArrayRef<const Attr *> &ForAttrs) {
JumpDest LoopExit = getJumpDestInCurrentScope("for.end");
- RunCleanupsScope ForScope(*this);
-
- CGDebugInfo *DI = getDebugInfo();
- if (DI)
- DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
+ LexicalScope ForScope(*this, S.getSourceRange());
// Evaluate the first part before the loop.
if (S.getInit())
@@ -842,7 +838,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
BreakContinueStack.push_back(BreakContinue(LoopExit, Continue));
// Create a cleanup scope for the condition variable cleanups.
- RunCleanupsScope ConditionScope(*this);
+ LexicalScope ConditionScope(*this, S.getSourceRange());
if (S.getCond()) {
// If the for statement has a condition scope, emit the local variable
@@ -902,9 +898,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
ForScope.ForceCleanup();
- if (DI)
- DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd());
-
LoopStack.pop();
// Emit the fall-through block.
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 04294ec8e57..6d21e78bf23 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -535,7 +535,7 @@ public:
}
};
- class LexicalScope: protected RunCleanupsScope {
+ class LexicalScope : public RunCleanupsScope {
SourceRange Range;
SmallVector<const LabelDecl*, 4> Labels;
LexicalScope *ParentScope;
diff --git a/clang/test/CodeGenCXX/debug-info-scope.cpp b/clang/test/CodeGenCXX/debug-info-scope.cpp
index 0447dc04d56..58195e37782 100644
--- a/clang/test/CodeGenCXX/debug-info-scope.cpp
+++ b/clang/test/CodeGenCXX/debug-info-scope.cpp
@@ -3,30 +3,45 @@
// Two variables with the same name in subsequent if staments need to be in separate scopes.
//
// rdar://problem/14024005
-//
-int printf(const char*, ...);
+int src();
-char *return_char (int input)
-{
- if (input%2 == 0)
- return "I am even.\n";
- else
- return "I am odd.\n";
-}
+void f();
-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);
+void func() {
+ // CHECK: = metadata !{i32 786688, metadata [[IF1:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]]
+ // CHECK: [[IF1]] = metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ]
+ if (int i = src())
+ f();
- return 0;
+ // CHECK: = metadata !{i32 786688, metadata [[IF2:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]]
+ // CHECK: [[IF2]] = metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ]
+ if (int i = src()) {
+ f();
+ } else
+ f();
+
+ // CHECK: = metadata !{i32 786688, metadata [[FOR:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]]
+ // CHECK: [[FOR]] = metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ]
+ for (int i = 0;
+ // CHECK: = metadata !{i32 786688, metadata [[FOR_BODY:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+6]]]
+ // The scope could be located at 'bool b', but LLVM drops line information for
+ // scopes anyway, so it's not terribly important.
+ // FIXME: change the debug info schema to not include locations of scopes,
+ // since they're not used.
+ // CHECK: [[FOR_BODY]] = metadata !{i32 {{.*}}, metadata [[FOR]], i32 [[@LINE-6]], {{.*}}} ; [ DW_TAG_lexical_block ]
+ bool b = i != 10; ++i)
+ f();
+
+ // CHECK: = metadata !{i32 786688, metadata [[FOR:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]]
+ // CHECK: [[FOR]] = metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ]
+ for (int i = 0; i != 10; ++i) {
+ // FIXME: Do not include scopes that have only other scopes (and no variables
+ // or using declarations) as direct children, they just waste
+ // space/relocations/etc.
+ // CHECK: [[FOR_BODY:![0-9]*]] = metadata !{i32 {{.*}}, metadata [[FOR]], i32 [[@LINE-4]], {{.*}}} ; [ DW_TAG_lexical_block ]
+ // CHECK: = metadata !{i32 786688, metadata [[FOR_COMPOUND:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+2]]]
+ // CHECK: [[FOR_COMPOUND]] = metadata !{i32 {{.*}}, metadata [[FOR_BODY]], i32 [[@LINE-6]], {{.*}}} ; [ DW_TAG_lexical_block ]
+ bool b = i % 2;
+ }
}
OpenPOWER on IntegriCloud