Get LLVMContext instance directly from llvm::Module
when building SVFModule
#1292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The recent commit merged in #1258 modified the interface to build an
SVF::SVFModule
instance from anllvm::Module
object to include astd::unique_ptr<llvm::LLVMContext>
parameter to specify the context used when loading theExtAPI
module. This change introduces a number of issues however, particularly when using SVF from an LLVM pass.Most critically, the use of
std::unique_ptr<>
creates problems when SVF is used from an LLVM pass, as automatic garbage collection on the context is done incorrectly. Creating a unique pointer based on the context of the LLVM module incorrectly means ownership of the context is taken by theLLVMModuleSet
object. This causes issues because the context is obviously not uniquely owned by the module set; when an SVFModule is built from an LLVM module, callingLLVMModuleSet::releaseLLVMModuleSet()
triggers an invalid free/double free and crashes. Wrapping the unconditional deletion on line 110 also does not solve this issue, as the static pointer remains set after the underlying object is garbage collected.This issue occurs using LLVM 15 (debug build with RTTI & exception handling enabled) and running SVF on the module from a module pass in a full LTO pipeline. I did not check if the issue also exists when running a pass separately through
opt
, but it could be possible this issue does not exist in that case (as I saw above issues reported byClang
for the test programs it compiles to check compiler functionality before compiling the actual target).Additionally, the change to explicitly passing an
LLVMContext
breaks backwards compatibility unnecessarily. Since the context used when loading ExtAPI should match the module used to build the SVFModule from, it is unnecessary to require the context be passed through a separate argument when it can be gotten directly from the module.