diff options
| author | Yong He <yonghe@outlook.com> | 2024-06-12 09:40:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-12 09:40:27 -0700 |
| commit | c194af81a5b1f7d2869d9617dc06cd50609362bf (patch) | |
| tree | 01018eed11a9cccb1176f70a085b948b825d07bc | |
| parent | 7a4757d2e97f92aae3ddb5dc353a54f72e23351e (diff) | |
Fix crash on invalid entrypoint varying parameter. (#4349)
* Fix crash on invalid entrypoint varying parameter.
* Fix test.
| -rw-r--r-- | source/slang/slang-diagnostic-defs.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 9 | ||||
| -rw-r--r-- | tests/bugs/invalid-entrypoint-param.slang | 17 |
3 files changed, 26 insertions, 2 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index eb7b5b993..f4bad6664 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -695,6 +695,8 @@ DIAGNOSTIC(39026, Error, matrixLayoutModifierOnNonMatrixType, "matrix layout mod DIAGNOSTIC(39027, Error, getAttributeAtVertexMustReferToPerVertexInput, "'GetAttributeAtVertex' must reference a vertex input directly, and the vertex input must be decorated with 'pervertex' or 'nointerpolation'.") +DIAGNOSTIC(39028, Error, notValidVaryingParameter, "parameter '$0' is not a valid varying parameter.") + // // 4xxxx - IL code generation. diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index 523ba9287..bce9b5d05 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -2185,9 +2185,11 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameter( state, fieldVarLayout); - SLANG_ASSERT(fieldTypeLayout); - if(!fieldTypeLayout) + if (!fieldTypeLayout) + { + getSink(context)->diagnose(field, Diagnostics::notValidVaryingParameter, field); continue; + } fieldVarLayout->typeLayout = fieldTypeLayout; // The field needs to have offset information stored @@ -4169,6 +4171,9 @@ ProgramLayout* TargetProgram::getOrCreateLayout(DiagnosticSink* sink) if( !m_layout ) { m_layout = generateParameterBindings(this, sink); + if (sink->getErrorCount() != 0) + return nullptr; + if( m_layout ) { m_irModuleForLayout = createIRModuleForLayout(sink); diff --git a/tests/bugs/invalid-entrypoint-param.slang b/tests/bugs/invalid-entrypoint-param.slang new file mode 100644 index 000000000..bafb0fb88 --- /dev/null +++ b/tests/bugs/invalid-entrypoint-param.slang @@ -0,0 +1,17 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// `TT` is not valid for defining a varying entrypoint parameter, +// and we should diagnose an error. + +// CHECK: error 39028 + +struct TT +{ + Texture2D tex; +} + +[numthreads(1, 1, 1)] +void f(TT t) +{ + return; +}
\ No newline at end of file |
