summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Leino <aleino@nvidia.com>2025-01-22 17:37:53 +0200
committerGitHub <noreply@github.com>2025-01-22 10:37:53 -0500
commita4d67a0b05d82a1795f77cf1d16c99a8a6143b6e (patch)
treeb13d338aa58caf8ba51510435fca64ffeac9e886
parent151bdb837f514caf5cde873aa39571525ba2e80f (diff)
Catch all exceptions from loadModule* and link API calls. (#6143)
This closes #5950.
-rw-r--r--source/slang/slang.cpp82
1 files changed, 73 insertions, 9 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index efc1c6fd1..6a242d5ce 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -1225,6 +1225,30 @@ SLANG_NO_THROW slang::ITarget* SLANG_MCALL Linkage::getTargetByIndex(SlangInt in
}
#endif
+static void outputExceptionDiagnostic(
+ const AbortCompilationException& exception,
+ DiagnosticSink& sink,
+ slang::IBlob** outDiagnostics)
+{
+ sink.diagnoseRaw(Severity::Error, exception.Message.getUnownedSlice());
+ sink.getBlobIfNeeded(outDiagnostics);
+}
+
+static void outputExceptionDiagnostic(
+ const Exception& exception,
+ DiagnosticSink& sink,
+ slang::IBlob** outDiagnostics)
+{
+ sink.diagnoseRaw(Severity::Internal, exception.Message.getUnownedSlice());
+ sink.getBlobIfNeeded(outDiagnostics);
+}
+
+static void outputExceptionDiagnostic(DiagnosticSink& sink, slang::IBlob** outDiagnostics)
+{
+ sink.diagnoseRaw(Severity::Fatal, "An unknown exception occurred");
+ sink.getBlobIfNeeded(outDiagnostics);
+}
+
SLANG_NO_THROW slang::IModule* SLANG_MCALL
Linkage::loadModule(const char* moduleName, slang::IBlob** outDiagnostics)
{
@@ -1247,9 +1271,19 @@ Linkage::loadModule(const char* moduleName, slang::IBlob** outDiagnostics)
return asExternal(module);
}
- catch (const AbortCompilationException&)
+ catch (const AbortCompilationException& e)
{
- sink.getBlobIfNeeded(outDiagnostics);
+ outputExceptionDiagnostic(e, sink, outDiagnostics);
+ return nullptr;
+ }
+ catch (const Exception& e)
+ {
+ outputExceptionDiagnostic(e, sink, outDiagnostics);
+ return nullptr;
+ }
+ catch (...)
+ {
+ outputExceptionDiagnostic(sink, outDiagnostics);
return nullptr;
}
}
@@ -1310,9 +1344,19 @@ slang::IModule* Linkage::loadModuleFromBlob(
sink.getBlobIfNeeded(outDiagnostics);
return asExternal(module);
}
- catch (const AbortCompilationException&)
+ catch (const AbortCompilationException& e)
{
- sink.getBlobIfNeeded(outDiagnostics);
+ outputExceptionDiagnostic(e, sink, outDiagnostics);
+ return nullptr;
+ }
+ catch (const Exception& e)
+ {
+ outputExceptionDiagnostic(e, sink, outDiagnostics);
+ return nullptr;
+ }
+ catch (...)
+ {
+ outputExceptionDiagnostic(sink, outDiagnostics);
return nullptr;
}
}
@@ -5021,12 +5065,32 @@ ComponentType::link(slang::IComponentType** outLinkedComponentType, ISlangBlob**
//
SLANG_UNUSED(outDiagnostics);
- auto linked = fillRequirements(this);
- if (!linked)
- return SLANG_FAIL;
+ DiagnosticSink sink(getLinkage()->getSourceManager(), Lexer::sourceLocationLexer);
- *outLinkedComponentType = ComPtr<slang::IComponentType>(linked).detach();
- return SLANG_OK;
+ try
+ {
+ auto linked = fillRequirements(this);
+ if (!linked)
+ return SLANG_FAIL;
+
+ *outLinkedComponentType = ComPtr<slang::IComponentType>(linked).detach();
+ return SLANG_OK;
+ }
+ catch (const AbortCompilationException& e)
+ {
+ outputExceptionDiagnostic(e, sink, outDiagnostics);
+ return SLANG_FAIL;
+ }
+ catch (const Exception& e)
+ {
+ outputExceptionDiagnostic(e, sink, outDiagnostics);
+ return SLANG_FAIL;
+ }
+ catch (...)
+ {
+ outputExceptionDiagnostic(sink, outDiagnostics);
+ return SLANG_FAIL;
+ }
}
SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::linkWithOptions(