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

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 11:40:02 PDT 2024


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

>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 1/2] [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);
   };

>From d7d5e94eea44246e706c774661b4a7077bd06e2f Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Tue, 23 Apr 2024 11:39:13 -0700
Subject: [PATCH 2/2] Remove assert when using getParamDecl()

---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2490ec4ca614a8..d544cfac55ba36 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5183,7 +5183,6 @@ 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());



More information about the cfe-commits mailing list