[llvm] a0ccba5 - [llvm] Fix some test failures with EXPENSIVE_CHECKS and libstdc++

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 01:53:43 PDT 2022


Author: David Spickett
Date: 2022-07-28T08:53:38Z
New Revision: a0ccba5e192b14341b66ad57bc646a3af7418409

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

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

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 whether we have 1 item.

Reviewed By: aprantl

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h b/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
index d7ab2091967fa..f6c1f0eb21944 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
@@ -214,6 +214,11 @@ class DebugLocEntry {
   // Sort the pieces by offset.
   // Remove any duplicate entries by dropping all but the first.
   void sortUniqueValues() {
+    // Values is either 1 item that does not have a fragment, or many items
+    // that all do. No need to sort if the former and also prevents operator<
+    // being called on a non fragment item when _GLIBCXX_DEBUG is defined.
+    if (Values.size() == 1)
+      return;
     llvm::sort(Values);
     Values.erase(std::unique(Values.begin(), Values.end(),
                              [](const DbgValueLoc &A, const DbgValueLoc &B) {


        


More information about the llvm-commits mailing list