https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/97910

This patch addresses static analyzer concern where TSI could be dereferenced 
after being assigned a null value from SubstType in 
clang::TemplateDeclInstantiator::VisitUsingEnumDecl(clang::UsingEnumDecl *).

The fix now checks null value of TSI after the call to SubstType and return 
nullptr to prevent potential null pointer dereferences when calling 
UsingEnumDecl::Create() and ensures safe execution.

>From 1c8d64e086f1d4e65fcc6bcc8afd13b75f675b6a Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.ma...@intel.com>
Date: Sat, 6 Jul 2024 13:23:10 -0700
Subject: [PATCH] [Clang] Fix null pointer dereference in VisitUsingEnumDecl

This patch addresses static analyzer concern where TSI could be dereferenced 
after being assigned a null value from SubstType in 
clang::TemplateDeclInstantiator::VisitUsingEnumDecl(clang::UsingEnumDecl *).

The fix now checks null value of TSI after the call to SubstType and return 
nullptr to prevent potential null pointer dereferences when calling 
UsingEnumDecl::Create() and ensures safe execution.
---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 64f6b01bed2292..8d856b807889ff 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3413,6 +3413,10 @@ Decl 
*TemplateDeclInstantiator::VisitUsingEnumDecl(UsingEnumDecl *D) {
 
   TypeSourceInfo *TSI = SemaRef.SubstType(D->getEnumType(), TemplateArgs,
                                           D->getLocation(), D->getDeclName());
+
+  if (!TSI)
+    return nullptr;
+
   UsingEnumDecl *NewUD =
       UsingEnumDecl::Create(SemaRef.Context, Owner, D->getUsingLoc(),
                             D->getEnumLoc(), D->getLocation(), TSI);

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to