aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorsmanna12 <soumi.manna@intel.com>2024-06-03 16:20:33 -0700
committerGitHub <noreply@github.com>2024-06-03 18:20:33 -0500
commitccaccc3367aa3d892ca31eb11d4bcea4979bead1 (patch)
tree123d60c8e251d2446b61a3419ba1c6c23f79c8bb /clang/lib/CodeGen/CodeGenModule.cpp
parentae1596a31a6fac2f4daafe1e256d4a5cf3742617 (diff)
downloadllvm-ccaccc3367aa3d892ca31eb11d4bcea4979bead1.zip
llvm-ccaccc3367aa3d892ca31eb11d4bcea4979bead1.tar.gz
llvm-ccaccc3367aa3d892ca31eb11d4bcea4979bead1.tar.bz2
[Clang] Prevent null pointer dereference in target attribute mangling (#94228)
This patch adds assertions in the getMangledNameImpl() function to ensure that the expected target attributes (TargetAttr, TargetVersionAttr, and TargetClonesAttr) are not null before they are passed to appendAttributeMangling() to prevent potential null pointer dereferences and improve the robustness of the attribute mangling process. This assertion will trigger a runtime error with a clear message in debug build if any of the expected attributes are missing, facilitating early and easier diagnosis and debugging of such issues related to attribute mangling.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c2314c3..be7bf0b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1853,18 +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");
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);