KhronosGroup / KhronosGroup/Vulkan-Samples
PostProcessingComputePass: dangling iterators from get_resources() temporaries (found via clang 23 -Wdangling-gsl)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 5.4k
- Forks
- 835
- Avg merge
- 2h 16m
- Merged PRs (30d)
- 1
Description
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:
- 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
- remove the class, as #841 already suggested.
Happy to send a PR for option 1 if that is the preferred direction.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in framework/rendering/postprocessing_computepass.cpp around line 154 and inspect how PipelineLayout::get_resources() is used in the transition code. Build with clang 23 and warnings-as-errors to reproduce -Wdangling-gsl, then verify the chosen fix removes the warning without changing the resource lookup behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 75/100