Fix uninitialized use of TIntermediate::resource (#2424)
authorBen Clayton <bclayton@google.com>
Mon, 19 Oct 2020 21:21:12 +0000 (22:21 +0100)
committerGitHub <noreply@github.com>
Mon, 19 Oct 2020 21:21:12 +0000 (15:21 -0600)
commit5b99b448b3dbc77f60a482b36f4e8fa9d0ff4a52
tree97c080881dd4f5e10f32311ba14783d8d928cb4f
parentf4f1d8a352ca1908943aea2ad8c54b39b4879080
Fix uninitialized use of TIntermediate::resource (#2424)

TIntermediate was constructed without initializing any of the `resources` fields,
and `TProgram::linkStage()` was not calling `TIntermediate::setLimits()`
after constructing new `TIntermediate`s for non-first stages.

Fields of `resources` were then read in `TIntermediate::finalCheck()`
triggering undefined behavior.

This CL makes three changes:
(1) `TIntermediate::setLimits()` is now called for non-first stages by
    copying the `firstIntermediate`'s limits. This ensures that the
    `resources` fields is initialized, fixing the bug.
(2) `TIntermediate::resources` is now wrapped in a `MustBeAssigned<>`
    helper struct, asserting in non-release builds that this field is
    always initialized before reading.
(3) `TIntermediate::resources` is now zero-initialized, so that if
    the `TIntermediate::resources` field is not set in a release build
    (and so the `assert()` will be disabled) behavior is still
    deterministic.

Fixes #2423
glslang/MachineIndependent/ShaderLang.cpp
glslang/MachineIndependent/linkValidate.cpp
glslang/MachineIndependent/localintermediate.h