Skip to content

PostProcessingComputePass: dangling iterators from get_resources() temporaries (found via clang 23 -Wdangling-gsl) #1570

Description

@windsunil

Building with clang 23 and warnings-as-errors fails in framework/rendering/postprocessing_computepass.cpp:

framework/rendering/postprocessing_computepass.cpp:154:33: error:
object backing the pointer will be destroyed at the end of the
full-expression [-Werror,-Wdangling-gsl]

Looking at the code, I think the warning is a true positive rather than noise. PipelineLayout::get_resources() returns
const std::vector<ShaderResource> by value (a fresh copy each call), and the transition code calls it three times:

auto resource = std::find_if(pipeline_layout.get_resources().begin(),
                             pipeline_layout.get_resources().end(),
                             [&storage](const auto &res) { ... });
if (resource == pipeline_layout.get_resources().end())
    ...
const bool readable = !(resource->qualifiers & ...);

So begin() and end() come from two different temporary vectors, both are destroyed at the end of the statement, the later end()
comparison uses a third temporary, and resource->qualifiers dereferences an iterator into a destroyed vector.

It probably never crashes in practice because, as #841 noted, this class appears to be unused - but it is still compiled everywhere, so
clang 23 makes it a build failure for -Werror configurations.

Two possible ways out:

  1. Call get_resources() once and keep it in a local:
const auto resources = pipeline_layout.get_resources();
auto resource = std::find_if(resources.begin(), resources.end(),
                             [&storage](const auto &res) { ... });
if (resource == resources.end())

or

  1. remove the class, as framework/rendering/postprocessing_computepass is never used - should it be removed? #841 already suggested.

Happy to send a PR for option 1 if that is the preferred direction.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions