[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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user