[PATCH] D130282: [llvm][FileCheck] Fix unit tests failures with EXPENSIVE_CHECKS

David Spickett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 08:40:52 PDT 2022


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

EXPENSIVE_CHECKS enables _GLIBCXX_DEBUG, which makes std::sort
check that the compare function is implemented correctly.

To do this it calls it with the first item as both sides.
Which trips the assert here because we think they're
2 capture ranges that overlap, when it's just the same range twice.

If EXPENSIVE_CHECKS is enabled check up front for them being
the same range (the same object, not just that they are ==).

(I considered putting this in llvm::sort but I think it's worth
fixing individual comparators so that we get the benefit of the
checks for the rest)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130282

Files:
  llvm/lib/FileCheck/FileCheck.cpp


Index: llvm/lib/FileCheck/FileCheck.cpp
===================================================================
--- llvm/lib/FileCheck/FileCheck.cpp
+++ llvm/lib/FileCheck/FileCheck.cpp
@@ -1424,6 +1424,14 @@
   // Sort variable captures by the order in which they matched the input.
   // Ranges shouldn't be overlapping, so we can just compare the start.
   llvm::sort(VarCaptures, [](const VarCapture &A, const VarCapture &B) {
+#ifdef EXPENSIVE_CHECKS
+    // When _GLIBCXX_DEBUG is enabled it will call the compare function
+    // with the first item as both sides to check that it is irreflexive
+    // (!(a<a) must be true). Which would otherwise make us think that a
+    // single capture overlaps with itself.
+    if (&A == &B)
+      return false;
+#endif
     assert(A.Range.Start != B.Range.Start &&
            "unexpected overlapping variable captures");
     return A.Range.Start.getPointer() < B.Range.Start.getPointer();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130282.446524.patch
Type: text/x-patch
Size: 938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220721/711ee011/attachment.bin>


More information about the llvm-commits mailing list