Do size checking for an array type's size.
| 5495 | // Do size checking for an array type's size. |
| 5496 | // |
| 5497 | void TParseContext::arraySizeCheck(const TSourceLoc& loc, TIntermTyped* expr, TArraySize& sizePair, |
| 5498 | const char* sizeType, const bool isTypeParameter) |
| 5499 | { |
| 5500 | bool isConst = false; |
| 5501 | sizePair.node = nullptr; |
| 5502 | |
| 5503 | int size = 1; |
| 5504 | |
| 5505 | TIntermConstantUnion* constant = expr->getAsConstantUnion(); |
| 5506 | if (constant) { |
| 5507 | // handle true (non-specialization) constant |
| 5508 | size = constant->getConstArray()[0].getIConst(); |
| 5509 | isConst = true; |
| 5510 | } else { |
| 5511 | // see if it's a specialization constant instead |
| 5512 | if (expr->getQualifier().isSpecConstant()) { |
| 5513 | isConst = true; |
| 5514 | sizePair.node = expr; |
| 5515 | TIntermSymbol* symbol = expr->getAsSymbolNode(); |
| 5516 | if (symbol && symbol->getConstArray().size() > 0) |
| 5517 | size = symbol->getConstArray()[0].getIConst(); |
| 5518 | } else if (expr->getAsUnaryNode() && expr->getAsUnaryNode()->getOp() == glslang::EOpArrayLength && |
| 5519 | expr->getAsUnaryNode()->getOperand()->getType().isCoopMatNV()) { |
| 5520 | isConst = true; |
| 5521 | size = 1; |
| 5522 | sizePair.node = expr->getAsUnaryNode(); |
| 5523 | } |
| 5524 | } |
| 5525 | |
| 5526 | sizePair.size = size; |
| 5527 | |
| 5528 | if (isTypeParameter) { |
| 5529 | if (extensionTurnedOn(E_GL_NV_cooperative_matrix2)) { |
| 5530 | if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint && expr->getBasicType() != EbtBool)) { |
| 5531 | error(loc, sizeType, "", "must be a constant integer or boolean expression"); |
| 5532 | return; |
| 5533 | } |
| 5534 | } else { |
| 5535 | if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint)) { |
| 5536 | error(loc, sizeType, "", "must be a constant integer expression"); |
| 5537 | return; |
| 5538 | } |
| 5539 | } |
| 5540 | if (size < 0) { |
| 5541 | error(loc, sizeType, "", "must be a non-negative integer"); |
| 5542 | return; |
| 5543 | } |
| 5544 | } else { |
| 5545 | if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint)) { |
| 5546 | error(loc, sizeType, "", "must be a constant integer expression"); |
| 5547 | return; |
| 5548 | } |
| 5549 | if (size <= 0) { |
| 5550 | error(loc, sizeType, "", "must be a positive integer"); |
| 5551 | return; |
| 5552 | } |
| 5553 | } |
| 5554 | } |
no test coverage detected