Skip to content

Commit ccaccc3

Browse files
authored
[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.
1 parent ae1596a commit ccaccc3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,18 +1853,24 @@ static std::string getMangledNameImpl(CodeGenModule &CGM, GlobalDecl GD,
18531853
break;
18541854
case MultiVersionKind::Target: {
18551855
auto *Attr = FD->getAttr<TargetAttr>();
1856+
assert(Attr && "Expected TargetAttr to be present "
1857+
"for attribute mangling");
18561858
const ABIInfo &Info = CGM.getTargetCodeGenInfo().getABIInfo();
18571859
Info.appendAttributeMangling(Attr, Out);
18581860
break;
18591861
}
18601862
case MultiVersionKind::TargetVersion: {
18611863
auto *Attr = FD->getAttr<TargetVersionAttr>();
1864+
assert(Attr && "Expected TargetVersionAttr to be present "
1865+
"for attribute mangling");
18621866
const ABIInfo &Info = CGM.getTargetCodeGenInfo().getABIInfo();
18631867
Info.appendAttributeMangling(Attr, Out);
18641868
break;
18651869
}
18661870
case MultiVersionKind::TargetClones: {
18671871
auto *Attr = FD->getAttr<TargetClonesAttr>();
1872+
assert(Attr && "Expected TargetClonesAttr to be present "
1873+
"for attribute mangling");
18681874
unsigned Index = GD.getMultiVersionIndex();
18691875
const ABIInfo &Info = CGM.getTargetCodeGenInfo().getABIInfo();
18701876
Info.appendAttributeMangling(Attr, Index, Out);

0 commit comments

Comments
 (0)