[llvm] 7156910 - [CodeView] Encode signed int values correctly when emitting S_CONSTANTs

Amy Huang via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 30 09:31:14 PDT 2020


Author: Amy Huang
Date: 2020-10-30T09:28:41-07:00
New Revision: 7156910d85fcafdc78371a852c00a7184f8563cd

URL: https://github.com/llvm/llvm-project/commit/7156910d85fcafdc78371a852c00a7184f8563cd
DIFF: https://github.com/llvm/llvm-project/commit/7156910d85fcafdc78371a852c00a7184f8563cd.diff

LOG: [CodeView] Encode signed int values correctly when emitting S_CONSTANTs

Differential Revision: https://reviews.llvm.org/D90199

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/test/DebugInfo/COFF/global-constants.ll
    llvm/test/DebugInfo/COFF/globals.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 125fea76b841..532d506862ea 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -3156,6 +3156,25 @@ void CodeViewDebug::emitStaticConstMemberList() {
   }
 }
 
+static bool isFloatDIType(const DIType *Ty) {
+  if (auto *CTy = dyn_cast<DICompositeType>(Ty))
+    return false;
+
+  if (auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
+    dwarf::Tag T = (dwarf::Tag)Ty->getTag();
+    if (T == dwarf::DW_TAG_pointer_type ||
+        T == dwarf::DW_TAG_ptr_to_member_type ||
+        T == dwarf::DW_TAG_reference_type ||
+        T == dwarf::DW_TAG_rvalue_reference_type)
+      return false;
+    assert(DTy->getBaseType() && "Expected valid base type");
+    return isFloatDIType(DTy->getBaseType());
+  }
+
+  auto *BTy = cast<DIBasicType>(Ty);
+  return (BTy->getEncoding() == dwarf::DW_ATE_float);
+}
+
 void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
   const DIGlobalVariable *DIGV = CVGV.DIGV;
 
@@ -3191,7 +3210,12 @@ void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
     const DIExpression *DIE = CVGV.GVInfo.get<const DIExpression *>();
     assert(DIE->isConstant() &&
            "Global constant variables must contain a constant expression.");
-    uint64_t Val = DIE->getElement(1);
+
+    // Use unsigned for floats.
+    bool isUnsigned = isFloatDIType(DIGV->getType())
+                          ? true
+                          : DebugHandlerBase::isUnsignedDIType(DIGV->getType());
+    APSInt Value(APInt(/*BitWidth=*/64, DIE->getElement(1)), isUnsigned);
 
     MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
     OS.AddComment("Type");
@@ -3202,7 +3226,7 @@ void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
     uint8_t data[10];
     BinaryStreamWriter Writer(data, llvm::support::endianness::little);
     CodeViewRecordIO IO(Writer);
-    cantFail(IO.mapEncodedInteger(Val));
+    cantFail(IO.mapEncodedInteger(Value));
     StringRef SRef((char *)data, Writer.getOffset());
     OS.emitBinaryData(SRef);
 

diff  --git a/llvm/test/DebugInfo/COFF/global-constants.ll b/llvm/test/DebugInfo/COFF/global-constants.ll
index 8276932925ac..c0e6afbe7024 100644
--- a/llvm/test/DebugInfo/COFF/global-constants.ll
+++ b/llvm/test/DebugInfo/COFF/global-constants.ll
@@ -37,9 +37,8 @@
 
 ; ASM:	      .short	4359                    # Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4101                    # Type
-; ASM-NEXT:	  .byte	0x0a, 0x80, 0x40, 0x61  # Value
-; ASM-NEXT:	  .byte	0x07, 0x80, 0xff, 0xff
-; ASM-NEXT:	  .byte	0xff, 0xff
+; ASM-NEXT:	  .byte	0x03, 0x80, 0x40, 0x61  # Value
+; ASM-NEXT:	  .byte	0x07, 0x80
 ; ASM-NEXT:	  .asciz	"ENUM_B"                # Name
 ; ASM-NEXT:	  .p2align	2
 ; ASM-NOT:    .asciz "S::SEnum"             # Name
@@ -64,7 +63,7 @@
 ; OBJ-NEXT:       ConstantSym {
 ; OBJ-NEXT:         Kind: S_CONSTANT (0x1107)
 ; OBJ-NEXT:         Type: TestEnum (0x1005)
-; OBJ-NEXT:         Value: 18446744071562551616
+; OBJ-NEXT:         Value: -214700000
 ; OBJ-NEXT:         Name: ENUM_B
 ; OBJ-NEXT:       }
 ; OBJ-NOT:          Name: S::SEnum

diff  --git a/llvm/test/DebugInfo/COFF/globals.ll b/llvm/test/DebugInfo/COFF/globals.ll
index 583f108f3f49..7960f63b1474 100644
--- a/llvm/test/DebugInfo/COFF/globals.ll
+++ b/llvm/test/DebugInfo/COFF/globals.ll
@@ -86,19 +86,19 @@
 
 ; ASM:        .short	4359                    # Record kind: S_CONSTANT
 ; ASM-NEXT:	  .long	4100                    # Type
-; ASM-NEXT:   .byte	0x08, 0x00              # Value
+; ASM-NEXT:   .byte	0x00, 0x80, 0x08        # Value
 ; ASM-NEXT:	  .asciz	"foo::constExpr"        # Name
 ; ASM-NEXT:   .p2align	2
 
 ; ASM:        .short	4359                    # Record kind: S_CONSTANT
 ; ASM-NEXT:   .long	4100                    # Type
-; ASM-NEXT:   .byte	0x09, 0x00              # Value
+; ASM-NEXT:   .byte	0x00, 0x80, 0x09        # Value
 ; ASM-NEXT:   .asciz	"foo::constVal"         # Name
 ; ASM-NEXT:   .p2align	2
 
 ; ASM:        .short	4359                    # Record kind: S_CONSTANT
 ; ASM-NEXT:   .long	4100                    # Type
-; ASM-NEXT:   .byte	0x0e, 0x00              # Value
+; ASM-NEXT:   .byte	0x00, 0x80, 0x0e        # Value
 ; ASM-NEXT:   .asciz	"foo::Data::DataConstExpr" # Name
 ; ASM-NEXT:   .p2align	2
 


        


More information about the llvm-commits mailing list