[clang] [Clang] Prevent null pointer dereference in target attribute mangling (PR #94228)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 3 10:12:40 PDT 2024
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.manna at intel.com>
Date: Fri, 31 May 2024 16:38:52 -0700
Subject: [PATCH 1/3] [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.manna at intel.com>
Date: Mon, 3 Jun 2024 07:35:01 -0700
Subject: [PATCH 2/3] 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);
>From cb9f803b3918384a1dae443ec87aff24b5009feb Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Mon, 3 Jun 2024 10:12:06 -0700
Subject: [PATCH 3/3] address review comment
---
clang/lib/CodeGen/CodeGenModule.cpp | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index b6c3ad06c6783..be7bf0b72dc0c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1853,26 +1853,24 @@ 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);
More information about the cfe-commits
mailing list