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

This patch adds an assert in getMangledNameImpl() to ensure that the expected 
attributes (TargetAttr, TargetVersionAttr, and TargetClonesAttr) are checked 
for NULL value before being used by appendAttributeMangling().

>From 5459e49d79f0916b198446fe9a0c06e7f24f7f7d Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.ma...@intel.com>
Date: Fri, 31 May 2024 16:38:52 -0700
Subject: [PATCH] [Clang] Prevent null pointer dereference in target attribute
 mangling

This patch adds an assert in getMangledNameImpl() to ensure that the
expected attributes (TargetAttr, TargetVersionAttr, and
TargetClonesAttr) are checked for NULL value before being used by 
appendAttributeMangling().
---
 clang/lib/CodeGen/CodeGenModule.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c2314c3a57d33..7541817e41e86 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1853,18 +1853,21 @@ static std::string getMangledNameImpl(CodeGenModule 
&CGM, GlobalDecl GD,
         break;
       case MultiVersionKind::Target: {
         auto *Attr = FD->getAttr<TargetAttr>();
+        assert(Attr && "Expected TargetAttr to be present for attribute 
mangling");
         const ABIInfo &Info = CGM.getTargetCodeGenInfo().getABIInfo();
         Info.appendAttributeMangling(Attr, Out);
         break;
       }
       case MultiVersionKind::TargetVersion: {
         auto *Attr = FD->getAttr<TargetVersionAttr>();
+        assert(Attr && "Expected TargetVersionAttr to be present for attribute 
mangling");
         const ABIInfo &Info = CGM.getTargetCodeGenInfo().getABIInfo();
         Info.appendAttributeMangling(Attr, Out);
         break;
       }
       case MultiVersionKind::TargetClones: {
         auto *Attr = FD->getAttr<TargetClonesAttr>();
+        assert(Attr && "Expected TargetClonesAttr to be present for attribute 
mangling");
         unsigned Index = GD.getMultiVersionIndex();
         const ABIInfo &Info = CGM.getTargetCodeGenInfo().getABIInfo();
         Info.appendAttributeMangling(Attr, Index, Out);

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

Reply via email to