This is an archive of the discontinued LLVM Phabricator instance.

[clang][deps] Preserve input ordering in the full output
ClosedPublic

Authored by jansvoboda11 on Mar 1 2023, 11:37 AM.

Details

Summary

This patch makes sure the ordering of TUs in the input CDB is preserved in the full output. Previously, the results were pushed into a global vector, potentially out-of-order and then sorted by the input file name. This is
non-deterministic when the CDB contains multiple entries with the same input file. This patch fixes that by pre-allocating the output vector and instead of appending, writes to the index corresponding to the current input. This also
eliminates one critical section.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Mar 1 2023, 11:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 11:37 AM
jansvoboda11 requested review of this revision.Mar 1 2023, 11:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 11:37 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
benlangmuir added inline comments.Mar 1 2023, 11:54 AM
clang/tools/clang-scan-deps/ClangScanDeps.cpp
291–293

Since the input index is coming from "outside": does this operator[] assert if the index is out of range? If not, we should do so here. I would also suggest asserting the value isn't already populated (e.g. assert(ID.FileName.empty())).

790

Since you should never resize FullDeps after you start, how about removing resize and instead:

  • Make FullDeps constructor take the size
  • Change FullDeps FD; to std::optional<FullDeps>
  • Change this line to FullDeps.emplace(Inputs.size())

Add asserts, make FullDeps take NumInputs in the constructor.

jansvoboda11 marked 2 inline comments as done.Mar 1 2023, 12:04 PM
jansvoboda11 added inline comments.
clang/tools/clang-scan-deps/ClangScanDeps.cpp
790

We don't want to resize when we're only scanning by module name, in that case our input is not a translation unit. I implemented your idea and will try to improve how we model the result types in a follow-up.

jansvoboda11 marked an inline comment as done.Mar 1 2023, 12:08 PM
benlangmuir accepted this revision.Mar 1 2023, 12:10 PM
This revision is now accepted and ready to land.Mar 1 2023, 12:10 PM

-fno-integrated-as strikes again. Thanks for reporting this, should be fixed in 3ac8d32.

Thanks for addressing this. Unfortunately the test is still failing after the fix and a clean build

https://lab.llvm.org/buildbot/#/builders/214/builds/6170/steps/6/logs/FAIL__Clang__modules-full-output-tu-order_c