[PATCH] D105328: [Frontend] Only compile modules if not already finalized

Ben Barham via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 1 18:46:47 PDT 2021


bnbarham created this revision.
bnbarham added reviewers: akyrtzi, arphaman.
Herald added a subscriber: mgorny.
bnbarham requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It was possible to re-add a module to a shared in-memory module cache
when search paths are changed.  This can eventually cause a crash if the
original module is referenced after this occurs.

1. Module A depends on B
2. B exists in two paths C and D
3. First run only has C on the search path, finds A and B and loads them
4. Second run adds D to the front of the search path. A is loaded and contains a reference to the already compiled module from C. But searching finds the module from D instead, causing a mismatch
5. B is considered out of date and is now rebuilt
6. The recompiled module is added to the in-memory cache, freeing the previously inserted one

This can never occur from a regular clang process, but is very easy to
do through the API. Update the compilation to return early if a module
is already finalized so that the pre-condition in the in-memory module
cache holds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105328

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/unittests/Serialization/CMakeLists.txt
  clang/unittests/Serialization/ModuleCacheTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105328.356074.patch
Type: text/x-patch
Size: 12424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210702/9df3d4db/attachment.bin>


More information about the cfe-commits mailing list