[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-28 Thread Amy Huang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7669f3c0f69d: Recommit [CodeView] Emit static data 
members as S_CONSTANTs. (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  llvm/include/llvm/CodeGen/DebugHandlerBase.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,14 +12,22 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name:
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
 ; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
 ; CHECK-NEXT: SizeOf: 0
-; CHECK-NEXT: Name: 
+; CHECK-NEXT: Name:
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = 

[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-27 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 301080.
akhuang added a comment.
Herald added a subscriber: jfb.

Moved isUnsignedDIType to DebugHandlerBase to avoid copying it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  llvm/include/llvm/CodeGen/DebugHandlerBase.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,14 +12,22 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name:
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
 ; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
 ; CHECK-NEXT: SizeOf: 0
-; CHECK-NEXT: Name: 
+; CHECK-NEXT: Name:
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang 

[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-27 Thread Amy Huang via Phabricator via cfe-commits
akhuang reopened this revision.
akhuang added a comment.
This revision is now accepted and ready to land.

Reverted because my copied `isUnsignedDIType` function had problems (guess I 
copied it at first but then was messing with the code); I moved it to 
DebugHandlerBase.h so it doesn't need to be copied.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-26 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

Patch to emit signed ints for other S_CONSTANTs: https://reviews.llvm.org/D90199


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-26 Thread Amy Huang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG515973222ed2: [CodeView] Emit static data members as 
S_CONSTANTs. (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,14 +12,22 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name:
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
 ; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
 ; CHECK-NEXT: SizeOf: 0
-; CHECK-NEXT: Name: 
+; CHECK-NEXT: Name:
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 

[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm

Please fix this case in a follow-up, though:

  static const signed int gv_signed = 0x;
  const signed int useit2() { return gv_signed; }

I think your `APSInt` code only works on static data member constants.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-23 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 300438.
akhuang added a comment.

Fix test failures; remove assert for signed APSInts.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,14 +12,22 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name:
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
 ; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
 ; CHECK-NEXT: SizeOf: 0
-; CHECK-NEXT: Name: 
+; CHECK-NEXT: Name:
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, 

[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-23 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked an inline comment as done.
akhuang added a comment.

Whoops, forgot to check the tests. Apparently `mapEncodedInteger` asserts if a 
signed APInt is not less than 0. I just removed the assert because it doesn't 
seem necessary?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-23 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

It seems like there are related test failures according to the 
Phabricator/Jenkins automation. Is that a true positive? Please confirm either 
way before landing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-22 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Looks good with a test for explicit zero initialization.




Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:3157
+
+if (Value.isNullValue())
+  continue;

What about zero constants like:
  struct Foo {
static const int sdm = 0;
  };

I think isNullValue just compares against zero, so that's not quite right. 
Maybe structure it as `if ConstantInt / else if ConstantFP / else continue`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-19 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-static-member.cpp:144-147
+// For some reason, const_va is not emitted when the target is MS.
+// NOT-MS: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
+// NOT-MS-SAME:   line: [[@LINE-3]]
+// NOT-MS-SAME:   extraData: i32 42

akhuang wrote:
> rnk wrote:
> > dblaikie wrote:
> > > Bug or feature? If it's a bug, probably should at least make this comment 
> > > a "FIXME"
> > Feature. The easiest way to understand it is to hallucinate the C++17 
> > `inline` keyword on MSVC static const integer data members with inline 
> > initializers. This metadata is probably emitted in MS mode, but it probably 
> > comes later on.
> Oh, ok. I don't think the metadata for `const_va` is emitted anywhere in MS 
> mode though. I guess it should be.
Not quite sure I follow - even though it's "inline" and thus the actual storage 
for the variable isn't emitted here (because it's just emitted anywhere it's 
needed, so the definition can be ignored)... 

Oh, because the definition is the only root holding the type alive in this file 
- yeah, if the definition is ignored, the type won't be emitted, etc. Fair 
enough. Test might be fixed to be more portable by making the type referenced 
otherwise (eg: declaring a variable that is a pointer to this type, maybe)

Oh, but right... yeah, the virtual dtor is there specifically to test the case 
where there is no type definition.

As to "const_va is not emitted anywhere in MS mode" - I'd have expected it to 
be emitted if the type definition is emitted:
```
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "x", file: !3, 
line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !7, identifier: 
"_ZTS1x")
!7 = !{!8}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !6, file: !3, line: 
1, baseType: !9, flags: DIFlagStaticMember, extraData: i32 42)
```
Something like that. But, yeah, if you use a type to hold some constants but 
never emit the type definition anywhere - then you'd never get the static 
member, I suppose.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked an inline comment as done.
akhuang added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-static-member.cpp:144-147
+// For some reason, const_va is not emitted when the target is MS.
+// NOT-MS: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
+// NOT-MS-SAME:   line: [[@LINE-3]]
+// NOT-MS-SAME:   extraData: i32 42

rnk wrote:
> dblaikie wrote:
> > Bug or feature? If it's a bug, probably should at least make this comment a 
> > "FIXME"
> Feature. The easiest way to understand it is to hallucinate the C++17 
> `inline` keyword on MSVC static const integer data members with inline 
> initializers. This metadata is probably emitted in MS mode, but it probably 
> comes later on.
Oh, ok. I don't think the metadata for `const_va` is emitted anywhere in MS 
mode though. I guess it should be.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-14 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 298258.
akhuang marked an inline comment as done.
akhuang added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,14 +12,22 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name:
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
 ; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
 ; CHECK-NEXT: SizeOf: 0
-; CHECK-NEXT: Name: 
+; CHECK-NEXT: Name:
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !15, globals: !16, nameTableKind: None)

[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-static-member.cpp:144-147
+// For some reason, const_va is not emitted when the target is MS.
+// NOT-MS: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
+// NOT-MS-SAME:   line: [[@LINE-3]]
+// NOT-MS-SAME:   extraData: i32 42

dblaikie wrote:
> Bug or feature? If it's a bug, probably should at least make this comment a 
> "FIXME"
Feature. The easiest way to understand it is to hallucinate the C++17 `inline` 
keyword on MSVC static const integer data members with inline initializers. 
This metadata is probably emitted in MS mode, but it probably comes later on.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:3147
+const DIScope *Scope = DTy->getScope();
+std::string QualifiedName = getFullyQualifiedName(Scope, DTy->getName());
+

Let's move this past the continue so we don't construct the name unless the 
value is non-null.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:3169
+CodeViewRecordIO IO(Writer);
+if (isStaticConstUnsigned(DTy->getBaseType())) {
+  uint64_t Val = Value.getZExtValue();

This makes me suspect that we still have bugs in the original S_CONSTANT code. 
Looks like this is a pre-existing bug:
```
$ cat t.cpp
static const signed int gv_signed = 0x;
const signed int useit2() { return gv_signed; }

$ clang-cl -c -Z7 t.cpp  && llvm-pdbutil dump -symbols t.obj | grep -A1 S_CONST
   0 | S_CONSTANT [size = 28] `gv_signed`
   type = 0x1000 (const int), value = 18446744073709551615

$ cl -c -Z7 t.cpp  && llvm-pdbutil dump -symbols t.obj | grep -A1 S_CONST
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29111 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.cpp
   0 | S_CONSTANT [size = 21] `gv_signed`
   type = 0x1000 (const int), value = -1
```

Can you re-structure this so that we aren't duplicating the calls to 
mapEncodedInteger in two places? mapEncodedInteger takes an APInt, which 
carries a sign already. We just have to use the type information to correct the 
sign on Value.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-static-member.cpp:144-147
+// For some reason, const_va is not emitted when the target is MS.
+// NOT-MS: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
+// NOT-MS-SAME:   line: [[@LINE-3]]
+// NOT-MS-SAME:   extraData: i32 42

Bug or feature? If it's a bug, probably should at least make this comment a 
"FIXME"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-08 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 297068.
akhuang added a comment.

Update clang test for static data members, and make it test the general cases
on the windows target as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,6 +12,14 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name: 
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
@@ -19,7 +27,7 @@
 ; CHECK-NEXT: SizeOf: 0
 ; CHECK-NEXT: Name: 
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !15, globals: !16, nameTableKind: None)
+!0 = 

[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-08 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

In D89072#2320209 , @dblaikie wrote:

> I'll probably leave the llvm/CodeView parts of this for @rnk - but for the 
> clang parts, they should have corresponding clang test coverage & I'd be 
> curious to see the test for that to understand what the IR was before/after 
> this change. (& to understand if/how either of those differ from the DWARF IR)

Oh, I forgot to update the clang tests. The clang change reverts 
https://reviews.llvm.org/D62167, which made the IR for CodeView different 
(adding DIGlobalVariables for static members).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

I'll probably leave the llvm/CodeView parts of this for @rnk - but for the 
clang parts, they should have corresponding clang test coverage & I'd be 
curious to see the test for that to understand what the IR was before/after 
this change. (& to understand if/how either of those differ from the DWARF IR)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89072/new/

https://reviews.llvm.org/D89072

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89072: [CodeView] Emit static data members as S_CONSTANTs.

2020-10-08 Thread Amy Huang via Phabricator via cfe-commits
akhuang created this revision.
akhuang added reviewers: rnk, dblaikie.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
akhuang requested review of this revision.

We used to only emit static const data members in CodeView as
S_CONSTANTS when they were used; this patch makes it so they are always emitted.

I changed CodeViewDebug.cpp to find the static const members from the
class debug info instead of creating DIGlobalVariables in the IR 
whenever a static const data member is used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89072

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/test/DebugInfo/COFF/global-constants.ll
  llvm/test/DebugInfo/COFF/types-array-unsized.ll

Index: llvm/test/DebugInfo/COFF/types-array-unsized.ll
===
--- llvm/test/DebugInfo/COFF/types-array-unsized.ll
+++ llvm/test/DebugInfo/COFF/types-array-unsized.ll
@@ -12,6 +12,14 @@
 ; Foo f; // FIXME: only needed to force emit 'Foo'
 
 ; CHECK:  CodeViewTypes [
+; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
+; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
+; CHECK-NEXT: ElementType: const char ({{.*}})
+; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
+; CHECK-NEXT: SizeOf: 5
+; CHECK-NEXT: Name: 
+; CHECK-NEXT:   }
+; CHECK:  ]
 ; CHECK:Array ([[ARRAY_FWD:0x.*]]) {
 ; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
 ; CHECK-NEXT: ElementType: const char ({{.*}})
@@ -19,7 +27,7 @@
 ; CHECK-NEXT: SizeOf: 0
 ; CHECK-NEXT: Name: 
 ; CHECK-NEXT:   }
-; CHECK:FieldList (0x1003) {
+; CHECK:FieldList (0x1004) {
 ; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
 ; CHECK-NEXT: StaticDataMember {
 ; CHECK-NEXT:   TypeLeafKind: LF_STMEMBER (0x150E)
@@ -28,14 +36,6 @@
 ; CHECK-NEXT:   Name: str
 ; CHECK-NEXT: }
 ; CHECK-NEXT:   }
-; CHECK:Array ([[ARRAY_COMPLETE:0x.*]]) {
-; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
-; CHECK-NEXT: ElementType: const char ({{.*}})
-; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
-; CHECK-NEXT: SizeOf: 5
-; CHECK-NEXT: Name: 
-; CHECK-NEXT:   }
-; CHECK:  ]
 
 ; CHECK:  GlobalData {
 ; CHECK-NEXT:   Kind: S_GDATA32 (0x110D)
Index: llvm/test/DebugInfo/COFF/global-constants.ll
===
--- llvm/test/DebugInfo/COFF/global-constants.ll
+++ llvm/test/DebugInfo/COFF/global-constants.ll
@@ -7,6 +7,9 @@
 ; }
 ; struct S {
 ;   static const int TestConst2 = -10;
+;   // Unused static consts should still be emitted.
+;   static const int TestConst3 = 3;
+;   static constexpr int TestConst 4 = 4;
 ;   enum { SEnum = 42 };
 ; };
 ; enum TestEnum : int {
@@ -34,14 +37,6 @@
 
 ; ASM:	  .short	4359# Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101# Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0xf6, 0xff  # Value
-; ASM-NEXT:	  .byte	0xff, 0xff, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
-; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
-; ASM-NEXT:	  .p2align	2
-
-; ASM:	  .short	4359# Record kind: S_CONSTANT
-; ASM-NEXT:	  .long	4110# Type
 ; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
 ; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
 ; ASM-NEXT:	  .byte	0xff, 0xff
@@ -49,6 +44,12 @@
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:.asciz "S::SEnum" # Name
 
+; ASM:	  .short	4359# Record kind: S_CONSTANT
+; ASM-NEXT:	  .long	4105# Type
+; ASM-NEXT:	  .byte	0x00, 0x80, 0xf6# Value
+; ASM-NEXT:	  .asciz	"S::TestConst2" # Name
+; ASM-NEXT:	  .p2align	2
+
 ; OBJ:CodeViewDebugInfo [
 ; OBJ:  Section: .debug$S
 ; OBJ:  Magic: 0x4
@@ -62,17 +63,17 @@
 ; OBJ-NEXT:   }
 ; OBJ-NEXT:   ConstantSym {
 ; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: const int (0x1005)
-; OBJ-NEXT: Value: 18446744073709551606
-; OBJ-NEXT: Name: S::TestConst2
-; OBJ-NEXT:   }
-; OBJ-NEXT:   ConstantSym {
-; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
-; OBJ-NEXT: Type: TestEnum (0x100E)
+; OBJ-NEXT: Type: TestEnum (0x1005)
 ; OBJ-NEXT: Value: 18446744071562551616
 ; OBJ-NEXT: Name: ENUM_B
 ; OBJ-NEXT:   }
 ; OBJ-NOT:  Name: S::SEnum
+; OBJ-NEXT:   ConstantSym {
+; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
+; OBJ-NEXT: Type: const int (0x1009)
+; OBJ-NEXT: Value: -10
+; OBJ-NEXT: Name: S::TestConst2
+; OBJ-NEXT:   }
 
 ; ModuleID = 'a.cpp'
 source_filename = "a.cpp"
@@ -98,43 +99,43 @@
 !llvm.module.flags = !{!26, !27, !28, !29}
 !llvm.ident = !{!30}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang