Repository: shader-slang/slang (2026-03-25T19:43:08Z)

Issue:
Crash in `Slang::UTF8Util::calcCodePointCount(const Slang::UnownedStringSlice &)`
# Issue Description

We have observed spurious crashes in slang-rhi tests for some time now. The test that crashes in slang is `texture-view-load-ro-single.d3d12`. It's worth mentioning that this test compiles a lot of shaders.

Full stack trace:
```
[Inline Frame] slang-compiler.dll!Slang::UTF8Util::calcCodePointCount(const Slang::UnownedStringSlice &) Line 199 (d:\a\slang\slang\source\core\slang-char-encode.cpp:199)
slang-compiler.dll!Slang::SourceFile::calcColumnIndex(int lineIndex, int offset, int) Line 595 (d:\a\slang\slang\source\compiler-core\slang-source-loc.cpp:595)
slang-compiler.dll!Slang::SourceView::getHandleLoc(Slang::SourceLoc loc, Slang::SourceLocType type) Line 388 (d:\a\slang\slang\source\compiler-core\slang-source-loc.cpp:388)
slang-compiler.dll!Slang::SourceView::getHumaneLoc(Slang::SourceLoc loc, Slang::SourceLocType type) Line 411 (d:\a\slang\slang\source\compiler-core\slang-source-loc.cpp:411)
[Inline Frame] slang-compiler.dll!Slang::SourceManager::getHumaneLoc(Slang::SourceLoc) Line 1013 (d:\a\slang\slang\source\compiler-core\slang-source-loc.cpp:1013)
slang-compiler.dll!Slang::SourceWriter::advanceToSourceLocation(const Slang::SourceLoc & sourceLocation) Line 344 (d:\a\slang\slang\source\slang\slang-emit-source-writer.cpp:344)
slang-compiler.dll!Slang::CLikeSourceEmitter::emitGlobalInstImpl(Slang::IRInst * inst) Line 5057 (d:\a\slang\slang\source\slang\slang-emit-c-like.cpp:5057)
[Inline Frame] slang-compiler.dll!Slang::CLikeSourceEmitter::emitGlobalInst(Slang::IRInst *) Line 5021 (d:\a\slang\slang\source\slang\slang-emit-c-like.cpp:5021)
slang-compiler.dll!Slang::CLikeSourceEmitter::executeEmitActions(const Slang::List<Slang::CLikeSourceEmitter::EmitAction,Slang::StandardAllocator> & actions) Line 5415 (d:\a\slang\slang\source\slang\slang-emit-c-like.cpp:5415)
slang-compiler.dll!Slang::CLikeSourceEmitter::emitModuleImpl(Slang::IRModule * module, Slang::DiagnosticSink * sink) Line 5434 (d:\a\slang\slang\source\slang\slang-emit-c-like.cpp:5434)
[Inline Frame] slang-compiler.dll!Slang::CLikeSourceEmitter::emitModule(Slang::IRModule *) Line 515 (d:\a\slang\slang\source\slang\slang-emit-c-like.h:515)
slang-compiler.dll!Slang::CodeGenContext::emitEntryPointsSourceFromIR(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 2239 (d:\a\slang\slang\source\slang\slang-emit.cpp:2239)
slang-compiler.dll!Slang::CodeGenContext::emitEntryPointsSource(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 166 (d:\a\slang\slang\source\slang\slang-code-gen.cpp:166)
slang-compiler.dll!Slang::CodeGenContext::emitWithDownstreamForEntryPoints(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 531 (d:\a\slang\slang\source\slang\slang-code-gen.cpp:531)
slang-compiler.dll!Slang::CodeGenContext::_emitEntryPoints(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 1151 (d:\a\slang\slang\source\slang\slang-code-gen.cpp:1151)
slang-compiler.dll!Slang::CodeGenContext::emitEntryPoints(Slang::ComPtr<Slang::IArtifact> & outArtifact) Line 1231 (d:\a\slang\slang\source\slang\slang-code-gen.cpp:1231)
slang-compiler.dll!Slang::TargetProgram::_createEntryPointResult(__int64 entryPointIndex, Slang::DiagnosticSink * sink, Slang::EndToEndCompileRequest * endToEndReq) Line 72 (d:\a\slang\slang\source\slang\slang-target-program.cpp:72)
slang-compiler.dll!Slang::TargetProgram::getOrCreateEntryPointResult(__int64 entryPointIndex, Slang::DiagnosticSink * sink) Line 117 (d:\a\slang\slang\source\slang\slang-target-program.cpp:117)
slang-compiler.dll!Slang::ComponentType::getEntryPointCode(__int64 entryPointIndex, __int64 targetIndex, ISlangBlob * * outCode, ISlangBlob * * outDiagnostics) Line 258 (d:\a\slang\slang\source\slang\slang-linkable.cpp:258)
slang-rhi-tests.exe!rhi::Device::getEntryPointCodeFromShaderCache(rhi::ShaderProgram * program, slang::IComponentType * componentType, const char * entryPointName, unsigned int entryPointIndex, unsigned int targetIndex, ISlangBlob * * outCode, ISlangBlob * * outDiagnostics) Line 413 (c:\src\slang-rhi\src\device.cpp:413)
slang-rhi-tests.exe!rhi::ShaderProgram::compileShaders::__l2::<lambda_1>::operator()(slang::EntryPointReflection * entryPointInfo, slang::IComponentType * entryPointComponent, unsigned int entryPointIndex) Line 123 (c:\src\slang-rhi\src\shader.cpp:123)
slang-rhi-tests.exe!rhi::ShaderProgram::compileShaders(rhi::Device * device) Line 151 (c:\src\slang-rhi\src\shader.cpp:151)
slang-rhi-tests.exe!rhi::Device::createComputePipeline(const rhi::ComputePipelineDesc & desc, rhi::IComputePipeline * * outPipeline) Line 716 (c:\src\slang-rhi\src\device.cpp:716)
slang-rhi-tests.exe!rhi::debug::DebugDevice::createComputePipeline(const rhi::ComputePipelineDesc & desc, rhi::IComputePipeline * * outPipeline) Line 1046 (c:\src\slang-rhi\src\debug-layer\debug-device.cpp:1046)
slang-rhi-tests.exe!TextureViewTest::getReadPipeline(TextureViewType textureViewType, rhi::TextureType textureType, rhi::Format format, ReadMethod readMethod) Line 753 (c:\src\slang-rhi\tests\test-texture-view.cpp:753)
slang-rhi-tests.exe!TextureViewTest::readTexelsDevice(TextureViewType textureViewType, rhi::ITextureView * textureView, std::span<TexelData,-1> texels, ReadMethod readMethod) Line 767 (c:\src\slang-rhi\tests\test-texture-view.cpp:767)
slang-rhi-tests.exe!GPU_TEST_ANONYMOUS_47::__l2::<lambda_1>::operator()(rhi::testing::TextureTestContext * c) Line 1191 (c:\src\slang-rhi\tests\test-texture-view.cpp:1191)
slang-rhi-tests.exe!rhi::testing::runTextureTest::__l2::<lambda_1>::operator()(const rhi::testing::TextureTestVariant & variant) Line 562 (c:\src\slang-rhi\tests\texture-test.h:562)
slang-rhi-tests.exe!std::invoke<`rhi::testing::runTextureTest<`GPU_TEST_ANONYMOUS_47'::`2'::<lambda_1>>'::`2'::<lambda_1> &,rhi::testing::TextureTestVariant const &>(rhi::testing::runTextureTest::__l2::<lambda_1> & _Obj, const rhi::testing::TextureTestVariant & _Arg1) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::runTextureTest<`GPU_TEST_ANONYMOUS_47'::`2'::<lambda_1>>'::`2'::<lambda_1>,void,rhi::testing::TextureTestVariant const &>::_Do_call(const rhi::testing::TextureTestVariant & <_Args_0>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,rhi::testing::TextureTestVariant const &>::operator()(const rhi::testing::TextureTestVariant & <_Args_0>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 768 (c:\src\slang-rhi\tests\texture-test.cpp:768)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::applyTextureSize(int state, rhi::testing::TextureTestVariant variant) Line 1292 (c:\src\slang-rhi\tests\texture-test.cpp:1292)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::addVariants::__l2::<lambda_3>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 393 (c:\src\slang-rhi\tests\texture-test.h:393)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::addVariants<enum rhi::testing::TTShape,enum rhi::testing::TTArray,enum rhi::testing::TTMip,enum rhi::testing::TTMS,enum rhi::testing::TTPowerOf2,enum rhi::testing::TTFmtCompressed,enum rhi::testing::TTFmtDepth,enum rhi::TextureUsage>'::`2'::<lambda_3> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::addVariants::__l2::<lambda_3> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::addVariants<enum rhi::testing::TTShape,enum rhi::testing::TTArray,enum rhi::testing::TTMip,enum rhi::testing::TTMS,enum rhi::testing::TTPowerOf2,enum rhi::testing::TTFmtCompressed,enum rhi::testing::TTFmtDepth,enum rhi::TextureUsage>'::`2'::<lambda_3>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::filterFormat(int state, rhi::testing::TextureTestVariant variant) Line 1239 (c:\src\slang-rhi\tests\texture-test.cpp:1239)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::addVariants::__l2::<lambda_2>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 385 (c:\src\slang-rhi\tests\texture-test.h:385)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::addVariants<enum rhi::testing::TTShape,enum rhi::testing::TTArray,enum rhi::testing::TTMip,enum rhi::testing::TTMS,enum rhi::testing::TTPowerOf2,enum rhi::testing::TTFmtCompressed,enum rhi::testing::TTFmtDepth,enum rhi::TextureUsage>'::`2'::<lambda_2> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::addVariants::__l2::<lambda_2> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::addVariants<enum rhi::testing::TTShape,enum rhi::testing::TTArray,enum rhi::testing::TTMip,enum rhi::testing::TTMS,enum rhi::testing::TTPowerOf2,enum rhi::testing::TTFmtCompressed,enum rhi::testing::TTFmtDepth,enum rhi::TextureUsage>'::`2'::<lambda_2>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::postProcessVariant(int state, rhi::testing::TextureTestVariant variant) Line 1176 (c:\src\slang-rhi\tests\texture-test.cpp:1176)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::addVariants::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 377 (c:\src\slang-rhi\tests\texture-test.h:377)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::addVariants<enum rhi::testing::TTShape,enum rhi::testing::TTArray,enum rhi::testing::TTMip,enum rhi::testing::TTMS,enum rhi::testing::TTPowerOf2,enum rhi::testing::TTFmtCompressed,enum rhi::testing::TTFmtDepth,enum rhi::TextureUsage>'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::addVariants::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::addVariants<enum rhi::testing::TTShape,enum rhi::testing::TTArray,enum rhi::testing::TTMip,enum rhi::testing::TTMS,enum rhi::testing::TTPowerOf2,enum rhi::testing::TTFmtCompressed,enum rhi::testing::TTFmtDepth,enum rhi::TextureUsage>'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 1030 (c:\src\slang-rhi\tests\texture-test.cpp:1030)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 985 (c:\src\slang-rhi\tests\texture-test.cpp:985)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 1007 (c:\src\slang-rhi\tests\texture-test.cpp:1007)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 1018 (c:\src\slang-rhi\tests\texture-test.cpp:1018)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 940 (c:\src\slang-rhi\tests\texture-test.cpp:940)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 898 (c:\src\slang-rhi\tests\texture-test.cpp:898)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 919 (c:\src\slang-rhi\tests\texture-test.cpp:919)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1>::operator()(int state, rhi::testing::TextureTestVariant variant) Line 844 (c:\src\slang-rhi\tests\texture-test.cpp:844)
slang-rhi-tests.exe!std::invoke<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1> &,int,rhi::testing::TextureTestVariant>(rhi::testing::TextureTestOptions::processVariantArg::__l2::<lambda_1> & _Obj, int && _Arg1, rhi::testing::TextureTestVariant && <_Args2_0>) Line 1680 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\type_traits:1680)
slang-rhi-tests.exe!std::_Func_impl_no_alloc<`rhi::testing::TextureTestOptions::processVariantArg'::`2'::<lambda_1>,void,int,rhi::testing::TextureTestVariant>::_Do_call(int && <_Args_0>, rhi::testing::TextureTestVariant && <_Args_1>) Line 880 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:880)
slang-rhi-tests.exe!std::_Func_class<void,int,rhi::testing::TextureTestVariant>::operator()(int <_Args_0>, rhi::testing::TextureTestVariant <_Args_1>) Line 926 (c:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\functional:926)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::next(int nextIndex, rhi::testing::TextureTestVariant variant) Line 760 (c:\src\slang-rhi\tests\texture-test.cpp:760)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::executeGeneratorList(int listIdx) Line 751 (c:\src\slang-rhi\tests\texture-test.cpp:751)
slang-rhi-tests.exe!rhi::testing::TextureTestOptions::run(std::function<void __cdecl(rhi::testing::TextureTestVariant const &)> func) Line 727 (c:\src\slang-rhi\tests\texture-test.cpp:727)
slang-rhi-tests.exe!rhi::testing::runTextureTest<`GPU_TEST_ANONYMOUS_47'::`2'::<lambda_1>>(rhi::testing::TextureTestOptions & options, GPU_TEST_ANONYMOUS_47::__l2::<lambda_1> && func) Line 542 (c:\src\slang-rhi\tests\texture-test.h:542)
slang-rhi-tests.exe!GPU_TEST_ANONYMOUS_47(rhi::testing::GpuTestContext * ctx, Slang::ComPtr<rhi::IDevice> device) Line 1150 (c:\src\slang-rhi\tests\test-texture-view.cpp:1150)
slang-rhi-tests.exe!rhi::testing::gpuTestTrampoline() Line 1006 (c:\src\slang-rhi\tests\testing.cpp:1006)
slang-rhi-tests.exe!doctest::Context::run() Line 7007 (c:\src\slang-rhi\external\doctest\doctest.h:7007)
slang-rhi-tests.exe!main(int argc, const char * * argv) Line 98 (c:\src\slang-rhi\tests\main.cpp:98)
slang-rhi-tests.exe!invoke_main() Line 79 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79)
slang-rhi-tests.exe!__scrt_common_main_seh() Line 288 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
slang-rhi-tests.exe!__scrt_common_main() Line 331 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
slang-rhi-tests.exe!mainCRTStartup(void * __formal) Line 17 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17)
kernel32.dll!00007ffbe62ce8d7() (Unknown Source:0)
ntdll.dll!00007ffbe743c34c() (Unknown Source:0)
```

# Reproducer Code
I can reproduce this crash locally by running `slang-rhi-tests.exe -tc=*.d3d12 -verbose`. It doesn't always crash, but happens from time to time. It seems important to run the full test suite (i.e. `*.d3d12`) and not just the crashing test case.

# Expected Behavior
No crash.

# Actual Behavior
Crash.

# Environment
 - Slang Version 2026.4.1 (but happened on previous releases as well)
 - Windows



Discussion:
I was able to reproduce this with latest slang master in a RelWithDebInfo build. I wasn't able to reproduce it with a Debug build.
The crash happens here:
```c++
/* static */ Index UTF8Util::calcCodePointCount(const UnownedStringSlice& in)
{
    Index count = 0;

    // Analyse with bytes...
    const int8_t* cur = (const int8_t*)in.begin();
    const int8_t* const end = (const int8_t*)in.end();

    while (cur < end)
    {
        const auto c = *cur++; /// <<< CRASH because cur points to invalid memory
```

two stack frames up we are here:

```c++
HandleSourceLoc SourceView::getHandleLoc(SourceLoc loc, SourceLocType type)
{
    {
        HandleSourceLoc handleLoc;
        if (SLANG_SUCCEEDED(_findSourceMapLoc(loc, type, handleLoc)))
        {
            return handleLoc;
        }
    }

    // Get the offset in bytes for this loc
    const int offset = m_range.getOffset(loc);

    // We need the line index from the original source file
    const int lineIndex = m_sourceFile->calcLineIndexFromOffset(offset);

    // TODO:
    // - Tab characters, which should really adjust how we report
    //   columns (although how are we supposed to know the setting
    //   that an IDE expects us to use when reporting locations?)
    //
    //   For now we just count tabs as single chars
    const int columnIndex = m_sourceFile->calcColumnIndex(lineIndex, offset);
```

and `m_sourceFile->m_content` contains invalid data

Maybe this helps tracking this bug down.


@NV-xiaoyongs Can you take a look at this one?
FYI @jkiviluoto-nv (stability)



Patch:
diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp
index 307928d42ad..e976d7f1c99 100644
--- a/source/compiler-core/slang-source-loc.cpp
+++ b/source/compiler-core/slang-source-loc.cpp
@@ -650,6 +650,11 @@ void SourceFile::setContents(ISlangBlob* blob)
     char const* decodedContentEnd = decodedContentBegin + decodedContentSize;
 
     m_content = UnownedStringSlice(decodedContentBegin, decodedContentEnd);
+
+    // Update m_contentSize to the decoded size so that getContentSize() always reflects the
+    // actual content length. For UTF-8 without BOM this is a no-op; for BOM or non-UTF-8 files,
+    // the decoded size may differ from the raw file size.
+    m_contentSize = decodedContentSize;
 }
 
 void SourceFile::setContents(const String& content)
diff --git a/source/compiler-core/slang-source-loc.h b/source/compiler-core/slang-source-loc.h
index b52f2e50dfb..d27d880b65f 100644
--- a/source/compiler-core/slang-source-loc.h
+++ b/source/compiler-core/slang-source-loc.h
@@ -352,7 +352,8 @@ class SourceFile
     ComPtr<ISlangBlob> m_contentBlob; ///< A blob that owns the storage for the file contents. If
                                       ///< nullptr, there is no contents
     UnownedStringSlice m_content;     ///< The actual contents of the file.
-    size_t m_contentSize;             ///< The size of the actual contents
+    size_t m_contentSize; ///< Initially set to the raw blob size; updated by setContents() to
+                          ///< the decoded content size after BOM/encoding processing.
 
     SHA1::Digest m_digest;
 


Test patch:
diff --git a/tools/slang-unit-test/unit-test-source-file-bom.cpp b/tools/slang-unit-test/unit-test-source-file-bom.cpp
new file mode 100644
index 00000000000..0ba32da75d4
--- /dev/null
+++ b/tools/slang-unit-test/unit-test-source-file-bom.cpp
@@ -0,0 +1,78 @@
+
+#include "../../source/compiler-core/slang-source-loc.h"
+#include "../../source/core/slang-blob.h"
+#include "unit-test/slang-unit-test.h"
+
+using namespace Slang;
+
+// Regression test for https://github.com/shader-slang/slang/issues/10616
+//
+// When a source file has a BOM or non-UTF-8 encoding, setContents() decodes/strips the
+// BOM, producing a decoded buffer smaller than the raw file. Previously m_contentSize was
+// not updated to the decoded size, causing getOffsetRangeAtLineIndex() to return
+// out-of-bounds ranges for the last line, which led to crashes in calcCodePointCount().
+
+static void _checkSourceFileBom(
+    SourceManager& sourceManager,
+    const void* rawData,
+    size_t rawSize,
+    size_t bomSize)
+{
+    auto blob = RawBlob::create(rawData, rawSize);
+    SourceFile* sf = sourceManager.createSourceFileWithBlob(PathInfo::makeUnknown(), blob);
+
+    // After setContents, getContentSize() must equal the actual decoded content length.
+    SLANG_CHECK(sf->getContentSize() == size_t(sf->getContent().getLength()));
+
+    // The decoded content must be smaller than the raw input by at least the BOM size.
+    SLANG_CHECK(sf->getContentSize() < rawSize);
+    SLANG_CHECK(rawSize - sf->getContentSize() >= bomSize);
+
+    // Exercise the crash path: calcColumnIndex on the last line calls
+    // getLineAtIndex -> getOffsetRangeAtLineIndex (uses getContentSize())
+    // -> head(colOffset) -> calcCodePointCount. With the stale m_contentSize
+    // this would read out of bounds.
+    int lastCharOffset = int(sf->getContent().getLength()) - 2;
+    int lineIndex = sf->calcLineIndexFromOffset(lastCharOffset);
+    int col = sf->calcColumnIndex(lineIndex, lastCharOffset);
+    SLANG_CHECK(col >= 0);
+}
+
+SLANG_UNIT_TEST(sourceFileBomContentSize)
+{
+    SLANG_UNUSED(unitTestContext);
+
+    SourceManager sourceManager;
+    sourceManager.initialize(nullptr, nullptr);
+
+    // Test 1: UTF-8 BOM (3 bytes: EF BB BF)
+    {
+        const char raw[] = "\xEF\xBB\xBF"
+                           "int x = 42;\nfloat y = 1.0;\n";
+        _checkSourceFileBom(sourceManager, raw, sizeof(raw) - 1, 3);
+    }
+
+    // Test 2: UTF-16 LE BOM (2 bytes: FF FE) followed by UTF-16 LE encoded text.
+    // "int a;\n" in UTF-16 LE is each ASCII char as (char, 0x00) pairs.
+    {
+        const Byte raw[] = {
+            0xFF,
+            0xFE, // UTF-16 LE BOM
+            'i',
+            0x00,
+            'n',
+            0x00,
+            't',
+            0x00, // "int"
+            ' ',
+            0x00,
+            'a',
+            0x00,
+            ';',
+            0x00, // " a;"
+            '\n',
+            0x00, // newline
+        };
+        _checkSourceFileBom(sourceManager, raw, sizeof(raw), 2);
+    }
+}