diff options
author | Michael Jabbour <michael.jabbour@sonarsource.com> | 2025-07-28 11:42:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-28 17:42:30 +0800 |
commit | 6c2caa63d7d2929765199a66a61660f5372f01c7 (patch) | |
tree | 3126246f6d74d3113562c890b64f6129a690926c /clang/unittests/Frontend/CompilerInvocationTest.cpp | |
parent | 2ad4e93dedbb9936f03bb7035dccebb1cf4a75cb (diff) | |
download | llvm-6c2caa63d7d2929765199a66a61660f5372f01c7.zip llvm-6c2caa63d7d2929765199a66a61660f5372f01c7.tar.gz llvm-6c2caa63d7d2929765199a66a61660f5372f01c7.tar.bz2 |
[Serialization] Fix crash while lazy-loading template specializations (#150430)
## Problem
This is a regression that was observed in Clang 20 on modules code that
uses import std.
The lazy-loading mechanism for template specializations introduced in
#119333 can currently load additional nodes when called multiple times,
which breaks assumptions made by code that iterates over
specializations. This leads to iterator invalidation crashes in some
scenarios.
The core issue occurs when:
1. Code calls `spec_begin()` to get an iterator over template
specializations. This invokes `LoadLazySpecializations()`.
2. Code then calls `spec_end()` to get the end iterator.
3. During the `spec_end()` call, `LoadExternalSpecializations()` is
invoked again.
4. This can load additional specializations for certain cases,
invalidating the begin iterator returned in 1.
I was able to trigger the problem when constructing a ParentMapContext.
The regression test demonstrates two ways to trigger the construction of
the ParentMapContext on problematic code:
- The ArrayBoundV2 checker
- Unsigned overflow detection in sanitized builds
Unfortunately, simply dumping the ast (e.g. using `-ast-dump-all`)
doesn't trigger the crash because dumping requires completing the redecl
chain before iterating over the specializations.
## Solution
The fix ensures that the redeclaration chain is always completed
**before** loading external specializations by calling
`CompleteRedeclChain(D)` at the start of
`LoadExternalSpecializations()`. The idea is to ensure that all
`SpecLookups` are fully known and loaded before the call to
`LoadExternalSpecializationsImpl()`.
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
0 files changed, 0 insertions, 0 deletions