Skip to content

Conversation

shafik
Copy link
Collaborator

@shafik shafik commented Oct 7, 2025

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.

shafik added 2 commits October 7, 2025 14:17
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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2025

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/162377.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplate.cpp (+1-1)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 419f3e1ad30ed..3a6ff9910667d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -318,7 +318,7 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
     }
   }
 
-  if (isPackProducingBuiltinTemplateName(Template) &&
+  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

Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, I think, but PR title needs some rewording.

@shafik shafik changed the title Fix add nullptr check for s is template name Add a nullptr check in template name Oct 8, 2025
@shafik shafik changed the title Add a nullptr check in template name [Clang][Sema] Add a nullptr check in template name Oct 8, 2025
@shafik shafik merged commit 37af81f into llvm:main Oct 8, 2025
12 checks passed
svkeerthy pushed a commit that referenced this pull request Oct 9, 2025
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`.
clingfei pushed a commit to clingfei/llvm-project that referenced this pull request Oct 10, 2025
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants