[clang] [Clang] Fix crash on template-specialization (PR #142338)
Mark de Wever via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 2 07:24:55 PDT 2025
================
@@ -5120,6 +5121,10 @@ bool Sema::addInstantiatedParametersToScope(
// Simple case: not a parameter pack.
assert(FParamIdx < Function->getNumParams());
ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+ DeclarationName name = FunctionParam->getDeclName();
+ auto _ = llvm::make_scope_exit([&]() {
+ FunctionParam->setDeclName(name);
----------------
mark-de-wever-sonarsource wrote:
This approach is based on what Richard suggested in https://github.com/llvm/llvm-project/issues/54279#issuecomment-2623325977 " for example, we need to set the name back when we're done with it.".
The crash is caused due to another scope-exit. In that scope a `FETokenInfo` "attached" to the name of the function argument. This function is unaware of that scope so the "rename" is unknown to that scope and at that scope's scope-exit the information "attached" to the current name (_not_ the original name) is removed. This is where an assertion triggers.
So this change basically restores the original name so the other scope-exit will "detach" the `FETokenInfo` using the original name and the crash is resolved.
https://github.com/llvm/llvm-project/pull/142338
More information about the cfe-commits
mailing list