pcc created this revision.
pcc added reviewers: dexonsmith, dblaikie, aprantl.
pcc added a subscriber: cfe-commits.

http://reviews.llvm.org/D20415

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/2009-10-20-GlobalDebug.c
  test/CodeGen/debug-info-packed-struct.c
  test/CodeGen/debug-info-static.c
  test/CodeGenCXX/debug-info-access.cpp
  test/CodeGenCXX/debug-info-alias.cpp
  test/CodeGenCXX/debug-info-anon-namespace.cpp
  test/CodeGenCXX/debug-info-anon-union-vars.cpp
  test/CodeGenCXX/debug-info-method.cpp
  test/CodeGenCXX/debug-info-namespace.cpp
  test/CodeGenCXX/debug-info-static-member.cpp
  test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
  test/CodeGenCXX/debug-info-template-member.cpp
  test/CodeGenCXX/debug-info-template.cpp
  test/CodeGenCXX/debug-info-uuid.cpp
  test/CodeGenCXX/debug-info.cpp
  test/CodeGenCXX/debug-lambda-expressions.cpp
  test/CodeGenCXX/inline-dllexport-member.cpp
  test/Driver/darwin-debug-flags.c
  test/Modules/ExtDebugInfo.cpp
  test/Modules/ExtDebugInfo.m

Index: test/Modules/ExtDebugInfo.m
===================================================================
--- test/Modules/ExtDebugInfo.m
+++ test/Modules/ExtDebugInfo.m
@@ -34,14 +34,8 @@
   return [c property];
 }
 
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClassWithPrivateIVars",
-// CHECK-SAME:             flags: DIFlagObjcClassComplete
-
 // CHECK: ![[MOD:.*]] = !DIModule(scope: null, name: "DebugObjC
 
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "hidden_ivar",
-// CHECK-SAME:           flags: DIFlagPrivate)
-
 // CHECK: !DIGlobalVariable(name: "GlobalUnion",
 // CHECK-SAME:              type: ![[GLOBAL_UNION:[0-9]+]]
 // CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
@@ -52,10 +46,11 @@
 // CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME:                elements: !{{[0-9]+}})
 
-// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion",
-// CHECK-SAME:           baseType: ![[TD_UNION:.*]])
-// CHECK: ![[TD_UNION]] = !DICompositeType(tag: DW_TAG_union_type,
-// CHECK-SAME:             flags: DIFlagFwdDecl)
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClassWithPrivateIVars",
+// CHECK-SAME:             flags: DIFlagObjcClassComplete
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "hidden_ivar",
+// CHECK-SAME:           flags: DIFlagPrivate)
 
 // CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefEnum",
 // CHECK-SAME:           baseType: ![[TD_ENUM:.*]])
@@ -67,6 +62,11 @@
 // CHECK: ![[TD_STRUCT]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME:             flags: DIFlagFwdDecl)
 
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion",
+// CHECK-SAME:           baseType: ![[TD_UNION:.*]])
+// CHECK: ![[TD_UNION]] = !DICompositeType(tag: DW_TAG_union_type,
+// CHECK-SAME:             flags: DIFlagFwdDecl)
+
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass",
 // CHECK-SAME:             scope: ![[MOD]],
 // CHECK-SAME:             flags: DIFlagFwdDecl)
Index: test/Modules/ExtDebugInfo.cpp
===================================================================
--- test/Modules/ExtDebugInfo.cpp
+++ test/Modules/ExtDebugInfo.cpp
@@ -67,20 +67,14 @@
   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
 }
 
-
-// CHECK: ![[STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
 // CHECK-SAME:             scope: ![[NS:[0-9]+]],
 // CHECK-SAME:             flags: DIFlagFwdDecl,
-// CHECK-SAME:             identifier: "_ZTSN8DebugCXX6StructE")
+// CHECK-SAME:             identifier:  "_ZTSN8DebugCXX4EnumE")
 
 // CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]],
 // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
 
-// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
-// CHECK-SAME:             scope: ![[NS]],
-// CHECK-SAME:             flags: DIFlagFwdDecl,
-// CHECK-SAME:             identifier:  "_ZTSN8DebugCXX4EnumE")
-
 // This type is anchored in the module by an explicit template instantiation.
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
 // CHECK-SAME:             name: "Template<long, DebugCXX::traits<long> >",
@@ -119,7 +113,12 @@
 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX1AIJvEEE")
 
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
-// CHECK-SAME:           scope: ![[STRUCT]]
+// CHECK-SAME:           scope: ![[STRUCT:[0-9]*]]
+
+// CHECK: ![[STRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
+// CHECK-SAME:             scope: ![[NS]],
+// CHECK-SAME:             flags: DIFlagFwdDecl,
+// CHECK-SAME:             identifier: "_ZTSN8DebugCXX6StructE")
 
 // CHECK: !DICompositeType(tag: DW_TAG_union_type,
 // CHECK-SAME:             flags: DIFlagFwdDecl,
@@ -181,7 +180,7 @@
 // CHECK-SAME:              name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
 
 
-// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: ![[STRUCT]], line: 27)
+// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !{{[0-9]+}}, entity: ![[STRUCT]], line: 27)
 
 // CHECK: !DICompileUnit(
 // CHECK-SAME:           splitDebugFilename:
Index: test/Driver/darwin-debug-flags.c
===================================================================
--- test/Driver/darwin-debug-flags.c
+++ test/Driver/darwin-debug-flags.c
@@ -5,7 +5,7 @@
 // <rdar://problem/12955296>
 // RUN: %clang -### -target i386-apple-darwin9 -c -g %t.s 2>&1 | FileCheck -check-prefix=P %s
 
-// CHECK: !0 = distinct !DICompileUnit(
+// CHECK: distinct !DICompileUnit(
 // CHECK-SAME:                flags:
 // CHECK-SAME:                -I path\5C with\5C \5C\5Cspaces
 // CHECK-SAME:                -g -Os
Index: test/CodeGenCXX/inline-dllexport-member.cpp
===================================================================
--- test/CodeGenCXX/inline-dllexport-member.cpp
+++ test/CodeGenCXX/inline-dllexport-member.cpp
@@ -1,11 +1,12 @@
 // RUN: %clang_cc1 -triple i686-windows-win32 -fms-extensions -debug-info-kind=limited -emit-llvm %s -o - \
 // RUN:    | FileCheck %s
 
+// CHECK: @"\01?ui@s@@2IB" = weak_odr dllexport constant i32 0, comdat, align 4, !dbg [[UI:![0-9]+]]
+
 struct __declspec(dllexport) s {
   static const unsigned int ui = 0;
 };
 
-// CHECK: ![[SCOPE:[0-9]+]] = distinct !DICompileUnit(
-// CHECK: !DIGlobalVariable(name: "ui", linkageName: "\01?ui@s@@2IB", scope: ![[SCOPE]],
-// CHECK-SAME:              variable: i32* @"\01?ui@s@@2IB"
+// CHECK: [[UI]] = distinct !DIGlobalVariable(name: "ui", linkageName: "\01?ui@s@@2IB", scope: ![[SCOPE:[0-9]+]],
+// CHECK: ![[SCOPE]] = distinct !DICompileUnit(
 
Index: test/CodeGenCXX/debug-lambda-expressions.cpp
===================================================================
--- test/CodeGenCXX/debug-lambda-expressions.cpp
+++ test/CodeGenCXX/debug-lambda-expressions.cpp
@@ -15,6 +15,12 @@
 int d(int x) { D y[10]; return [x,y] { return y[x].x; }(); }
 
 // Randomness for file. -- 6
+
+// VAR:
+// CHECK: !DIGlobalVariable(name: "var"
+// CHECK-SAME:              line: [[VAR_LINE:[0-9]+]]
+// CHECK-SAME:              type: ![[VAR_T:[0-9]+]]
+
 // CHECK: [[FILE:.*]] = !DIFile(filename: "{{.*}}debug-lambda-expressions.cpp",
 
 // CVAR:
@@ -26,10 +32,6 @@
 // CHECK-SAME:                           elements: ![[CVAR_ARGS:[0-9]+]]
 // CHECK: ![[CVAR_ARGS]] = !{!{{[0-9]+}}}
 
-// VAR:
-// CHECK: !DIGlobalVariable(name: "var"
-// CHECK-SAME:              line: [[VAR_LINE:[0-9]+]]
-// CHECK-SAME:              type: ![[VAR_T:[0-9]+]]
 // CHECK: ![[VAR_T]] = distinct !DICompositeType(tag: DW_TAG_class_type
 // CHECK-SAME:                          line: [[VAR_LINE]],
 // CHECK-SAME:                          elements: ![[VAR_ARGS:[0-9]+]]
Index: test/CodeGenCXX/debug-info.cpp
===================================================================
--- test/CodeGenCXX/debug-info.cpp
+++ test/CodeGenCXX/debug-info.cpp
@@ -1,14 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=BOTH
 // RUN: %clang_cc1 -triple i686-pc-windows-msvc -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=MSVC --check-prefix=BOTH
 
+// CHECK: @_ZN6pr96081xE = global [3 x i8]* null, align 8, !dbg [[X:![0-9]+]]
+
 // CHECK: define void @_ZN7pr147634funcENS_3fooE
 // CHECK: call void @llvm.dbg.declare({{.*}}, metadata ![[F:[0-9]+]], metadata ![[EXPR:[0-9]+]])
 
 // !llvm.dbg.cu pulls in globals and their types first.
 // CHECK-NOT: !DIGlobalVariable(name: "c"
-// CHECK: !DIGlobalVariable(name: "x", linkageName: "_ZN6pr96081xE"
+// CHECK: [[X]] = distinct !DIGlobalVariable(name: "x", linkageName: "_ZN6pr96081xE"
 // CHECK-SAME:              type: [[INCARRAYPTR:![0-9]*]]
-// CHECK-SAME:              variable: [3 x i8]** @_ZN6pr96081xE
 // CHECK: [[INCARRAYPTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[INCARRAY:![0-9]+]]
 // CHECK: [[INCARRAY]] = !DICompositeType(tag: DW_TAG_array_type
 // CHECK-NOT:                             line:
Index: test/CodeGenCXX/debug-info-uuid.cpp
===================================================================
--- test/CodeGenCXX/debug-info-uuid.cpp
+++ test/CodeGenCXX/debug-info-uuid.cpp
@@ -1,6 +1,18 @@
 // RUN: %clang_cc1 -emit-llvm -fms-extensions -triple=x86_64-pc-win32 -debug-info-kind=limited %s -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -fms-extensions -triple=x86_64-unknown-unknown -debug-info-kind=limited %s -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=CHECK-ITANIUM
 
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "tmpl_guid2<__uuidof(uuid)>"
+// CHECK-SAME:             templateParams: [[TGI2ARGS:![0-9]*]]
+// CHECK: [[TGI2ARGS]] = !{[[TGI2ARG1:![0-9]*]]}
+// CHECK: [[TGI2ARG1]] = !DITemplateValueParameter(
+// CHECK-SAME:                                     type: [[CONST_GUID_REF:![0-9]*]]
+// CHECK-SAME:                                     value: { i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab
+// CHECK: [[CONST_GUID_REF]] = !DIDerivedType(tag: DW_TAG_reference_type,
+// CHECK-SAME:                                baseType: [[CONST_GUID:![0-9]*]]
+// CHECK: [[CONST_GUID]] = !DIDerivedType(tag: DW_TAG_const_type
+// CHECK-SAME:                            baseType: [[GUID:![0-9]*]]
+// CHECK: [[GUID]] = !DICompositeType(tag: DW_TAG_structure_type, name: "_GUID"
+
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "tmpl_guid<&__uuidof(uuid)>"
 // CHECK-SAME:             templateParams: [[TGIARGS:![0-9]*]]
 // CHECK: [[TGIARGS]] = !{[[TGIARG1:![0-9]*]]}
@@ -11,23 +23,11 @@
 // CHECK-SAME:                                baseType: [[CONST_GUID:![0-9]*]]
 // CHECK-SAME:                                size: 64
 // CHECK-SAME:                                align: 64
-// CHECK: [[CONST_GUID]] = !DIDerivedType(tag: DW_TAG_const_type
-// CHECK-SAME:                            baseType: [[GUID:![0-9]*]]
-// CHECK: [[GUID]] = !DICompositeType(tag: DW_TAG_structure_type, name: "_GUID"
-
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "tmpl_guid2<__uuidof(uuid)>"
-// CHECK-SAME:             templateParams: [[TGI2ARGS:![0-9]*]]
-// CHECK: [[TGI2ARGS]] = !{[[TGI2ARG1:![0-9]*]]}
-// CHECK: [[TGI2ARG1]] = !DITemplateValueParameter(
-// CHECK-SAME:                                     type: [[CONST_GUID_REF:![0-9]*]]
-// CHECK-SAME:                                     value: { i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab
-// CHECK: [[CONST_GUID_REF]] = !DIDerivedType(tag: DW_TAG_reference_type,
-// CHECK-SAME:                                baseType: [[CONST_GUID:![0-9]*]]
 
-// CHECK-ITANIUM: !DICompositeType(tag: DW_TAG_structure_type, name: "tmpl_guid<&__uuidof(uuid)>"
-// CHECK-ITANIUM-SAME:             identifier: "_ZTS9tmpl_guidIXadu8__uuidoft4uuidEE"
 // CHECK-ITANIUM: !DICompositeType(tag: DW_TAG_structure_type, name: "tmpl_guid2<__uuidof(uuid)>"
 // CHECK-ITANIUM-SAME:             identifier: "_ZTS10tmpl_guid2IXu8__uuidoft4uuidEE"
+// CHECK-ITANIUM: !DICompositeType(tag: DW_TAG_structure_type, name: "tmpl_guid<&__uuidof(uuid)>"
+// CHECK-ITANIUM-SAME:             identifier: "_ZTS9tmpl_guidIXadu8__uuidoft4uuidEE"
 
 struct _GUID;
 template <const _GUID *>
Index: test/CodeGenCXX/debug-info-template.cpp
===================================================================
--- test/CodeGenCXX/debug-info-template.cpp
+++ test/CodeGenCXX/debug-info-template.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
 
+// CHECK: @tci = global %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>::nested" zeroinitializer, align 1, !dbg [[TCI:![0-9]+]]
+// CHECK: @tcn = global %struct.TC zeroinitializer, align 1, !dbg [[TCN:![0-9]+]]
+// CHECK: @nn = global %struct.NN zeroinitializer, align 1, !dbg [[NN:![0-9]+]]
+
 // CHECK: !DICompileUnit(
 // CHECK: [[EMPTY:![0-9]*]] = !{}
 
@@ -18,13 +22,11 @@
   };
 };
 
-// CHECK: [[INT:![0-9]+]] = !DIBasicType(name: "int"
 int glb;
 void func();
 
-// CHECK: !DIGlobalVariable(name: "tci",
+// CHECK: [[TCI]] = distinct !DIGlobalVariable(name: "tci",
 // CHECK-SAME:              type: ![[TCNESTED:[0-9]+]]
-// CHECK-SAME:              variable: %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>::nested"* @tci
 // CHECK: ![[TCNESTED]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "nested",
 // CHECK-SAME:             scope: ![[TC:[0-9]+]],
 
@@ -39,7 +41,8 @@
   2,
 // CHECK: [[TCARG3]] = !DITemplateValueParameter(name: "x", type: [[CINTPTR:![0-9]*]], value: i32* @glb)
 // CHECK: [[CINTPTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, {{.*}}baseType: [[CINT:![0-9]+]]
-// CHECK: [[CINT]] = !DIDerivedType(tag: DW_TAG_const_type, {{.*}}baseType: [[INT]]
+// CHECK: [[CINT]] = !DIDerivedType(tag: DW_TAG_const_type, {{.*}}baseType: [[INT:![0-9]+]]
+// CHECK: [[INT]] = !DIBasicType(name: "int"
   &glb,
 // CHECK: [[TCARG4]] = !DITemplateValueParameter(name: "a", type: [[MEMINTPTR:![0-9]*]], value: i64 8)
 // CHECK: [[MEMINTPTR]] = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, {{.*}}baseType: [[INT]], {{.*}}extraData: ![[FOO:[0-9]+]])
@@ -80,9 +83,8 @@
 // CHECK: [[TCARG7_3]] = !DITemplateValueParameter(type: [[INT]], value: i32 3)
   3>::nested tci;
 
-// CHECK: !DIGlobalVariable(name: "tcn"
+// CHECK: [[TCN]] = distinct !DIGlobalVariable(name: "tcn"
 // CHECK-SAME:              type: ![[TCNT:[0-9]+]]
-// CHECK-SAME:              variable: %struct.TC* @tcn
 TC
 // CHECK: ![[TCNT]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "TC<int, -3, nullptr, nullptr, nullptr, nullptr>"
 // CHECK-SAME:             templateParams: [[TCNARGS:![0-9]*]]
@@ -121,9 +123,8 @@
 struct NN {
 };
 
-// CHECK: !DIGlobalVariable(name: "nn"
+// CHECK: [[NN]] = distinct !DIGlobalVariable(name: "nn"
 // CHECK-SAME:              type: ![[NNT:[0-9]+]]
-// CHECK-SAME:              variable: %struct.NN* @nn
 
 // FIXME: these parameters should probably be rendered as 'glb' rather than
 // '&glb', since they're references, not pointers.
Index: test/CodeGenCXX/debug-info-template-member.cpp
===================================================================
--- test/CodeGenCXX/debug-info-template-member.cpp
+++ test/CodeGenCXX/debug-info-template-member.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-apple-darwin %s -o - | FileCheck %s
 
+// CHECK: @x = global %"struct.outer<foo>::inner" zeroinitializer, align 4, !dbg [[X:![0-9]+]]
+
 struct MyClass {
   template <int i> int add(int j) {
     return i + j;
@@ -17,9 +19,8 @@
 }
 
 // The compile unit pulls in the global variables first.
-// CHECK: !DIGlobalVariable(name: "x",
+// CHECK: [[X]] = distinct !DIGlobalVariable(name: "x",
 // CHECK-SAME:              type: ![[OUTER_FOO_INNER_ID:[0-9]+]]
-// CHECK-SAME:              variable: %"struct.outer<foo>::inner"* @x
 
 // CHECK: ![[OUTER_FOO_INNER_ID:[0-9]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "inner"{{.*}}, identifier:
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
@@ -38,7 +39,7 @@
 // CHECK: [[C_MEM]] = !{[[C_VPTR:![0-9]*]], [[C_FUNC:![0-9]*]]}
 // CHECK: [[C_VPTR]] = !DIDerivedType(tag: DW_TAG_member, name: "_vptr$MyClass"
 
-// CHECK: [[C_FUNC]] = !DISubprogram(name: "func",{{.*}} line: 7,
+// CHECK: [[C_FUNC]] = !DISubprogram(name: "func",{{.*}} line: 9,
 
 // CHECK: !DISubprogram(name: "add<2>"
 // CHECK-SAME:          scope: [[C]]
Index: test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
===================================================================
--- test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
+++ test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
@@ -22,9 +22,6 @@
 };
 extern template class b<int>;
 b<int> bi;
-// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "b<int>"
-// CHECK-NOT: DIFlagFwdDecl
-// CHECK-SAME: ){{$}}
 
 template <typename T>
 struct c {
@@ -116,3 +113,7 @@
 struct k<int>;
 template struct k<int>;
 // CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "k<int>"
+
+// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "b<int>"
+// CHECK-NOT: DIFlagFwdDecl
+// CHECK-SAME: ){{$}}
Index: test/CodeGenCXX/debug-info-static-member.cpp
===================================================================
--- test/CodeGenCXX/debug-info-static-member.cpp
+++ test/CodeGenCXX/debug-info-static-member.cpp
@@ -3,6 +3,10 @@
 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S -o - | FileCheck %s
 // PR14471
 
+// CHECK: @_ZN1C1aE = global i32 4, align 4, !dbg [[A:![0-9]+]]
+// CHECK: @_ZN1C1bE = global i32 2, align 4, !dbg [[B:![0-9]+]]
+// CHECK: @_ZN1C1cE = global i32 1, align 4, !dbg [[C:![0-9]+]]
+
 enum X {
   Y
 };
@@ -28,37 +32,39 @@
 // why the definition of "a" comes before the declarations while
 // "b" and "c" come after.
 
+// CHECK: [[A]] = distinct !DIGlobalVariable(name: "a", {{.*}} declaration: ![[DECL_A:[0-9]+]])
+//
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X")
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>"
 // CHECK-NOT:              DIFlagFwdDecl
 // CHECK-SAME:             ){{$}}
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var"
 
-// CHECK: !DIGlobalVariable(name: "a", {{.*}}variable: i32* @_ZN1C1aE, declaration: ![[DECL_A:[0-9]+]])
 int C::a = 4;
-// CHECK: ![[DECL_A]] = !DIDerivedType(tag: DW_TAG_member, name: "a"
+// CHECK: [[B]] = distinct !DIGlobalVariable(name: "b", {{.*}} declaration: ![[DECL_B:[0-9]+]])
+// CHECK: ![[DECL_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b"
 // CHECK-NOT:                                 size:
 // CHECK-NOT:                                 align:
 // CHECK-NOT:                                 offset:
-// CHECK-SAME:                                flags: DIFlagStaticMember)
+// CHECK-SAME:                                flags: DIFlagProtected | DIFlagStaticMember)
 //
 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C")
 //
+// CHECK: ![[DECL_A]] = !DIDerivedType(tag: DW_TAG_member, name: "a"
+// CHECK-NOT:                                 size:
+// CHECK-NOT:                                 align:
+// CHECK-NOT:                                 offset:
+// CHECK-SAME:                                flags: DIFlagStaticMember)
+//
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a"
 // CHECK-NOT:            size:
 // CHECK-NOT:            align:
 // CHECK-NOT:            offset:
 // CHECK-SAME:           flags: DIFlagStaticMember,
 // CHECK-SAME:           extraData: i1 true)
 
-// CHECK: ![[DECL_B:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "b"
-// CHECK-NOT:                                 size:
-// CHECK-NOT:                                 align:
-// CHECK-NOT:                                 offset:
-// CHECK-SAME:                                flags: DIFlagProtected | DIFlagStaticMember)
-//
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b"
 // CHECK-NOT:            size:
 // CHECK-NOT:            align:
@@ -82,9 +88,8 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a"
 // CHECK-SAME:           flags: DIFlagPublic | DIFlagStaticMember)
 
-// CHECK: !DIGlobalVariable(name: "b", {{.*}}variable: i32* @_ZN1C1bE, declaration: ![[DECL_B]])
 int C::b = 2;
-// CHECK: !DIGlobalVariable(name: "c", {{.*}}variable: i32* @_ZN1C1cE, declaration: ![[DECL_C]])
+// CHECK: [[C]] = distinct !DIGlobalVariable(name: "c", {{.*}} declaration: ![[DECL_C]])
 int C::c = 1;
 
 int main()
Index: test/CodeGenCXX/debug-info-namespace.cpp
===================================================================
--- test/CodeGenCXX/debug-info-namespace.cpp
+++ test/CodeGenCXX/debug-info-namespace.cpp
@@ -55,16 +55,16 @@
 // This should work even if 'i' and 'func' were declarations & not definitions,
 // but it doesn't yet.
 
-// CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
-// CHECK-SAME:                            imports: [[MODULES:![0-9]*]]
 // CHECK: [[I:![0-9]+]] = distinct !DIGlobalVariable(name: "i",{{.*}} scope: [[NS:![0-9]+]],
 // CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]], file: [[FOOCPP:![0-9]+]], line: 1)
 // CHECK: [[FOOCPP]] = !DIFile(filename: "foo.cpp"
 // CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null, file: [[FILE:![0-9]+]], line: 5)
 // CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-namespace.cpp",
 // CHECK: [[VAR_FWD:![0-9]+]] = distinct !DIGlobalVariable(name: "var_fwd",{{.*}} scope: [[NS]],
 // CHECK-SAME:                                             line: 44
 // CHECK-SAME:                                             isDefinition: true
+// CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
+// CHECK-SAME:                            imports: [[MODULES:![0-9]*]]
 // CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], [[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], [[M17:![0-9]+]]}
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CTXT]], entity: [[NS]], line: 15)
 
Index: test/CodeGenCXX/debug-info-method.cpp
===================================================================
--- test/CodeGenCXX/debug-info-method.cpp
+++ test/CodeGenCXX/debug-info-method.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -debug-info-kind=limited %s -o - | FileCheck %s
+// CHECK: !DIDerivedType(tag: DW_TAG_ptr_to_member_type
 // CHECK: ![[A:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A",{{.*}} identifier: "_ZTS1A")
 // CHECK: !DISubprogram(name: "foo", linkageName: "_ZN1A3fooEiS_3$_0"
 // CHECK-SAME:          DIFlagProtected
 // CHECK: ![[THISTYPE:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[A]]
 // CHECK-SAME:                                  DIFlagArtificial
-// CHECK: !DIDerivedType(tag: DW_TAG_ptr_to_member_type
 // CHECK: !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: ![[MEMFUNTYPE:[0-9]+]]
 // CHECK: ![[MEMFUNTYPE]] = !DISubroutineType(types: ![[MEMFUNARGS:[0-9]+]])
 // CHECK: ![[MEMFUNARGS]] = {{.*}}, ![[THISTYPE]],
Index: test/CodeGenCXX/debug-info-anon-union-vars.cpp
===================================================================
--- test/CodeGenCXX/debug-info-anon-union-vars.cpp
+++ test/CodeGenCXX/debug-info-anon-union-vars.cpp
@@ -45,8 +45,8 @@
 }
 
 // CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE:.*]], line: 6,{{.*}} isLocal: true, isDefinition: true
-// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",
 // CHECK: !DIGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
+// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",
 // CHECK: !DIGlobalVariable(name: "a",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
 // CHECK: !DIGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
 // CHECK: !DIGlobalVariable(name: "result", {{.*}} isLocal: false, isDefinition: true
Index: test/CodeGenCXX/debug-info-anon-namespace.cpp
===================================================================
--- test/CodeGenCXX/debug-info-anon-namespace.cpp
+++ test/CodeGenCXX/debug-info-anon-namespace.cpp
@@ -19,8 +19,9 @@
 
 
 // PS4:  [[NS:![0-9]+]] = !DINamespace
+// PS4:  [[CU:![0-9]+]] = distinct !DICompileUnit
 // PS4:  [[NS2:![0-9]+]] = !DINamespace
-// PS4: !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0, entity: [[NS]])
+// PS4: !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CU]], entity: [[NS]])
 // PS4: !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[NS]], entity: [[NS2]], line: {{[0-9]+}})
 // NON-PS4-NOT: !DIImportedEntity
 
Index: test/CodeGenCXX/debug-info-alias.cpp
===================================================================
--- test/CodeGenCXX/debug-info-alias.cpp
+++ test/CodeGenCXX/debug-info-alias.cpp
@@ -14,8 +14,6 @@
 }
 
 // CHECK: !DIGlobalVariable(name: "bi",{{.*}} type: [[BINT:![0-9]+]]
-// CHECK: [[BINT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar<int>"
-// CHECK-SAME:                      line: 42,
 x::bar<int> bi;
 // CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
 // CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar<float>"
@@ -37,3 +35,6 @@
 using v = void;
 // CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "v"
 v *vp;
+
+// CHECK: [[BINT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar<int>"
+// CHECK-SAME:                      line: 42,
Index: test/CodeGenCXX/debug-info-access.cpp
===================================================================
--- test/CodeGenCXX/debug-info-access.cpp
+++ test/CodeGenCXX/debug-info-access.cpp
@@ -39,6 +39,6 @@
 // CHECK-SAME:          flags: DIFlagPrototyped,
 void free() {}
 
+U u;
 A a;
 B b;
-U u;
Index: test/CodeGen/debug-info-static.c
===================================================================
--- test/CodeGen/debug-info-static.c
+++ test/CodeGen/debug-info-static.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1  -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
 
-// CHECK: !DIGlobalVariable({{.*}}variable: i32* @f.xyzzy
+// CHECK: @f.xyzzy = internal global i32 0, align 4, !dbg [[XYZZY:![0-9]+]]
+
+// CHECK: [[XYZZY]] = distinct !DIGlobalVariable
 void f(void)
 {
    static int xyzzy;
Index: test/CodeGen/debug-info-packed-struct.c
===================================================================
--- test/CodeGen/debug-info-packed-struct.c
+++ test/CodeGen/debug-info-packed-struct.c
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -x c -debug-info-kind=limited -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s
 
+// CHECK: %struct.layout3 = type <{ i8, [3 x i8], %struct.size8_pack4, i8, [3 x i8] }>
 // CHECK: %struct.layout0 = type { i8, %struct.size8, i8 }
 // CHECK: %struct.layout1 = type <{ i8, %struct.size8_anon, i8, [2 x i8] }>
 // CHECK: %struct.layout2 = type <{ i8, %struct.size8_pack1, i8 }>
-// CHECK: %struct.layout3 = type <{ i8, [3 x i8], %struct.size8_pack4, i8, [3 x i8] }>
 
 // ---------------------------------------------------------------------
 // Not packed.
@@ -85,7 +85,7 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12",
 // CHECK-SAME:     {{.*}}size: 1, align: 32, offset: 96)
 
+struct layout3 l3;
 struct layout0 l0;
 struct layout1 l1;
 struct layout2 l2;
-struct layout3 l3;
Index: test/CodeGen/2009-10-20-GlobalDebug.c
===================================================================
--- test/CodeGen/2009-10-20-GlobalDebug.c
+++ test/CodeGen/2009-10-20-GlobalDebug.c
@@ -1,16 +1,18 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang -target i386-apple-darwin10 -flto -S -g %s -o - | FileCheck %s
+
+// CHECK: @main.localstatic = internal global i32 0, align 4, !dbg [[L:![0-9]+]]
+// CHECK: @global = common global i32 0, align 4, !dbg [[G:![0-9]+]]
+
 int global;
 int main() { 
   static int localstatic;
   return 0;
 }
 
-// CHECK: !DIGlobalVariable(name: "localstatic"
+// CHECK: [[L]] = distinct !DIGlobalVariable(name: "localstatic"
 // CHECK-NOT:               linkageName:
-// CHECK-SAME:              line: 5,
-// CHECK-SAME:              variable: i32* @main.localstatic
-// CHECK: !DIGlobalVariable(name: "global"
+// CHECK-SAME:              line: 9,
+// CHECK: [[G]] = distinct !DIGlobalVariable(name: "global"
 // CHECK-NOT:               linkageName:
-// CHECK-SAME:              line: 3,
-// CHECK-SAME:              variable: i32* @global
+// CHECK-SAME:              line: 7,
Index: lib/CodeGen/CodeGenFunction.h
===================================================================
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2690,7 +2690,7 @@
   LValue EmitStmtExprLValue(const StmtExpr *E);
   LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
   LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E);
-  void   EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init);
+  void   EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init);
 
   //===--------------------------------------------------------------------===//
   //                         Scalar Expression Emission
Index: lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1777,8 +1777,8 @@
 }
 
 void CodeGenFunction::EmitDeclRefExprDbgValue(const DeclRefExpr *E,
-                                              llvm::Constant *Init) {
-  assert (Init && "Invalid DeclRefExpr initializer!");
+                                              const APValue &Init) {
+  assert(!Init.isUninit() && "Invalid DeclRefExpr initializer!");
   if (CGDebugInfo *Dbg = getDebugInfo())
     if (CGM.getCodeGenOpts().getDebugInfo() >= codegenoptions::LimitedDebugInfo)
       Dbg->EmitGlobalVariable(E->getDecl(), Init);
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1162,10 +1162,10 @@
   // This should probably fire even for
   if (isa<VarDecl>(value)) {
     if (!getContext().DeclMustBeEmitted(cast<VarDecl>(value)))
-      EmitDeclRefExprDbgValue(refExpr, C);
+      EmitDeclRefExprDbgValue(refExpr, result.Val);
   } else {
     assert(isa<EnumConstantDecl>(value));
-    EmitDeclRefExprDbgValue(refExpr, C);
+    EmitDeclRefExprDbgValue(refExpr, result.Val);
   }
 
   // If we emitted a reference constant, we need to dereference that.
Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -346,7 +346,7 @@
   void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
   /// Emit global variable's debug info.
-  void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
+  void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
 
   /// Emit C++ using directive.
   void EmitUsingDirective(const UsingDirectiveDecl &UD);
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3388,9 +3388,10 @@
       continue;
     }
     // Use VarDecl's Tag, Scope and Line number.
-    GV = DBuilder.createGlobalVariable(DContext, FieldName, LinkageName, Unit,
-                                       LineNo, FieldTy,
-                                       Var->hasInternalLinkage(), Var, nullptr);
+    GV = DBuilder.createGlobalVariable(
+        DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
+        Var->hasInternalLinkage(), nullptr, nullptr);
+    Var->addDebugInfo(GV);
   }
   return GV;
 }
@@ -3423,14 +3424,14 @@
   } else {
     GV = DBuilder.createGlobalVariable(
         DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
-        Var->hasInternalLinkage(), Var,
+        Var->hasInternalLinkage(), nullptr,
         getOrCreateStaticDataMemberDeclarationOrNull(D));
+    Var->addDebugInfo(GV);
   }
   DeclCache[D->getCanonicalDecl()].reset(static_cast<llvm::Metadata *>(GV));
 }
 
-void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
-                                     llvm::Constant *Init) {
+void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
   if (VD->hasAttr<NoDebugAttr>())
     return;
@@ -3470,9 +3471,13 @@
   auto &GV = DeclCache[VD];
   if (GV)
     return;
+  llvm::DIExpression *InitExpr = nullptr;
+  if (Init.isInt())
+    InitExpr =
+        DBuilder.createConstantValueExpression(Init.getInt().getExtValue());
   GV.reset(DBuilder.createGlobalVariable(
       DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
-      true, Init, getOrCreateStaticDataMemberDeclarationOrNull(VarD)));
+      true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD)));
 }
 
 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to