[PATCH] D130156: [llvm] Fix some test failures with EXPENSIVE_CHECKS and libstdc++

David Spickett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 03:01:48 PDT 2022


DavidSpickett created this revision.
Herald added subscribers: jsji, pengfei, mgrang, hiraditya.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

DebugLocEntry assumes that it either contains 1 item that has no fragment
or many items that all have fragments (see the assert in addValues).

When EXPENSIVE_CHECKS is enabled, _GLIBCXX_DEBUG is defined. On a few machines
I've checked, this causes std::sort to call the comparator even
if there is only 1 item to sort. Perhaps to check that it is implemented
properly ordering wise, I didn't find out exactly why.

operator< for a DbgValueLoc will crash if this happens because the
optional Fragment is empty.

Compiler/linker/optimisation level seems to make this happen
or not. So I've seen this happen on x86 Ubuntu but the buildbot
for release EXPENSIVE_CHECKS did not have this issue.

Add an explicit check if we have 1 item when EXPENSIVE_CHECKS is enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130156

Files:
  llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h


Index: llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
+++ llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
@@ -214,6 +214,15 @@
   // Sort the pieces by offset.
   // Remove any duplicate entries by dropping all but the first.
   void sortUniqueValues() {
+#ifdef EXPENSIVE_CHECKS
+    // EXPENSIVE_CHECKS enables _GLIBCXX_DEBUG which causes std::sort to
+    // call operator< below, even if there is only one item
+    // (preumably to check if the comparator is implemented correctly).
+    // Values has 2 states. 1 item that does not have a fragment, or
+    // many items that all do. If it's the former then operator< will crash.
+    if (Values.size() == 1)
+      return;
+#endif
     llvm::sort(Values);
     Values.erase(std::unique(Values.begin(), Values.end(),
                              [](const DbgValueLoc &A, const DbgValueLoc &B) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130156.446095.patch
Type: text/x-patch
Size: 961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220720/da66bdc4/attachment.bin>


More information about the llvm-commits mailing list