[clang] [Clang] [Sema] Added a check for `NameInfo` actually containing a valid destructor name (PR #210610)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 19 09:30:34 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Soham Karandikar (skadewdl3)
<details>
<summary>Changes</summary>
Fixes #<!-- -->210234
As per my investigation (mostly following stack traces and dumping variable values), a default empty `DeclarationNameInfo` was being returned after template substitution [over here](https://github.com/llvm/llvm-project/blob/c45b4e4d00bed488d6ece5608560561732ae5b9e/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L3270).
```cpp
// D-.>getNameInfo() has actual data here
DeclarationNameInfo NameInfo
= SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
// NameInfo has default values
```
This was being passed on directly to `CXXDestructorDecl::Create` leading to the assertion being hit. This PR adds a check that ensures `NameInfo` actually contains a valid destructor name before constructing a `CXXDestructorDecl`. This fixes the assertion being hit in the reproducer from the linked issue.
---
Full diff: https://github.com/llvm/llvm-project/pull/210610.diff
1 Files Affected:
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+4-1)
``````````diff
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index c2e90624b8a6e..30ddad02f63c2 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3287,7 +3287,10 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
TrailingRequiresClause);
Method->setRangeEnd(Constructor->getEndLoc());
} else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) {
- Method = CXXDestructorDecl::Create(
+ if (NameInfo.getName().getNameKind() != DeclarationName::NameKind::CXXDestructorName) {
+ return nullptr;
+ }
+ Method = CXXDestructorDecl::Create(
SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
Destructor->UsesFPIntrin(), Destructor->isInlineSpecified(), false,
Destructor->getConstexprKind(), TrailingRequiresClause);
``````````
</details>
https://github.com/llvm/llvm-project/pull/210610
More information about the cfe-commits
mailing list