SPV: Fix #1783: Don't do bounds checking for spec-const-expression size
It's okay for symbolic spec-consts, but without constant folding, not okay when the array size is an expression.
This commit is contained in:
parent
4b4b41a634
commit
96524f9168
6
Test/baseResults/spv.specConstArrayCheck.vert.out
Executable file
6
Test/baseResults/spv.specConstArrayCheck.vert.out
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
spv.specConstArrayCheck.vert
|
||||||
|
ERROR: 0:13: '[' : array index out of range '6'
|
||||||
|
ERROR: 1 compilation errors. No code generated.
|
||||||
|
|
||||||
|
|
||||||
|
SPIR-V is not generated for failed compile or link
|
14
Test/spv.specConstArrayCheck.vert
Executable file
14
Test/spv.specConstArrayCheck.vert
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(constant_id = 0) const uint a = 1;
|
||||||
|
layout(constant_id = 1) const uint b = 2;
|
||||||
|
layout(location = 0) out uint o;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uint arr1[a+a];
|
||||||
|
uint arr2[b];
|
||||||
|
o = arr1[1];
|
||||||
|
o = arr2[1];
|
||||||
|
o = arr1[6];
|
||||||
|
o = arr2[6];
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
// This header is generated by the make-revision script.
|
// This header is generated by the make-revision script.
|
||||||
|
|
||||||
#define GLSLANG_PATCH_LEVEL 3276
|
#define GLSLANG_PATCH_LEVEL 3294
|
||||||
|
@ -254,11 +254,17 @@ void TParseContextBase::trackLinkage(TSymbol& symbol)
|
|||||||
// Give an error if not.
|
// Give an error if not.
|
||||||
void TParseContextBase::checkIndex(const TSourceLoc& loc, const TType& type, int& index)
|
void TParseContextBase::checkIndex(const TSourceLoc& loc, const TType& type, int& index)
|
||||||
{
|
{
|
||||||
|
const auto sizeIsSpecializationExpression = [&type]() {
|
||||||
|
return type.containsSpecializationSize() &&
|
||||||
|
type.getArraySizes()->getOuterNode() != nullptr &&
|
||||||
|
type.getArraySizes()->getOuterNode()->getAsSymbolNode() == nullptr; };
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
error(loc, "", "[", "index out of range '%d'", index);
|
error(loc, "", "[", "index out of range '%d'", index);
|
||||||
index = 0;
|
index = 0;
|
||||||
} else if (type.isArray()) {
|
} else if (type.isArray()) {
|
||||||
if (type.isSizedArray() && index >= type.getOuterArraySize()) {
|
if (type.isSizedArray() && !sizeIsSpecializationExpression() &&
|
||||||
|
index >= type.getOuterArraySize()) {
|
||||||
error(loc, "", "[", "array index out of range '%d'", index);
|
error(loc, "", "[", "array index out of range '%d'", index);
|
||||||
index = type.getOuterArraySize() - 1;
|
index = type.getOuterArraySize() - 1;
|
||||||
}
|
}
|
||||||
|
@ -545,6 +545,7 @@ INSTANTIATE_TEST_CASE_P(
|
|||||||
"vulkan.vert",
|
"vulkan.vert",
|
||||||
"vulkan.comp",
|
"vulkan.comp",
|
||||||
"samplerlessTextureFunctions.frag",
|
"samplerlessTextureFunctions.frag",
|
||||||
|
"spv.specConstArrayCheck.vert",
|
||||||
})),
|
})),
|
||||||
FileNameAsCustomTestSuffix
|
FileNameAsCustomTestSuffix
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user