Skip to content

Commit 8b08aa3

Browse files
committed
Fix to allow defining variables of link-time size.
1 parent 6c12500 commit 8b08aa3

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

source/slang/slang-ast-decl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ enum class TypeTag
137137
{
138138
None = 0,
139139
Unsized = 1,
140-
Incomplete = 2
140+
Incomplete = 2,
141+
LinkTimeSized = 4,
141142
};
142143

143144
// Declaration of a type that represents some sort of aggregate

source/slang/slang-check-conformance.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ namespace Slang
274274
}
275275
else if (auto intVal = arrayType->getElementCount())
276276
{
277-
sized = !intVal->isLinkTimeVal();
277+
sized = true;
278+
typeTag = (TypeTag)((int)typeTag | (int)TypeTag::LinkTimeSized);
278279
}
279280
if (!sized)
280281
typeTag = (TypeTag)((int)typeTag | (int)TypeTag::Unsized);

source/slang/slang-check-decl.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,9 @@ namespace Slang
20532053
if (parentDecl)
20542054
{
20552055
parentDecl->addTag(getVarTypeTags());
2056-
bool isUnsized = (((int)getVarTypeTags() & (int)TypeTag::Unsized) != 0);
2057-
if (isUnsized)
2056+
auto unsizedMask = (int)TypeTag::Unsized | (int)TypeTag::LinkTimeSized;
2057+
bool isUnknownSize = (((int)getVarTypeTags() & unsizedMask) != 0);
2058+
if (isUnknownSize)
20582059
{
20592060
// Unsized decl must appear as the last member of the struct.
20602061
for (auto memberIdx = parentDecl->members.getCount() - 1; memberIdx >= 0; memberIdx--)

tests/bugs/gh-4150.slang

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//TEST:SIMPLE(filecheck=CHECK1):-target spirv -DERROR1
22
//TEST:SIMPLE(filecheck=CHECK2):-target spirv -DERROR2
3+
extern static const int constValue = 1;
34

45
struct RWTex<T : __BuiltinRealType, let N : uint>
56
{
@@ -42,4 +43,7 @@ void main(uint3 pixel_i : SV_DispatchThreadID)
4243

4344
//CHECK1-NOT:([[# @LINE+1]]): error
4445
float sa4[] = { 1, 2, 3 }; // should be ok.
46+
47+
//CHECK1-NOT:([[# @LINE+1]]): error
48+
float sa5[constValue]; // should be ok.
4549
}

0 commit comments

Comments
 (0)