Skip to content

Commit 6c12500

Browse files
committed
Add more tests.
1 parent 8af5738 commit 6c12500

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

source/slang/slang-check-decl.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,8 @@ namespace Slang
20492049
}
20502050
return varTypeTags.value();
20512051
};
2052-
if (auto parentDecl = as<AggTypeDecl>(getParentDecl(varDecl)))
2052+
auto parentDecl = as<AggTypeDecl>(getParentDecl(varDecl));
2053+
if (parentDecl)
20532054
{
20542055
parentDecl->addTag(getVarTypeTags());
20552056
bool isUnsized = (((int)getVarTypeTags() & (int)TypeTag::Unsized) != 0);
@@ -2073,14 +2074,14 @@ namespace Slang
20732074
}
20742075
}
20752076
}
2076-
bool isGlobalVar = (isGlobalDecl(varDecl) && !isGlobalShaderParameter(varDecl))
2077-
|| (!as<ParamDecl>(varDecl) && varDecl->hasModifier<HLSLStaticModifier>());
2078-
if (isGlobalVar)
2077+
bool isGlobalOrLocalVar = !isGlobalShaderParameter(varDecl) && !as<ParamDecl>(varDecl) &&
2078+
(!parentDecl || isEffectivelyStatic(varDecl));
2079+
if (isGlobalOrLocalVar)
20792080
{
20802081
bool isUnsized = (((int)getVarTypeTags() & (int)TypeTag::Unsized) != 0);
20812082
if (isUnsized)
20822083
{
2083-
getSink()->diagnose(varDecl, Diagnostics::globalVarCannotBeUnsized);
2084+
getSink()->diagnose(varDecl, Diagnostics::varCannotBeUnsized);
20842085
}
20852086
}
20862087

source/slang/slang-diagnostic-defs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ DIAGNOSTIC(30067, Error, mutatingMethodOnFunctionInputParameterError, "mutating
326326
DIAGNOSTIC(30068, Warning, mutatingMethodOnFunctionInputParameterWarning, "mutating method '$0' called on `in` parameter '$1'; changes will not be visible to caller. copy the parameter into a local variable if this behavior is intended")
327327

328328
DIAGNOSTIC(30070, Error, unsizedMemberMustAppearLast, "unsized member can only appear as the last member in a composite type.")
329-
DIAGNOSTIC(30071, Error, globalVarCannotBeUnsized, "global or static variable cannot not be unsized.")
329+
DIAGNOSTIC(30071, Error, varCannotBeUnsized, "cannot instantiate a variable of unsized type.")
330330

331331
DIAGNOSTIC(30075, Error, cannotSpecializeGeneric, "cannot specialize generic '$0' with the provided arguments.")
332332

tests/bugs/gh-4150.slang

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
//TEST:SIMPLE(filecheck=CHECK1):-target spirv -DERROR1
22
//TEST:SIMPLE(filecheck=CHECK2):-target spirv -DERROR2
33

4-
// CHECK1: error 30075
5-
// CHECK2: error 30071
6-
74
struct RWTex<T : __BuiltinRealType, let N : uint>
85
{
96
#ifdef ERROR2
107
// expect error: cannot define static member with unsized type.
8+
// CHECK2:([[# @LINE+1]]): error 30071
119
static [[vk::binding(0, 0)]] vector<T,N> rwtable[];
1210
#else
1311
static [[vk::binding(0, 0)]] vector<T,N> rwtable[4];
@@ -25,11 +23,23 @@ RWStructuredBuffer<float3> output;
2523
[numthreads(8, 8, 1)]
2624
void main(uint3 pixel_i : SV_DispatchThreadID)
2725
{
28-
output[0] =
26+
output[0] =
2927
#ifdef ERROR1
30-
// expect error: trying to specialize RWTex, which has two arguments, with only one argument.
31-
RWTex<float3>::get(p.image_id);
28+
// expect error: trying to specialize RWTex, which has two arguments, with only one argument.
29+
// CHECK1:([[# @LINE+1]]): error 30075
30+
RWTex<float3>::get(p.image_id);
3231
#else
33-
RWTex<float,3>::get(p.image_id);
32+
RWTex<float, 3>::get(p.image_id);
3433
#endif
34+
//CHECK1:([[# @LINE+1]]): error 30071
35+
static float sa1[];
36+
37+
//CHECK1:([[# @LINE+1]]): error 30071
38+
float sa2[];
39+
40+
//CHECK1-NOT:([[# @LINE+1]]): error
41+
static float sa3[] = { 1, 2, 3 }; // should be ok.
42+
43+
//CHECK1-NOT:([[# @LINE+1]]): error
44+
float sa4[] = { 1, 2, 3 }; // should be ok.
3545
}

0 commit comments

Comments
 (0)