Fixing a bug where debug info for a local variable gets emitted at file scope.

The patch was discussed in Phabricator. See:
http://llvm-reviews.chandlerc.com/D1281



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189649 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGen/debug-info-line5.cpp b/test/CodeGen/debug-info-line5.cpp
new file mode 100644
index 0000000..0f10427
--- /dev/null
+++ b/test/CodeGen/debug-info-line5.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang %s -g -gcolumn-info -S -emit-llvm -o - | FileCheck %s
+// Line table entries should reference this cpp file, not the header
+
+#include "debug-info-line5.h"
+
+int result;
+int foo(unsigned);
+
+int main()
+{
+  while ( 1 )
+  {
+    result = foo(Marker);
+  }
+  return result;
+}
+
+// CHECK: !{{[0-9]*}} = metadata !{i32 {{[0-9]*}}, i32 {{[0-9]*}}, null, metadata !"Marker", {{.*}} ; [ DW_TAG_variable ] [Marker]
diff --git a/test/CodeGen/debug-info-line5.h b/test/CodeGen/debug-info-line5.h
new file mode 100644
index 0000000..690c9b7
--- /dev/null
+++ b/test/CodeGen/debug-info-line5.h
@@ -0,0 +1,2 @@
+// Declaration of "Marker"
+const unsigned Marker = 0xFF999999;
diff --git a/test/CodeGen/debug-info-scope.c b/test/CodeGen/debug-info-scope.c
index 9decaea..05cd299 100644
--- a/test/CodeGen/debug-info-scope.c
+++ b/test/CodeGen/debug-info-scope.c
@@ -1,7 +1,16 @@
 // RUN: %clang_cc1 -g -emit-llvm < %s | FileCheck %s
+
+// Make sure that the debug info of the local variable d does not shadow
+// the global variable d
+// CHECK: [ DW_TAG_variable ] [d] [line 6] [def]
+const int d = 100;
+
 // Two variables with same name in separate scope.
 // Radar 8330217.
 int main() {
+// CHECK-NOT: [ DW_TAG_variable ] [d] [line 13]
+// CHECK: [ DW_TAG_auto_variable ] [d] [line 13]
+	const int d = 4;
 	int j = 0;
 	int k = 0;
 // CHECK: DW_TAG_auto_variable ] [i]
@@ -12,5 +21,5 @@
 // CHECK-NEXT: DW_TAG_lexical_block
 	for (int i = 0; i < 10; i++)
 		k++;
-	return 0;
+	return d; // make a reference to d so that its debug info gets included
 }