diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-10 03:49:38 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 19:49:38 +0800 |
| commit | 89bf795f105ebe2703ee74a021e16786990ca7b2 (patch) | |
| tree | 59f9900680f40c6bd91a4511cdab032840c98336 | |
| parent | b0dfb1aef2cd5483f59b858c8921707174ffdf2d (diff) | |
Fix a crash when search for files. (#5818)
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
| -rw-r--r-- | source/core/slang-string-util.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 2 | ||||
| -rw-r--r-- | tests/language-feature/modules/gh-5799/Common/Common.slang | 3 | ||||
| -rw-r--r-- | tests/language-feature/modules/gh-5799/Common/Test.slang | 8 | ||||
| -rw-r--r-- | tests/language-feature/modules/gh-5799/HelloTriangleFS.slang | 37 | ||||
| -rw-r--r-- | tests/language-feature/modules/gh-5799/Scene/Scene.slang | 3 | ||||
| -rw-r--r-- | tests/language-feature/modules/gh-5799/Simple.h | 0 | ||||
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 13 |
8 files changed, 66 insertions, 2 deletions
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp index 6f1dc2ccb..ba234e30b 100644 --- a/source/core/slang-string-util.cpp +++ b/source/core/slang-string-util.cpp @@ -461,7 +461,7 @@ String StringUtil::replaceAll( StringBuilder builder; for (Index i = 0; i < text.getLength();) { - if (i + subStr.getLength() >= text.getLength()) + if (i + subStr.getLength() > text.getLength()) { builder.append(text.subString(i, text.getLength() - i)); break; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index e4de61276..9e9b5fbe3 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -4257,7 +4257,7 @@ SourceFile* Linkage::findFile(Name* name, SourceLoc loc, IncludeSystem& outInclu // Next, try to find the file of the given name, // using our ordinary include-handling logic. - auto searchDirs = getSearchDirectories(); + auto& searchDirs = getSearchDirectories(); outIncludeSystem = IncludeSystem(&searchDirs, getFileSystemExt(), getSourceManager()); // Get the original path info diff --git a/tests/language-feature/modules/gh-5799/Common/Common.slang b/tests/language-feature/modules/gh-5799/Common/Common.slang new file mode 100644 index 000000000..d60907cb6 --- /dev/null +++ b/tests/language-feature/modules/gh-5799/Common/Common.slang @@ -0,0 +1,3 @@ +module Common; + +__include Common.Test; diff --git a/tests/language-feature/modules/gh-5799/Common/Test.slang b/tests/language-feature/modules/gh-5799/Common/Test.slang new file mode 100644 index 000000000..231519ae7 --- /dev/null +++ b/tests/language-feature/modules/gh-5799/Common/Test.slang @@ -0,0 +1,8 @@ +//#pragma once +#include "Simple.h" +// +//#ifndef HOST_CODE +//implementing Common; +//#endif +implementing Common; + diff --git a/tests/language-feature/modules/gh-5799/HelloTriangleFS.slang b/tests/language-feature/modules/gh-5799/HelloTriangleFS.slang new file mode 100644 index 000000000..2d47b5b2b --- /dev/null +++ b/tests/language-feature/modules/gh-5799/HelloTriangleFS.slang @@ -0,0 +1,37 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -I $dirname + +//CHECK: OpEntryPoint + +// shaders.slang + +// +// This file provides a simple vertex and fragment shader that can be compiled +// using Slang. This code should also be valid as HLSL, and thus it does not +// use any of the new language features supported by Slang. +// + +import Scene.Scene; + +// Output of the vertex shader, and input to the fragment shader. +struct CoarseVertex +{ + float3 color; +}; + +// Output of the fragment shader +struct Fragment +{ + float4 color; +}; + + +// Fragment Shader + +[shader("fragment")] +float4 main( + CoarseVertex coarseVertex : CoarseVertex) : SV_Target +{ + float3 fragColor = coarseVertex.color; + + return float4(fragColor, 1.0); +} diff --git a/tests/language-feature/modules/gh-5799/Scene/Scene.slang b/tests/language-feature/modules/gh-5799/Scene/Scene.slang new file mode 100644 index 000000000..9551c9f08 --- /dev/null +++ b/tests/language-feature/modules/gh-5799/Scene/Scene.slang @@ -0,0 +1,3 @@ +module Scene; +import Common.Common; + diff --git a/tests/language-feature/modules/gh-5799/Simple.h b/tests/language-feature/modules/gh-5799/Simple.h new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/language-feature/modules/gh-5799/Simple.h diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index ae6eb6216..376d0e0bd 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -524,6 +524,17 @@ static SlangResult _extractCommand(const char** ioCursor, UnownedStringSlice& ou } } +static void applyMacroSubstitution(String filePath, TestDetails& details) +{ + for (auto& arg : details.options.args) + { + arg = StringUtil::replaceAll( + arg.getUnownedSlice(), + toSlice("$dirname"), + Path::getParentDirectory(filePath).getUnownedSlice()); + } +} + // Try to read command-line options from the test file itself static SlangResult _gatherTestsForFile( TestCategorySet* categorySet, @@ -597,6 +608,7 @@ static SlangResult _gatherTestsForFile( if (command == "TEST") { SLANG_RETURN_ON_FAIL(_gatherTestOptions(categorySet, &cursor, testDetails.options)); + applyMacroSubstitution(filePath, testDetails); // See if the type of test needs certain APIs available const RenderApiFlags testRequiredApis = @@ -611,6 +623,7 @@ static SlangResult _gatherTestsForFile( else if (command == "DIAGNOSTIC_TEST") { SLANG_RETURN_ON_FAIL(_gatherTestOptions(categorySet, &cursor, testDetails.options)); + applyMacroSubstitution(filePath, testDetails); // Apply the file wide options _combineOptions(categorySet, fileOptions, testDetails.options); |
