[PATCH] D15450: Avoid double deletion in Clang driver.

Serge Pavlov via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 17 08:14:36 PST 2016


sepavloff added a comment.

In http://reviews.llvm.org/D15450#354606, @yaron.keren wrote:

> It certainly makes sense to redirect the module request to its owner instead of duplicating it in a local copy.


It is not even a duplication, it is simultaneous sharing by two unique_ptr's.

> There may be a change in behaviour here, pre-patch CodeGenAction::EndSourceFileAction() would take the BackendConsumer Module, keeping CodeGen Module intact whereas post-patch it takes the CodeGen Module.

>  How does this work out?


It should not be a problem. CodeGenAction::EndSourceFileAction() is called when code generation is finished, so taking ownership from GodeGen looks safe. Anyway, module must not be owned by two unique_ptr's.

There are at least 3 unique_ptr's that owns the same module object:

- CodeGenAction::TheModule
- BackendConsumer::TheModule
- CodeGeneratorImpl::M

It looks like CodeGenAction::TheModule does not cause any problem, it takes ownership according to usual unique_ptr semantics. But the last two variables owns the same object simultaneously, which violates semantics of unique_ptr. The patch fixes ownership by allowing only CodeGeneratorImpl::M to be an owner.


http://reviews.llvm.org/D15450





More information about the cfe-commits mailing list