[all-commits] [llvm/llvm-project] 766a08: [Frontend] Only compile modules if not already fin...

Ben Barham via All-commits all-commits at lists.llvm.org
Thu Jul 15 18:28:10 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 766a08df12c111b15ed51d0fcac06042d2f68cd6
      https://github.com/llvm/llvm-project/commit/766a08df12c111b15ed51d0fcac06042d2f68cd6
  Author: Ben Barham <ben_barham at apple.com>
  Date:   2021-07-15 (Thu, 15 Jul 2021)

  Changed paths:
    M clang/include/clang/Basic/DiagnosticCommonKinds.td
    M clang/include/clang/Basic/DiagnosticSerializationKinds.td
    M clang/include/clang/Serialization/ASTReader.h
    M clang/lib/Frontend/CompilerInstance.cpp
    M clang/lib/Serialization/ASTReader.cpp
    M clang/unittests/Serialization/CMakeLists.txt
    A clang/unittests/Serialization/ModuleCacheTest.cpp

  Log Message:
  -----------
  [Frontend] Only compile modules if not already finalized

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 and the modules that depend on it are considered out of date and
     thus rebuilt
  6. The recompiled module A 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 - whether through the use of a shared case or just
running multiple compilations from a single `CompilerInstance`. Update
the compilation to return early if a module is already finalized so that
the pre-condition in the in-memory module cache holds.

Resolves rdar://78180255

Differential Revision: https://reviews.llvm.org/D105328




More information about the All-commits mailing list