diff --git a/Test/baseResults/hlsl.partialInit.frag.out b/Test/baseResults/hlsl.partialInit.frag.out index 146af5682381aa68f91658f2b34367cc3afc7169..e0bda0e1bf826e36c9e98bd3db39dbb17bc02d01 100755 --- a/Test/baseResults/hlsl.partialInit.frag.out +++ b/Test/baseResults/hlsl.partialInit.frag.out @@ -1,4 +1,7 @@ hlsl.partialInit.frag +WARNING: 0:35: 'cgf2a' : variable with qualifier 'const' not initialized; zero initializing +WARNING: 0:36: 'ci' : variable with qualifier 'const' not initialized; zero initializing + Shader version: 450 gl_FragCoord origin is upper left 0:? Sequence @@ -175,6 +178,15 @@ gl_FragCoord origin is upper left 0:? 'input' (layout(location=0 ) in 4-component vector of float) 0:? 'gv' (global 4-component vector of float) 0:? 'gfa' (global 3-element array of float) +0:? 'cgf2a' (const 3-element array of 2-component vector of float) +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 'ci' (const int) +0:? 0 (const int) Linked fragment stage: @@ -356,10 +368,19 @@ gl_FragCoord origin is upper left 0:? 'input' (layout(location=0 ) in 4-component vector of float) 0:? 'gv' (global 4-component vector of float) 0:? 'gfa' (global 3-element array of float) +0:? 'cgf2a' (const 3-element array of 2-component vector of float) +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 0.000000 +0:? 'ci' (const int) +0:? 0 (const int) // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 90 +// Id's are bound by 92 Capability Shader 1: ExtInstImport "GLSL.std.450" @@ -451,6 +472,8 @@ gl_FragCoord origin is upper left 84(v): 83(ptr) Variable Output 88: TypePointer Input 7(fvec4) 89(input): 88(ptr) Variable Input + 90: TypeArray 53(fvec2) 14 + 91: 90 ConstantComposite 58 58 58 4(PixelShaderFunction): 2 Function None 3 5: Label 23(o2): 22(ptr) Variable Function diff --git a/Test/hlsl.partialInit.frag b/Test/hlsl.partialInit.frag index d47751f45fa5897c7e4e96c9612804b770397e59..01aee8e60b5527390944b4003f167034c07b1f88 100755 --- a/Test/hlsl.partialInit.frag +++ b/Test/hlsl.partialInit.frag @@ -31,3 +31,6 @@ outs PixelShaderFunction(float4 input) : COLOR0 return o4; } + +static const float2 cgf2a[3]; +static const int ci; diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 67bb883cc4339dccd717cde7a2ca5758c576722c..bf59b81b2e2a8ea33ad624fa1a5026156e774548 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -3255,7 +3255,7 @@ bool TParseContext::lineDirectiveShouldSetNextLine() const void TParseContext::nonInitConstCheck(const TSourceLoc& loc, TString& identifier, TType& type) { // - // Make the qualifier make sense, given that there is an initializer. + // Make the qualifier make sense, given that there is not an initializer. // if (type.getQualifier().storage == EvqConst || type.getQualifier().storage == EvqConstReadOnly) { @@ -5007,7 +5007,7 @@ TIntermNode* TParseContext::declareVariable(const TSourceLoc& loc, TString& iden if (voidErrorCheck(loc, identifier, type.getBasicType())) return nullptr; - if (initializer) + if (initializer) rValueErrorCheck(loc, "initializer", initializer); else nonInitConstCheck(loc, identifier, type); diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index a92ad4c3704d65ec4883a712cef1fa0de74d79ce..893cbfcaf9d79c5b8815093d79a4fae553586fc9 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -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; diff --git a/hlsl/hlslParseHelper.h b/hlsl/hlslParseHelper.h index d017a2a7cd36675a6fa71c9b01612d7eda0f7fc6..127dc27d6554e60440901e54e7fda5a486424949 100755 --- a/hlsl/hlslParseHelper.h +++ b/hlsl/hlslParseHelper.h @@ -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);