Handle buffer references vs 'const'

Allow constructors to and from references to be constant folded. Section 4.3.3
says constructors whose arguments are all constant expressions must fold.

Disallow 'const' on buffer reference types. It is not a 'non-void transparent
basic data type' (it is not considered 'basic').

Handle buffer reference constants (which can be assigned to a non-const reference,
or can be further folded to another type of constant) by converting to
'constructor(uint64_t constant)' in addConversion.

Disallow == and != operators on reference types.
This commit is contained in:
Jeff Bolz 2019-02-18 00:11:05 -06:00
parent d90d548161
commit be63facd80
13 changed files with 1271 additions and 1099 deletions

View file

@ -4435,6 +4435,12 @@ void TParseContext::opaqueCheck(const TSourceLoc& loc, const TType& type, const
error(loc, "can't use with samplers or structs containing samplers", op, "");
}
void TParseContext::referenceCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
if (containsFieldWithBasicType(type, EbtReference))
error(loc, "can't use with reference types", op, "");
}
void TParseContext::storage16BitAssignmentCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtFloat16))
@ -6290,6 +6296,9 @@ TIntermNode* TParseContext::declareVariable(const TSourceLoc& loc, TString& iden
#ifdef NV_EXTENSIONS
accStructNVCheck(loc, type, identifier);
#endif
if (type.getQualifier().storage == EvqConst && type.containsBasicType(EbtReference)) {
error(loc, "variables with reference type can't have qualifier 'const'", "qualifier", "");
}
if (type.getQualifier().storage != EvqUniform && type.getQualifier().storage != EvqBuffer) {
if (type.containsBasicType(EbtFloat16))
@ -6518,7 +6527,11 @@ TIntermNode* TParseContext::executeInitializer(const TSourceLoc& loc, TIntermTyp
// We either have a folded constant in getAsConstantUnion, or we have to use
// the initializer's subtree in the AST to represent the computation of a
// specialization constant.
assert(initializer->getAsConstantUnion() || initializer->getType().getQualifier().isSpecConstant());
// A third case arises when a reference type is made non-constant due to
// addConstantReferenceConversion, but reference types can't be const, so
// this is an error.
assert(initializer->getAsConstantUnion() || initializer->getType().getQualifier().isSpecConstant() ||
initializer->getType().getBasicType() == EbtReference);
if (initializer->getAsConstantUnion())
variable->setConstArray(initializer->getAsConstantUnion()->getConstArray());
else {
@ -6860,7 +6873,7 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
case EOpConstructUint64:
if (type.isScalar() && node->getType().getBasicType() == EbtReference) {
TIntermUnary* newNode = intermediate.addUnaryNode(EOpConvPtrToUint64, node, node->getLoc(), type);
TIntermTyped* newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvPtrToUint64, true, node, type);
return newNode;
}
// fall through
@ -6885,11 +6898,11 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
case EOpConstructReference:
// construct reference from reference
if (node->getType().getBasicType() == EbtReference) {
newNode = intermediate.addUnaryNode(EOpConstructReference, node, node->getLoc(), type);
newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConstructReference, true, node, type);
return newNode;
// construct reference from uint64
} else if (node->getType().isScalar() && node->getType().getBasicType() == EbtUint64) {
TIntermUnary* newNode = intermediate.addUnaryNode(EOpConvUint64ToPtr, node, node->getLoc(), type);
TIntermTyped* newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvUint64ToPtr, true, node, type);
return newNode;
} else {
return nullptr;