[PATCH] D81357: [DWARFYAML][debug_ranges] Emit an error message for invalid offset.

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 01:35:27 PDT 2020


jhenderson added inline comments.


================
Comment at: llvm/lib/ObjectYAML/DWARFEmitter.cpp:134
     const size_t CurrOffset = OS.tell() - RangesOffset;
-    assert(DebugRanges.Offset >= CurrOffset &&
-           "Offset should be greater than or equal to the bytes that we have "
-           "written");
+    if ((uint64_t)DebugRanges.Offset < CurrOffset)
+      return createStringError(errc::invalid_argument,
----------------
Do you need the new cast? If I've followed it correctly, `Offset` is a `Hex64`, so is already a 64-bit number.


================
Comment at: llvm/lib/ObjectYAML/DWARFEmitter.cpp:138-139
+                                   Twine(EntryIndex) +
+                                   " must be greater than or equal to the "
+                                   "bytes we have written (0x" +
+                                   Twine::utohexstr(CurrOffset) + ")");
----------------
I think this should be " must be greater than or equal to the number of bytes written already (0x"


================
Comment at: llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml:317
+
+## i) Test that yaml2obj emits an error message if we try to assign an invalid offset to the
+## entry of the '.debug_ranges' section.
----------------
invalid offset to the -> invalid offset to an


================
Comment at: llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml:337
+          HighOffset: 0x02
+    - Offset:   0x10 ## Must be greater than or equal to 0x20.
+      AddrSize: 0x08
----------------
Let's make this `0x1A` to test the edge case (i.e. no off-by-one error).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81357





More information about the llvm-commits mailing list