Skip to content

Commit 38d2af1

Browse files
committed
Fix static_assert test
1 parent a383f30 commit 38d2af1

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

source/slang/slang-diagnostic-defs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ DIAGNOSTIC(-1, Note, seeUsingOf, "see using of '$0'")
4949
DIAGNOSTIC(-1, Note, seeDefinitionOfShader, "see definition of shader '$0'")
5050
DIAGNOSTIC(-1, Note, seeInclusionOf, "see inclusion of '$0'")
5151
DIAGNOSTIC(-1, Note, seeModuleBeingUsedIn, "see module '$0' being used in '$1'")
52+
DIAGNOSTIC(-1, Note, seeCallOfFunc, "see call to '$0'")
5253
DIAGNOSTIC(-1, Note, seePipelineRequirementDefinition, "see pipeline requirement definition")
5354
DIAGNOSTIC(
5455
-1,
@@ -2309,7 +2310,7 @@ DIAGNOSTIC(
23092310
41402,
23102311
Error,
23112312
staticAssertionConditionNotConstant,
2312-
"condition for static assertion cannot be evaluated at the compile-time.")
2313+
"condition for static assertion cannot be evaluated at compile time.")
23132314

23142315
DIAGNOSTIC(
23152316
41402,

source/slang/slang-emit.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,31 @@ void calcRequiredLoweringPassSet(
475475
}
476476
}
477477

478+
void diagnoseCallStack(IRInst* inst, DiagnosticSink* sink)
479+
{
480+
static const int maxDepth = 5;
481+
for (int i = 0; i < maxDepth; i++)
482+
{
483+
auto func = getParentFunc(inst);
484+
if (!func)
485+
return;
486+
bool shouldContinue = false;
487+
for (auto use = func->firstUse; use; use = use->nextUse)
488+
{
489+
auto user = use->getUser();
490+
if (auto call = as<IRCall>(user))
491+
{
492+
sink->diagnose(call, Diagnostics::seeCallOfFunc, func);
493+
inst = call;
494+
shouldContinue = true;
495+
break;
496+
}
497+
}
498+
if (!shouldContinue)
499+
return;
500+
}
501+
}
502+
478503
bool checkStaticAssert(IRInst* inst, DiagnosticSink* sink)
479504
{
480505
switch (inst->getOp())
@@ -498,6 +523,7 @@ bool checkStaticAssert(IRInst* inst, DiagnosticSink* sink)
498523
{
499524
sink->diagnose(inst, Diagnostics::staticAssertionFailureWithoutMessage);
500525
}
526+
diagnoseCallStack(inst, sink);
501527
}
502528
}
503529
else

tests/language-feature/static_assert.slang

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//TEST:SIMPLE(filecheck=CHK):-target hlsl -stage compute -entry computeMain
1+
//TEST:SIMPLE:-target hlsl -stage compute -entry computeMain
22
//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain
33
//TEST:SIMPLE(filecheck=CHK):-target spirv -stage compute -entry computeMain
44
//TEST:SIMPLE(filecheck=HLSL):-target hlsl -stage compute -entry computeMain
@@ -56,14 +56,12 @@ extension MyType<T>
5656
[numthreads(1,1,1)]
5757
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
5858
{
59-
//CHK-NOT:error {{.*}} TEST_specialize
60-
//CHK: error {{.*}} TEST_specialize T_is_int
61-
//CHK-NOT:error {{.*}} TEST_specialize
59+
// CHK-DAG: error {{.*}} TEST_specialize T_is_int
60+
// CHK:error {{.*}} TEST_specialize<float>
6261
TEST_specialize<float>();
6362

64-
//CHK-NOT:error {{.*}} TEST_specialize
65-
//CHK: error 41400: {{.*}} TEST_specialize T_is_float
66-
//CHK-NOT:error {{.*}} TEST_specialize
63+
// CHK-DAG: error {{.*}} TEST_specialize T_is_float
64+
// CHK:error {{.*}} TEST_specialize<int>
6765
TEST_specialize<int>();
6866

6967
//HLSL: error {{.*}} TEST_target_switch all

0 commit comments

Comments
 (0)