From b8b8b47a1b8996b8cf906e3ba0b3190fbf5c0151 Mon Sep 17 00:00:00 2001 From: Shafik Yaghmour Date: Tue, 7 Oct 2025 14:17:31 -0700 Subject: [PATCH 1/2] [Clang][Sema] Add nullptr check in isTemplateName Static analysis flagged that when calling ActOnTemplateName, S can be a nullptr and we call isTemplateName which unconditionally dereferences the S argument at some point. I added a nullptr check to assure we don't dereference S in isTemplateName if it is a nullptr. --- clang/lib/Sema/SemaTemplate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 419f3e1ad30ed..3076dae9f927b 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -319,7 +319,7 @@ TemplateNameKind Sema::isTemplateName(Scope *S, } if (isPackProducingBuiltinTemplateName(Template) && - S->getTemplateParamParent() == nullptr) + S && S->getTemplateParamParent() == nullptr) Diag(Name.getBeginLoc(), diag::err_builtin_pack_outside_template) << TName; // Recover by returning the template, even though we would never be able to // substitute it. From 13de0fd59355ad635be95fe1df828d2d74b7412c Mon Sep 17 00:00:00 2001 From: Shafik Yaghmour Date: Tue, 7 Oct 2025 14:42:41 -0700 Subject: [PATCH 2/2] Applied clang-format --- clang/lib/Sema/SemaTemplate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 3076dae9f927b..3a6ff9910667d 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -318,8 +318,8 @@ TemplateNameKind Sema::isTemplateName(Scope *S, } } - if (isPackProducingBuiltinTemplateName(Template) && - S && S->getTemplateParamParent() == nullptr) + if (isPackProducingBuiltinTemplateName(Template) && S && + S->getTemplateParamParent() == nullptr) Diag(Name.getBeginLoc(), diag::err_builtin_pack_outside_template) << TName; // Recover by returning the template, even though we would never be able to // substitute it.