Skip to content

Commit 89bf795

Browse files
Fix a crash when search for files. (#5818)
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
1 parent b0dfb1a commit 89bf795

File tree

8 files changed

+66
-2
lines changed

8 files changed

+66
-2
lines changed

source/core/slang-string-util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ String StringUtil::replaceAll(
461461
StringBuilder builder;
462462
for (Index i = 0; i < text.getLength();)
463463
{
464-
if (i + subStr.getLength() >= text.getLength())
464+
if (i + subStr.getLength() > text.getLength())
465465
{
466466
builder.append(text.subString(i, text.getLength() - i));
467467
break;

source/slang/slang.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4257,7 +4257,7 @@ SourceFile* Linkage::findFile(Name* name, SourceLoc loc, IncludeSystem& outInclu
42574257
// Next, try to find the file of the given name,
42584258
// using our ordinary include-handling logic.
42594259

4260-
auto searchDirs = getSearchDirectories();
4260+
auto& searchDirs = getSearchDirectories();
42614261
outIncludeSystem = IncludeSystem(&searchDirs, getFileSystemExt(), getSourceManager());
42624262

42634263
// Get the original path info
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Common;
2+
3+
__include Common.Test;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//#pragma once
2+
#include "Simple.h"
3+
//
4+
//#ifndef HOST_CODE
5+
//implementing Common;
6+
//#endif
7+
implementing Common;
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//TEST:SIMPLE(filecheck=CHECK): -target spirv -I $dirname
2+
3+
//CHECK: OpEntryPoint
4+
5+
// shaders.slang
6+
7+
//
8+
// This file provides a simple vertex and fragment shader that can be compiled
9+
// using Slang. This code should also be valid as HLSL, and thus it does not
10+
// use any of the new language features supported by Slang.
11+
//
12+
13+
import Scene.Scene;
14+
15+
// Output of the vertex shader, and input to the fragment shader.
16+
struct CoarseVertex
17+
{
18+
float3 color;
19+
};
20+
21+
// Output of the fragment shader
22+
struct Fragment
23+
{
24+
float4 color;
25+
};
26+
27+
28+
// Fragment Shader
29+
30+
[shader("fragment")]
31+
float4 main(
32+
CoarseVertex coarseVertex : CoarseVertex) : SV_Target
33+
{
34+
float3 fragColor = coarseVertex.color;
35+
36+
return float4(fragColor, 1.0);
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Scene;
2+
import Common.Common;
3+

tests/language-feature/modules/gh-5799/Simple.h

Whitespace-only changes.

tools/slang-test/slang-test-main.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,17 @@ static SlangResult _extractCommand(const char** ioCursor, UnownedStringSlice& ou
524524
}
525525
}
526526

527+
static void applyMacroSubstitution(String filePath, TestDetails& details)
528+
{
529+
for (auto& arg : details.options.args)
530+
{
531+
arg = StringUtil::replaceAll(
532+
arg.getUnownedSlice(),
533+
toSlice("$dirname"),
534+
Path::getParentDirectory(filePath).getUnownedSlice());
535+
}
536+
}
537+
527538
// Try to read command-line options from the test file itself
528539
static SlangResult _gatherTestsForFile(
529540
TestCategorySet* categorySet,
@@ -597,6 +608,7 @@ static SlangResult _gatherTestsForFile(
597608
if (command == "TEST")
598609
{
599610
SLANG_RETURN_ON_FAIL(_gatherTestOptions(categorySet, &cursor, testDetails.options));
611+
applyMacroSubstitution(filePath, testDetails);
600612

601613
// See if the type of test needs certain APIs available
602614
const RenderApiFlags testRequiredApis =
@@ -611,6 +623,7 @@ static SlangResult _gatherTestsForFile(
611623
else if (command == "DIAGNOSTIC_TEST")
612624
{
613625
SLANG_RETURN_ON_FAIL(_gatherTestOptions(categorySet, &cursor, testDetails.options));
626+
applyMacroSubstitution(filePath, testDetails);
614627

615628
// Apply the file wide options
616629
_combineOptions(categorySet, fileOptions, testDetails.options);

0 commit comments

Comments
 (0)