[PATCH] D25916: Modules: emit an error instead of a random crash (or a misleading error) due to use-after-free.

Manman Ren via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 24 11:31:20 PDT 2016


manmanren created this revision.
manmanren added reviewers: benlangmuir, rsmith.
manmanren added a subscriber: cfe-commits.

With implicit modules, it is hard to debug issues that depend on state of the module cache before the clang invocation. The state of the module cache can be changed by other  parallel clang invocations that share the module cache.

We build a module by spawning a child thread. Even when the parent thread already validated some modules and stored the FileEntries, the child thread can invalidate those modules, causing use-after-free for the parent thread.

Since this issue is time-sensitive, it is hard to reproduce with a release compiler. With an assert or an ASAN'ed compiler the chance of reproducing is even smaller. This patch tries to diagnose the use-after-free in the compiler, by passing up the list of invalidated modules from the child thread and emitting a hard error in the parent thread.

Another option is to pass down the list of validated modules from the parent thread, the child thread can emit a warning and not invalidate those modules.
I am open to other suggestions as well.


https://reviews.llvm.org/D25916

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Serialization/ModuleManager.h
  lib/Frontend/CompilerInstance.cpp
  lib/Serialization/ModuleManager.cpp
  test/Modules/Inputs/system-out-of-date/X.h
  test/Modules/Inputs/system-out-of-date/Y.h
  test/Modules/Inputs/system-out-of-date/Z.h
  test/Modules/Inputs/system-out-of-date/module.map
  test/Modules/system-out-of-date-test.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25916.75616.patch
Type: text/x-patch
Size: 6781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161024/2db03c2e/attachment.bin>


More information about the cfe-commits mailing list