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

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

>From e30b21648a74a881b645a4a2695546783f20b500 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.ma...@intel.com>
Date: Mon, 3 Jun 2024 07:35:01 -0700
Subject: [PATCH 2/2] Fix clang-format errors

---
 clang/lib/CodeGen/CodeGenModule.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 7541817e41e86..b6c3ad06c6783 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1853,21 +1853,26 @@ 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");
+        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");
+        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");
+        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