From 8ecb2c70437292ef6fa34f7122df44067de6a4de Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Sun, 25 May 2025 23:44:26 +0300 Subject: Fix #7232 (#7236) --- source/slang/slang-check-expr.cpp | 4 +++ source/slang/slang-parser.cpp | 4 +-- tests/bugs/gh-7232.slang | 59 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests/bugs/gh-7232.slang diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 75b1b7024..0c0b1ec9d 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -2331,6 +2331,10 @@ Expr* SemanticsVisitor::CheckSimpleSubscriptExpr(IndexExpr* subscriptExpr, Type* return CreateErrorExpr(subscriptExpr); } + for (auto& expr : subscriptExpr->indexExprs) + { + expr = CheckExpr(expr); + } auto indexExpr = subscriptExpr->indexExprs[0]; if (!isScalarIntegerType(indexExpr->type.type)) diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index f968f9fe1..565cb2e5f 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -2426,8 +2426,8 @@ static Expr* tryParseGenericApp(Parser* parser, Expr* base) for (auto candidate : overloadedExpr->lookupResult2) { if (candidate.declRef.is() || - declRefExpr->declRef.is() || - declRefExpr->declRef.is()) + candidate.declRef.is() || + candidate.declRef.is()) { baseKind = BaseGenericKind::Generic; break; diff --git a/tests/bugs/gh-7232.slang b/tests/bugs/gh-7232.slang new file mode 100644 index 000000000..041d3e880 --- /dev/null +++ b/tests/bugs/gh-7232.slang @@ -0,0 +1,59 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -dx12 +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu + +// CHECK: 5 +// CHECK-NEXT: 5 +// CHECK-NEXT: 5 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 +// CHECK-NEXT: 1 + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +interface IFoo +{ + property uint value { get; } +}; + +struct Foo : IFoo +{ + property uint value + { + get { return _value; } + } + + uint _value; +}; + +void issue1(Foo foo) +{ + int array[10] = {0,1,2,3,4,5,6,7,8,9}; + outputBuffer[0] = array[foo._value]; // ok + outputBuffer[1] = array[uint(foo.value)]; // ok + outputBuffer[2] = array[foo.value]; // Used to cause error, 'value' was not resolved before checking that it's an integer +} + +void issue2(Foo foo, uint arg) +{ + bool b1 = foo._value < arg; // ok + bool b2 = uint(foo.value) < arg; // ok + bool b3 = foo.value < arg; // Used to crash the compiler + bool b4 = foo.value > arg; // ok + if (b1) outputBuffer[3] = 1; + if (b2) outputBuffer[4] = 1; + if (b3) outputBuffer[5] = 1; + if (!b4) outputBuffer[6] = 1; +} + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + Foo foo; + foo._value = 5; + issue1(foo); + foo._value = 42; + issue2(foo, 43); +} -- cgit v1.2.3