[clang] [Clang] [NFC] Prevent null pointer dereference in Sema::InstantiateFu… (PR #89801)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 10:41:27 PDT 2024


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

…nctionDefinition

In the lambda function within clang::Sema::InstantiateFunctionDefinition, the return value of a function that may return null is now checked before dereferencing to avoid potential null pointer dereference issues.

>From 326b428c826e866feb538b9dcd33a9df957f9f69 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Tue, 23 Apr 2024 10:37:01 -0700
Subject: [PATCH] [Clang] [NFC] Prevent null pointer dereference in
 Sema::InstantiateFunctionDefinition

In the lambda function within clang::Sema::InstantiateFunctionDefinition, the return value of a function that may return null is now checked before dereferencing to avoid potential null pointer dereference issues.
---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 787a485e0b2f8c..2490ec4ca614a8 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5183,7 +5183,9 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
     Function->setTypeSourceInfo(NewSI);
 
     ParmVarDecl *Parm = Function->getParamDecl(0);
+    assert(Parm && "First parameter not found in function declaration.");
     TypeSourceInfo *NewParmSI = IR.TransformType(Parm->getTypeSourceInfo());
+    assert(NewParmSI && "Type transformation failed.");
     Parm->setType(NewParmSI->getType());
     Parm->setTypeSourceInfo(NewParmSI);
   };



More information about the cfe-commits mailing list