llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

"DICompileUnit not listed in llvm.dbg.cu" verifier error after recent regression

Open dstenb opened this issue 4 years ago • 6 comments

Commit: 958abe864ab777302d1e7aee7b6c5ea4b0fe9be6

Command:

opt -S -strip-debug -disable-debug-info-type-map < foo.ll
DICompileUnit not listed in llvm.dbg.cu
!18 = distinct !DICompileUnit(language: DW_LANG_C99, file: !15, producer: "clang version 16.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
/repo/edasten/llvm-main/llvm/build-all/bin/opt: -: error: input module is broken!

foo.ll.gz

dstenb avatar Sep 05 '22 09:09 dstenb

This seems to be a regression caused by:

f5a68feab30a Use llvm::none_of (NFC)

due to this change:

   // MDNode. This loop also initializes DILocationReachable, later
   // needed by updateLoopMetadataDebugLocationsImpl; the use of
   // count_if avoids an early exit.
-  if (!std::count_if(N->op_begin() + 1, N->op_end(),
-                     [&Visited, &DILocationReachable](const MDOperand &Op) {
-                       return isDILocationReachable(
-                                  Visited, DILocationReachable, Op.get());
-                     }))
+  if (llvm::none_of(llvm::drop_begin(N->operands()),
+                    [&Visited, &DILocationReachable](const MDOperand &Op) {
+                      return isDILocationReachable(Visited, DILocationReachable,
+                                                   Op.get());
+                    }))
     return N;

llvm::none_of uses std::none_of, which breaks at the first match of the predicate:

https://en.cppreference.com/w/cpp/algorithm/all_any_none_of

template< class InputIt, class UnaryPredicate >
bool none_of( InputIt first, InputIt last, UnaryPredicate p ); (5)
  1. Checks if unary predicate p returns true for no elements in the range [first, last).

Complexity 1,3,5) At most last - first applications of the predicate

Not all items are initialized in this case, leading to the contract indicated by the comment in that code snippet being broken, which seems to be the problem here.

dstenb avatar Sep 05 '22 09:09 dstenb

I accidentally closed it, so reopening.

dstenb avatar Sep 05 '22 09:09 dstenb

Thank you for reporting the issue. Fixed with a partial revert:

5a68d6721d042d57d1b2fef5d1b2e40a1260c169

kazutakahirata avatar Sep 05 '22 21:09 kazutakahirata

Thanks for fixing this, @kazutakahirata! However, I think it would be good to add a lit regression test also. The original reproducer has a RUN line and is reduced, so I guess it is almost there.

dstenb avatar Sep 06 '22 08:09 dstenb

Probably worth adding a comment to the code about the fact that the isDILocationReachable is side effecting/required? (if I'm understanding the description in this issue correctly, that is) - oh, I see there is a comment already there... fair enough. (maybe renaming the isDILocationReachable function so it's clear it has side effects would be good)

& CCing whoever wrote this code so they're aware it's a bit of a timebomb?

dwblaikie avatar Sep 08 '22 15:09 dwblaikie

David, thank you for the test case. Posted a patch: https://reviews.llvm.org/D133651

kazutakahirata avatar Sep 10 '22 21:09 kazutakahirata