[llvm] r345811 - [CodeView] Emit the correct TypeIndex for std::nullptr_t.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 31 21:02:41 PDT 2018


Author: zturner
Date: Wed Oct 31 21:02:41 2018
New Revision: 345811

URL: http://llvm.org/viewvc/llvm-project?rev=345811&view=rev
Log:
[CodeView] Emit the correct TypeIndex for std::nullptr_t.

The TypeIndex used by cl.exe is 0x103, which indicates a SimpleTypeMode
of NearPointer (note the absence of the bitness, normally pointers use a
mode of NearPointer32 or NearPointer64) and a SimpleTypeKind of void.
So this is basically a void*, but without a specified size, which makes
sense given how std::nullptr_t is defined.

clang-cl was actually not emitting *anything* for this. Instead, when we
encountered std::nullptr_t in a DIType, we would actually just emit a
TypeIndex of 0, which is obviously wrong.

std::nullptr_t in DWARF is represented as a DW_TAG_unspecified_type with
a name of "decltype(nullptr)", so we add that logic along with a test,
as well as an update to the dumping code so that we no longer print
void* when dumping 0x103 (which would previously treat Void/NearPointer
no differently than Void/NearPointer64).

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

Added:
    llvm/trunk/test/DebugInfo/COFF/types-std-nullptr-t.ll
Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/trunk/lib/DebugInfo/CodeView/TypeIndex.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h?rev=345811&r1=345810&r2=345811&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h Wed Oct 31 21:02:41 2018
@@ -145,6 +145,13 @@ public:
     return TypeIndex(SimpleTypeKind::Void, SimpleTypeMode::NearPointer64);
   }
 
+  static TypeIndex NullptrT() {
+    // std::nullptr_t uses the pointer mode that doesn't indicate bit-width,
+    // presumably because std::nullptr_t is intended to be compatible with any
+    // pointer type.
+    return TypeIndex(SimpleTypeKind::Void, SimpleTypeMode::NearPointer);
+  }
+
   static TypeIndex SignedCharacter() {
     return TypeIndex(SimpleTypeKind::SignedCharacter);
   }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=345811&r1=345810&r2=345811&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Wed Oct 31 21:02:41 2018
@@ -1516,6 +1516,8 @@ TypeIndex CodeViewDebug::lowerType(const
   case dwarf::DW_TAG_union_type:
     return lowerTypeUnion(cast<DICompositeType>(Ty));
   case dwarf::DW_TAG_unspecified_type:
+    if (Ty->getName() == "decltype(nullptr)")
+      return TypeIndex::NullptrT();
     return TypeIndex::None();
   default:
     // Use the null type index.

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeIndex.cpp?rev=345811&r1=345810&r2=345811&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeIndex.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeIndex.cpp Wed Oct 31 21:02:41 2018
@@ -74,6 +74,9 @@ StringRef TypeIndex::simpleTypeName(Type
   if (TI.isNoneType())
     return "<no type>";
 
+  if (TI == TypeIndex::NullptrT())
+    return "std::nullptr_t";
+
   // This is a simple type.
   for (const auto &SimpleTypeName : SimpleTypeNames) {
     if (SimpleTypeName.Kind == TI.getSimpleKind()) {

Added: llvm/trunk/test/DebugInfo/COFF/types-std-nullptr-t.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/types-std-nullptr-t.ll?rev=345811&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/types-std-nullptr-t.ll (added)
+++ llvm/trunk/test/DebugInfo/COFF/types-std-nullptr-t.ll Wed Oct 31 21:02:41 2018
@@ -0,0 +1,42 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
+
+; C++ source to regenerate:
+; $ cat foo.cpp
+; decltype(nullptr) NullPtr = nullptr;
+; $ clang hello.cpp -S -emit-llvm -g -gcodeview -o t.ll
+
+; CHECK: CodeViewDebugInfo [
+; CHECK:   Subsection [
+; CHECK:     SubSectionType: Symbols (0xF1)
+; CHECK:     GlobalData {
+; CHECK:       Kind: S_GDATA32 (0x110D)
+; CHECK:       DataOffset: ?NullPtr@@3$$TA+0x0
+; CHECK:       Type: std::nullptr_t (0x103)
+; CHECK:       DisplayName: NullPtr
+; CHECK:       LinkageName: ?NullPtr@@3$$TA
+; CHECK:     }
+
+
+; ModuleID = 'foo.cpp'
+source_filename = "foo.cpp"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.15.26730"
+
+@"?NullPtr@@3$$TA" = dso_local global i8* null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "NullPtr", linkageName: "?NullPtr@@3$$TA", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 8.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
+!3 = !DIFile(filename: "foo.cpp", directory: "D:\5Csrc\5Cllvmbuild\5Ccl\5CDebug\5Cx64", checksumkind: CSK_MD5, checksum: "0d5c7c9860a17e584808c03a24a135e6")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
+!7 = !{i32 2, !"CodeView", i32 1}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 2}
+!10 = !{i32 7, !"PIC Level", i32 2}
+!11 = !{!"clang version 8.0.0 "}




More information about the llvm-commits mailing list