Author: smanna12 Date: 2024-06-03T18:20:33-05:00 New Revision: ccaccc3367aa3d892ca31eb11d4bcea4979bead1
URL: https://github.com/llvm/llvm-project/commit/ccaccc3367aa3d892ca31eb11d4bcea4979bead1 DIFF: https://github.com/llvm/llvm-project/commit/ccaccc3367aa3d892ca31eb11d4bcea4979bead1.diff LOG: [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. Added: Modified: clang/lib/CodeGen/CodeGenModule.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c2314c3a57d33..be7bf0b72dc0c 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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits