diff --git a/svf-llvm/include/SVF-LLVM/LLVMModule.h b/svf-llvm/include/SVF-LLVM/LLVMModule.h index b34d45340..b8174c16a 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMModule.h +++ b/svf-llvm/include/SVF-LLVM/LLVMModule.h @@ -111,7 +111,8 @@ class LLVMModuleSet llvmModuleSet = nullptr; } - static SVFModule* buildSVFModule(Module& mod); + // The parameter of context should be the llvm context of the mod, the llvm context of mod and extapi module should be the same + static SVFModule* buildSVFModule(Module& mod, std::unique_ptr context); static SVFModule* buildSVFModule(const std::vector& moduleNameVec); inline SVFModule* getSVFModule() @@ -356,7 +357,8 @@ class LLVMModuleSet std::vector getLLVMGlobalFunctions(const GlobalVariable* global); void loadModules(const std::vector& moduleNameVec); - void loadExtAPIModules(); + // The llvm context of app module and extapi module should be the same + void loadExtAPIModules(std::unique_ptr context = nullptr); void addSVFMain(); void createSVFDataStructure(); diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 5e2e6958c..a1870ecb2 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -77,13 +77,14 @@ LLVMModuleSet::LLVMModuleSet() { } -SVFModule* LLVMModuleSet::buildSVFModule(Module &mod) +SVFModule* LLVMModuleSet::buildSVFModule(Module &mod, std::unique_ptr context) { LLVMModuleSet* mset = getLLVMModuleSet(); double startSVFModuleTime = SVFStat::getClk(true); SVFModule::getSVFModule()->setModuleIdentifier(mod.getModuleIdentifier()); mset->modules.emplace_back(mod); + mset->loadExtAPIModules(std::move(context)); mset->build(); double endSVFModuleTime = SVFStat::getClk(true); @@ -528,7 +529,7 @@ void LLVMModuleSet::loadModules(const std::vector &moduleNameVec) } } -void LLVMModuleSet::loadExtAPIModules() +void LLVMModuleSet::loadExtAPIModules(std::unique_ptr context) { // Load external API module (extapi.bc) if (!ExtAPI::getExtAPI()->getExtBcPath().empty()) @@ -540,6 +541,9 @@ void LLVMModuleSet::loadExtAPIModules() abort(); } SMDiagnostic Err; + assert(!(cxts == nullptr && context == nullptr) && "Before loading extapi module, at least one LLVMContext should be initialized !!!"); + if (context != nullptr) + cxts = std::move(context); std::unique_ptr mod = parseIRFile(extModuleName, Err, *cxts); if (mod == nullptr) {