[PATCH] D55721: llvm-dwarfdump: Improve/fix pretty printing of array dimensions

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 14 14:21:42 PST 2018


dblaikie created this revision.
dblaikie added reviewers: aprantl, probinson, JDevlieghere.
Herald added a subscriber: llvm-commits.

This is to address post-commit feedback from Paul Robinson on r348954.

The original commit misinterprets count and upper bound as the same thing (I thought I saw GCC producing an upper bound the same as Clang's count, but GCC correctly produces an upper bound that's one less than the count (in C, that is, where arrays are zero indexed)).

I want to preserve the C-like output for the common case, so in the absence of a lower bound the count (or one greater than the upper bound) is rendered between []. In the trickier cases, where a lower bound is specified, a half-open range is used (eg: lower bound 1, count 2 would be "[1, 3)" and an unknown parts use a '?' (eg: "[1, ?)" or "[?, 7)" or "[?, ? + 3)").


Repository:
  rL LLVM

https://reviews.llvm.org/D55721

Files:
  lib/DebugInfo/DWARF/DWARFDie.cpp
  test/tools/llvm-dwarfdump/X86/prettyprint_types.s


Index: test/tools/llvm-dwarfdump/X86/prettyprint_types.s
===================================================================
--- test/tools/llvm-dwarfdump/X86/prettyprint_types.s
+++ test/tools/llvm-dwarfdump/X86/prettyprint_types.s
@@ -20,7 +20,7 @@
 
 # array_type
 # Testing lower_bound, upper_bound, lower and upper, lower and count, and count separately.
-# CHECK:   DW_AT_type{{.*}}"int[1-][2][1-2][1-3][2]"
+# CHECK:   DW_AT_type{{.*}}"int{{\[}}[1, ?)][3]{{\[}}[1, 2)]{{\[}}[1, 3)][2]"
 
 # subroutine types
 # CHECK:   DW_AT_type{{.*}}"int()"
Index: lib/DebugInfo/DWARF/DWARFDie.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFDie.cpp
+++ lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -204,20 +204,37 @@
     Optional<uint64_t> Bound;
     for (const DWARFDie &C : D.children())
       if (C.getTag() == DW_TAG_subrange_type) {
-        OS << '[';
-        uint64_t LowerBound = 0;
+        Optional<uint64_t> LB;
+        Optional<uint64_t> Count;
+        Optional<uint64_t> UB;
         if (Optional<DWARFFormValue> L = C.find(DW_AT_lower_bound))
-          if (Optional<uint64_t> LB = L->getAsUnsignedConstant()) {
-            LowerBound = *LB;
-            OS << LowerBound << '-';
-          }
-        if (Optional<DWARFFormValue> CountV = C.find(DW_AT_count)) {
-          if (Optional<uint64_t> C = CountV->getAsUnsignedConstant())
-            OS << (*C + LowerBound);
-        } else if (Optional<DWARFFormValue> UpperV = C.find(DW_AT_upper_bound))
-          if (Optional<uint64_t> U = UpperV->getAsUnsignedConstant())
-            OS << *U;
-        OS << ']';
+          LB = L->getAsUnsignedConstant();
+        if (Optional<DWARFFormValue> CountV = C.find(DW_AT_count))
+          Count = CountV->getAsUnsignedConstant();
+        if (Optional<DWARFFormValue> UpperV = C.find(DW_AT_upper_bound))
+          UB = UpperV->getAsUnsignedConstant();
+        if (!LB && !Count && !UB)
+          OS << "[]";
+        if (!LB && (Count || UB))
+          OS << '[' << (Count ? *Count : *UB + 1) << ']';
+        else {
+          OS << "[[";
+          if (LB)
+            OS << *LB;
+          else
+            OS << '?';
+          OS << ", ";
+          if (Count)
+            if (LB)
+              OS << *LB + *Count;
+            else
+              OS << "? + " << *Count;
+          else if (UB)
+            OS << *UB;
+          else
+            OS << '?';
+          OS << ")]";
+        }
       }
     break;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55721.178286.patch
Type: text/x-patch
Size: 2493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181214/954a61b5/attachment.bin>


More information about the llvm-commits mailing list