This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process
ClosedPublic

Authored by njames93 on Mar 9 2021, 11:18 AM.

Details

Summary

Both the mpi-type-mismatch and mpi-buffer-deref check make use of a static MPIFunctionClassifier object.
This causes issue as the classifier is initialized with the first ASTContext that produces a match.
If the check is enabled on multiple translation units in a single clang-tidy process, this classifier won't be reinitialized for each TU. I'm not an expert in the MPIFunctionClassifier but I'd imagine this is a source of UB.
It is suspected that this bug may result in the crash caused here: https://bugs.llvm.org/show_bug.cgi?id=48985. However even if not the case, this should still be addressed.

Diff Detail

Event Timeline

njames93 created this revision.Mar 9 2021, 11:18 AM
njames93 requested review of this revision.Mar 9 2021, 11:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2021, 11:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2021, 1:25 PM
aaron.ballman accepted this revision.Mar 24 2021, 12:07 PM

LGTM, thanks!

clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
29–30

This is racy, but I don't think we support running multiple checks in parallel, do we?

This revision is now accepted and ready to land.Mar 24 2021, 12:07 PM
njames93 marked an inline comment as done.Mar 24 2021, 12:22 PM
njames93 added inline comments.
clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
29–30

This isn't racy as one instance of a check will only ever run on one thread.

aaron.ballman added inline comments.Mar 24 2021, 12:25 PM
clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
29–30

I was thinking if the check gets run multiple times in parallel on different source files (e.g., someone downstream who incorporates the checks as a library in a creative way rather than runs clang-tidy as a command line tool). But yeah, I'm not worried about it as I don't think we support that sort of thing.

njames93 marked 2 inline comments as done.Mar 24 2021, 12:30 PM
njames93 added inline comments.
clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
29–30

Plenty of other checks hold state that is mutated in the check callback, so if this is a race, all the other checks that mutate state in the callbacks will also have a race.

This revision was automatically updated to reflect the committed changes.
njames93 marked an inline comment as done.