]> granicus.if.org Git - clang/commitdiff
Fix 'for' loop variables' scope.
authorDevang Patel <dpatel@apple.com>
Wed, 25 Aug 2010 00:28:56 +0000 (00:28 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 25 Aug 2010 00:28:56 +0000 (00:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112002 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGStmt.cpp
test/CodeGen/debug-info-scope.c [new file with mode: 0644]

index 3a6c44aba01a58c4726700e8f0a577e7b9617c5f..16145f766af2c1a0bc1799faffcb406d1ddd3394 100644 (file)
@@ -501,6 +501,12 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) {
 
   RunCleanupsScope ForScope(*this);
 
+  CGDebugInfo *DI = getDebugInfo();
+  if (DI) {
+    DI->setLocation(S.getSourceRange().getBegin());
+    DI->EmitRegionStart(Builder);
+  }
+
   // Evaluate the first part before the loop.
   if (S.getInit())
     EmitStmt(S.getInit());
@@ -558,12 +564,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) {
   // Store the blocks to use for break and continue.
   BreakContinueStack.push_back(BreakContinue(LoopExit, Continue));
 
-  CGDebugInfo *DI = getDebugInfo();
-  if (DI) {
-    DI->setLocation(S.getSourceRange().getBegin());
-    DI->EmitRegionStart(Builder);
-  }
-
   {
     // Create a separate cleanup scope for the body, in case it is not
     // a compound statement.
diff --git a/test/CodeGen/debug-info-scope.c b/test/CodeGen/debug-info-scope.c
new file mode 100644 (file)
index 0000000..6051e6e
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -g -emit-llvm < %s | FileCheck %s
+// Two variables with same name in separate scope.
+// Radar 8330217.
+int main() {
+       int j = 0;
+       int k = 0;
+// CHECK: DW_TAG_auto_variable
+// CHECK-NEXT: DW_TAG_lexical_block
+       for (int i = 0; i < 10; i++)
+               j++;
+       for (int i = 0; i < 10; i++)
+               k++;
+       return 0;
+}