From d8e452412e14a6a8ba137f2adcae13b398e5cecb Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 28 Sep 2021 15:03:03 -0700 Subject: Fix AbortCompilationException leaking through loadModule API. (#1949) * Fix AbortCompilationException leaking through loadModule API. * Update. * Fix. Co-authored-by: Yong He --- source/slang/slang.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index b79d97331..1362cb038 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -822,13 +822,21 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModule( const char* moduleName, slang::IBlob** outDiagnostics) { - auto name = getNamePool()->getName(moduleName); + try + { + auto name = getNamePool()->getName(moduleName); - DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer); - auto module = findOrImportModule(name, SourceLoc(), &sink); - sink.getBlobIfNeeded(outDiagnostics); + DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer); + auto module = findOrImportModule(name, SourceLoc(), &sink); + sink.getBlobIfNeeded(outDiagnostics); + + return asExternal(module); - return asExternal(module); + } + catch (const AbortCompilationException&) + { + return nullptr; + } } SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompositeComponentType( @@ -2454,7 +2462,7 @@ void Linkage::_diagnoseErrorInImportedModule( { for(auto info = m_modulesBeingImported; info; info = info->next) { - sink->diagnose(info->importLoc, Diagnostics::errorInImportedModule, info->name); + sink->diagnose(info->importLoc, Diagnostics::errorInImportedModule, info->name); } sink->diagnose(SourceLoc(), Diagnostics::complationCeased); } -- cgit v1.2.3