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
5 changed files with 29 additions and 2 deletions
|
|
@ -254,11 +254,17 @@ void TParseContextBase::trackLinkage(TSymbol& symbol)
|
|||
// Give an error if not.
|
||||
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) {
|
||||
error(loc, "", "[", "index out of range '%d'", index);
|
||||
index = 0;
|
||||
} 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);
|
||||
index = type.getOuterArraySize() - 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue