diff --git a/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h b/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
--- a/llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h
+++ b/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) {