[clang] [Sema] Fix crash in Sema::FindInstantiatedDecl (PR #96509)
Alejandro Álvarez Ayllón via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 10 02:07:06 PDT 2024
================
@@ -6300,7 +6300,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
getTrivialTemplateArgumentLoc(UnpackedArg, QualType(), Loc));
}
QualType T = CheckTemplateIdType(TemplateName(TD), Loc, Args);
- if (T.isNull())
+ if (T.isNull() || T->containsErrors())
----------------
alejandro-alvarez-sonarsource wrote:
I have checked the other places where `CheckTemplateIdType` is used, and indeed, I can not (easily, at least) find any reason why we would have a crash in those places. For instance, in [`SemaTemplate.cpp`](https://github.com/llvm/llvm-project/blob/9ae24c9ac94017e15eb827e25c5693418e6cdb4b/clang/lib/Sema/SemaTemplate.cpp#L5072) there is a similar pattern (as @Sirraide was concerned), but there a null `RecordType` is appropriately handled.
While looking at it, I realized that the null pointer dereference we had fixed downstream was fixed upstream [four months ago](https://github.com/llvm/llvm-project/commit/7415524b45392651969374c067041daa82dc89e7#diff-761c59b5215d832845bd988566c7d0abaa1cc6294cb8ea90f32e33d15bfccf28R6290) in #77890. The introduced assertions trigger, though, throwing me off (since the stack trace is almost identical).
I have gone back to the original commit and added a comment. I will also rework the PR title and description.
https://github.com/llvm/llvm-project/pull/96509
More information about the cfe-commits
mailing list