<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153384>153384</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clangd crashes when parsing nested template lambda in std::for_each(SIGSEGV in ItaniumMangle.cpp)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
songwei163
</td>
</tr>
</table>
<pre>
Environment
clangd version: Built from LLVM 20 source (provide output of clangd --versionif available)
OS: Linux (details if known, e.g., Ubuntu 22.04)
Reproduction: Observed during background indexing in an editor (e.g., VSCode, Neovim)
Crash Details
Crash Backtrace:
#0 0x00000000006fcfe8 llvm::sys::PrintStackTrace(...)
#1 0x00000000006fadb4 SignalHandler(int)
...
#10 ItaniumMangleContextImpl::mangleLambdaSig(...) // <-- Crash during lambda mangling
Trigger Code:
void collect(std::vector<std::shared_ptr<IntermediateSource<std::vector<value_type>>>>& sources) const {
std::for_each(sources.begin(), sources.end(), [](typename decltype(sources)::value_type& ptr) {
ptr = std::make_shared<typename decltype(sources)::value_type>(); // <-- Crash here
});
}
Minimal Reproduction Example
#include <memory>
#include <vector>
template<typename T>
struct IntermediateSource {};
void test() {
using value_type = int;
std::vector<std::shared_ptr<IntermediateSource<std::vector<value_type>>>> sources;
std::for_each(sources.begin(), sources.end(), [](auto& ptr) {
ptr = std::make_shared<typename decltype(sources)::value_type>(); // Triggers crash
});
}
Observations
Crash occurs during lambda name mangling (ItaniumMangle.cpp).
Likely related to nested template types (decltype(sources)::value_typeinside a lambda).
Workarounds:
Replace decltype(sources)::value_typewith an explicit type alias (resolves the crash).
Use range-based forloop instead of std::for_each.
Request
Please investigate the crash in ItaniumMangleContextImpl::mangleLambdaSig. The issue appears to be triggered by complex template deductions in lambdas.
Additional Notes
Attach full backtrace if needed (from the original error log).
Mention if the crash is reproducible with other STL algorithms (e.g., std::transform).
</pre>
<img width="1" height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