KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.91k stars 816 forks source link

maybe-uninitialized warning in GCC9 #2080

Closed dneto0 closed 7 months ago

dneto0 commented 4 years ago

There are a few warnings in GCC9 for maybe-uninitialized members of structs. Looking at the first example, I'm not sure there is a zero-cost fix for this. Do you advise turning off the warning? (This is low priority for me.)

/glslang/MachineIndependent/../Include/../Include/Types.h: In member function ‘void glslang::TParseContext::declareBlock(const glslang::TSourceLoc&, glslang::TTypeList&, const TString*, glslan
g::TArraySizes*)’:
/glslang/MachineIndependent/../Include/../Include/Types.h:1555:17: warning: ‘blockNameType.glslang::TType::sampler’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1555 |         sampler = copyOf.sampler;
      |         ~~~~~~~~^~~~~~~~~~~~~~~~
/glslang/MachineIndependent/../Include/../Include/Types.h:1569:24: warning: ‘blockNameType.glslang::TType::typeParameters’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1569 |         typeParameters = copyOf.typeParameters;
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
...
/build/dneto/v/amber/amber/third_party/glslang/glslang/MachineIndependent/../Include/../Include/Types.h:1570:17: warning: ‘blockNameType.glslang::TType::coopmat’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1570 |         coopmat = copyOf.isCoopMat();
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
johnkslang commented 4 years ago

These members are all included in virtually all the constructors' setting/clearing, so would typically be initialized.

I see the exception is the somewhat recent TType constructor for block references, which for some reason has these three members missing from the constructor.

It seems worthwhile to me to include full construction (initialization) in all the constructors.

Looking at line ~1528, you can see these three missing in the block reference constructor:

    // For interface blocks
    TType(TTypeList* userDef, const TString& n, const TQualifier& q) :
                            basicType(EbtBlock), vectorSize(1), matrixCols(0), matrixRows(0), vector1(false), coopmat(false),
                            qualifier(q), arraySizes(nullptr), structure(userDef), fieldName(nullptr), typeParameters(nullptr)
                            {
                                sampler.clear();
                                ...
    // for block reference (first parameter must be EbtReference)
    explicit TType(TBasicType t, const TType &p, const TString& n) :
                            basicType(t), vectorSize(1), matrixCols(0), matrixRows(0), vector1(false),
                            arraySizes(nullptr), structure(nullptr), fieldName(nullptr), typeName(nullptr)

The latter fails to initialize the same members the OP identifies. I think that should be fixed (but I don't see the warnings, or whether this is only some of them).

ncesario-lunarg commented 7 months ago

Closing this as we are not seeing this warning anymore.