HLSL: Handle const with no initializer. Fixes issue #651.
This commit is contained in:
@@ -3892,6 +3892,23 @@ void HlslParseContext::updateImplicitArraySize(const TSourceLoc& loc, TIntermNod
|
||||
symbol->getWritableType().setImplicitArraySize(index + 1);
|
||||
}
|
||||
|
||||
//
|
||||
// Enforce non-initializer type/qualifier rules.
|
||||
//
|
||||
void HlslParseContext::fixConstInit(const TSourceLoc& loc, TString& identifier, TType& type, TIntermTyped*& initializer)
|
||||
{
|
||||
//
|
||||
// Make the qualifier make sense, given that there is an initializer.
|
||||
//
|
||||
if (initializer == nullptr) {
|
||||
if (type.getQualifier().storage == EvqConst ||
|
||||
type.getQualifier().storage == EvqConstReadOnly) {
|
||||
initializer = intermediate.makeAggregate(loc);
|
||||
warn(loc, "variable with qualifier 'const' not initialized; zero initializing", identifier.c_str(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// See if the identifier is a built-in symbol that can be redeclared, and if so,
|
||||
// copy the symbol table's read-only built-in variable to the current
|
||||
@@ -4736,6 +4753,9 @@ TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& i
|
||||
if (voidErrorCheck(loc, identifier, type.getBasicType()))
|
||||
return nullptr;
|
||||
|
||||
// make const and initialization consistent
|
||||
fixConstInit(loc, identifier, type, initializer);
|
||||
|
||||
// Check for redeclaration of built-ins and/or attempting to declare a reserved name
|
||||
TSymbol* symbol = nullptr;
|
||||
|
||||
|
||||
@@ -183,6 +183,7 @@ protected:
|
||||
int nextBinding; // next binding to use.
|
||||
};
|
||||
|
||||
void fixConstInit(const TSourceLoc&, TString& identifier, TType& type, TIntermTyped*& initializer);
|
||||
void inheritGlobalDefaults(TQualifier& dst) const;
|
||||
TVariable* makeInternalVariable(const char* name, const TType&) const;
|
||||
TVariable* declareNonArray(const TSourceLoc&, TString& identifier, TType&, bool track);
|
||||
|
||||
Reference in New Issue
Block a user