From 20fece1a5c717fe9891f3a1956f585d40477827b Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 25 Apr 2025 15:02:09 -0600 Subject: [PATCH] Warn on misuse of DiagnosticInfo classes that hold Twines This annotates the `Twine` passed to the constructors of the various DiagnosticInfo subclasses with `[[clang::lifetimebound]]`, which causes us to warn when we would try to print the twine after it had already been destructed. We also update `DiagnosticInfoUnsupported` to hold a `const Twine &` like all of the other DiagnosticInfo classes, since this warning allows us to clean up all of the places where it was being used incorrectly. --- llvm/include/llvm/IR/DiagnosticInfo.h | 30 ++++++++------ .../CodeGen/TargetLoweringObjectFileImpl.cpp | 2 +- llvm/lib/LTO/LTOCodeGenerator.cpp | 3 +- llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 2 +- llvm/lib/Linker/LinkDiagnosticInfo.h | 3 +- llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp | 17 ++++---- .../AMDGPU/AMDGPUInstructionSelector.cpp | 6 +-- .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp | 29 ++++++------- .../AMDGPU/AMDGPUPrintfRuntimeBinding.cpp | 5 +-- llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 41 ++++++++----------- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 6 +-- llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp | 8 ++-- llvm/lib/Target/ARM/ARMISelLowering.cpp | 30 ++++++-------- llvm/lib/Target/ARM/ARMMCInstLower.cpp | 9 ++-- .../Target/BPF/BPFPreserveStaticOffset.cpp | 5 +-- llvm/lib/Target/BPF/BPFRegisterInfo.cpp | 5 +-- llvm/lib/Target/DirectX/DXILOpLowering.cpp | 6 +-- .../Target/DirectX/DXILTranslateMetadata.cpp | 3 +- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 15 +++---- llvm/lib/Transforms/Instrumentation/KCFI.cpp | 2 +- 20 files changed, 105 insertions(+), 122 deletions(-) diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h index a1113134f6a34e..9908e03ad371f6 100644 --- a/llvm/include/llvm/IR/DiagnosticInfo.h +++ b/llvm/include/llvm/IR/DiagnosticInfo.h @@ -146,11 +146,12 @@ class DiagnosticInfoGeneric : public DiagnosticInfo { /// \p MsgStr is the message to be reported to the frontend. /// This class does not copy \p MsgStr, therefore the reference must be valid /// for the whole life time of the Diagnostic. - DiagnosticInfoGeneric(const Twine &MsgStr, + DiagnosticInfoGeneric(const Twine &MsgStr LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_Generic, Severity), MsgStr(MsgStr) {} - DiagnosticInfoGeneric(const Instruction *I, const Twine &ErrMsg, + DiagnosticInfoGeneric(const Instruction *I, + const Twine &ErrMsg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_Generic, Severity), MsgStr(ErrMsg), Inst(I) {} @@ -181,7 +182,8 @@ class DiagnosticInfoInlineAsm : public DiagnosticInfo { /// \p MsgStr gives the message. /// This class does not copy \p MsgStr, therefore the reference must be valid /// for the whole life time of the Diagnostic. - DiagnosticInfoInlineAsm(uint64_t LocCookie, const Twine &MsgStr, + DiagnosticInfoInlineAsm(uint64_t LocCookie, + const Twine &MsgStr LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error); /// \p Instr gives the original instruction that triggered the diagnostic. @@ -189,7 +191,8 @@ class DiagnosticInfoInlineAsm : public DiagnosticInfo { /// This class does not copy \p MsgStr, therefore the reference must be valid /// for the whole life time of the Diagnostic. /// Same for \p I. - DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr, + DiagnosticInfoInlineAsm(const Instruction &I, + const Twine &MsgStr LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error); uint64_t getLocCookie() const { return LocCookie; } @@ -258,15 +261,16 @@ class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo { class DiagnosticInfoSampleProfile : public DiagnosticInfo { public: DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum, - const Twine &Msg, + const Twine &Msg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName), LineNum(LineNum), Msg(Msg) {} - DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg, + DiagnosticInfoSampleProfile(StringRef FileName, + const Twine &Msg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName), Msg(Msg) {} - DiagnosticInfoSampleProfile(const Twine &Msg, + DiagnosticInfoSampleProfile(const Twine &Msg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_SampleProfile, Severity), Msg(Msg) {} @@ -296,7 +300,8 @@ class DiagnosticInfoSampleProfile : public DiagnosticInfo { /// Diagnostic information for the PGO profiler. class DiagnosticInfoPGOProfile : public DiagnosticInfo { public: - DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg, + DiagnosticInfoPGOProfile(const char *FileName, + const Twine &Msg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {} @@ -364,7 +369,7 @@ class DiagnosticInfoWithLocationBase : public DiagnosticInfo { /// Return the absolute path tot the file. std::string getAbsolutePath() const; - + const Function &getFunction() const { return Fn; } DiagnosticLocation getLocation() const { return Loc; } @@ -1062,7 +1067,7 @@ class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization { /// Diagnostic information for unsupported feature in backend. class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase { private: - Twine Msg; + const Twine &Msg; public: /// \p Fn is the function where the diagnostic is being emitted. \p Loc is @@ -1072,7 +1077,7 @@ class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase { /// copy this message, so this reference must be valid for the whole life time /// of the diagnostic. DiagnosticInfoUnsupported( - const Function &Fn, const Twine &Msg, + const Function &Fn, const Twine &Msg LLVM_LIFETIME_BOUND, const DiagnosticLocation &Loc = DiagnosticLocation(), DiagnosticSeverity Severity = DS_Error) : DiagnosticInfoWithLocationBase(DK_Unsupported, Severity, Fn, Loc), @@ -1090,7 +1095,8 @@ class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase { /// Diagnostic information for MisExpect analysis. class DiagnosticInfoMisExpect : public DiagnosticInfoWithLocationBase { public: - DiagnosticInfoMisExpect(const Instruction *Inst, const Twine &Msg); + DiagnosticInfoMisExpect(const Instruction *Inst, + const Twine &Msg LLVM_LIFETIME_BOUND); /// \see DiagnosticInfo::print. void print(DiagnosticPrinter &DP) const override; diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index e1bdc7e09fdc01..b8c632d11f2e08 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -709,7 +709,7 @@ class LoweringDiagnosticInfo : public DiagnosticInfo { const Twine &Msg; public: - LoweringDiagnosticInfo(const Twine &DiagMsg, + LoweringDiagnosticInfo(const Twine &DiagMsg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_Lowering, Severity), Msg(DiagMsg) {} void print(DiagnosticPrinter &DP) const override { DP << Msg; } diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index a477a80b165250..09b91d81225a8e 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -739,7 +739,8 @@ namespace { class LTODiagnosticInfo : public DiagnosticInfo { const Twine &Msg; public: - LTODiagnosticInfo(const Twine &DiagMsg, DiagnosticSeverity Severity=DS_Error) + LTODiagnosticInfo(const Twine &DiagMsg LLVM_LIFETIME_BOUND, + DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {} void print(DiagnosticPrinter &DP) const override { DP << Msg; } }; diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 1bfa4ae760ac4d..5b333cda31fb81 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -163,7 +163,7 @@ namespace { class ThinLTODiagnosticInfo : public DiagnosticInfo { const Twine &Msg; public: - ThinLTODiagnosticInfo(const Twine &DiagMsg, + ThinLTODiagnosticInfo(const Twine &DiagMsg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {} void print(DiagnosticPrinter &DP) const override { DP << Msg; } diff --git a/llvm/lib/Linker/LinkDiagnosticInfo.h b/llvm/lib/Linker/LinkDiagnosticInfo.h index 30c16abaf50907..fdae1b79a9e17b 100644 --- a/llvm/lib/Linker/LinkDiagnosticInfo.h +++ b/llvm/lib/Linker/LinkDiagnosticInfo.h @@ -16,7 +16,8 @@ class LinkDiagnosticInfo : public DiagnosticInfo { const Twine &Msg; public: - LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg); + LinkDiagnosticInfo(DiagnosticSeverity Severity, + const Twine &Msg LLVM_LIFETIME_BOUND); void print(DiagnosticPrinter &DP) const override; }; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp index 7ed055e8da2b69..05e2162a4d77ea 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp @@ -1389,9 +1389,8 @@ SDValue AMDGPUTargetLowering::lowerUnhandledCall(CallLoweringInfo &CLI, else if (const GlobalAddressSDNode *G = dyn_cast(Callee)) FuncName = G->getGlobal()->getName(); - DiagnosticInfoUnsupported NoCalls( - Fn, Reason + FuncName, CLI.DL.getDebugLoc()); - DAG.getContext()->diagnose(NoCalls); + DAG.getContext()->diagnose( + DiagnosticInfoUnsupported(Fn, Reason + FuncName, CLI.DL.getDebugLoc())); if (!CLI.IsTailCall) { for (ISD::InputArg &Arg : CLI.Ins) @@ -1410,9 +1409,8 @@ SDValue AMDGPUTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const { const Function &Fn = DAG.getMachineFunction().getFunction(); - DiagnosticInfoUnsupported NoDynamicAlloca(Fn, "unsupported dynamic alloca", - SDLoc(Op).getDebugLoc()); - DAG.getContext()->diagnose(NoDynamicAlloca); + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( + Fn, "unsupported dynamic alloca", SDLoc(Op).getDebugLoc())); auto Ops = {DAG.getConstant(0, SDLoc(), Op.getValueType()), Op.getOperand(0)}; return DAG.getMergeValues(Ops, SDLoc()); } @@ -1527,10 +1525,9 @@ SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI, !AMDGPU::isNamedBarrier(*cast(GV))) { SDLoc DL(Op); const Function &Fn = DAG.getMachineFunction().getFunction(); - DiagnosticInfoUnsupported BadLDSDecl( - Fn, "local memory global used by non-kernel function", - DL.getDebugLoc(), DS_Warning); - DAG.getContext()->diagnose(BadLDSDecl); + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( + Fn, "local memory global used by non-kernel function", + DL.getDebugLoc(), DS_Warning)); // We currently don't have a way to correctly allocate LDS objects that // aren't directly associated with a kernel. We do force inlining of diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp index cf72608420add7..7e72f6ca478fd0 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp @@ -2339,9 +2339,9 @@ bool AMDGPUInstructionSelector::selectG_INTRINSIC_W_SIDE_EFFECTS( case Intrinsic::amdgcn_exp_compr: if (!STI.hasCompressedExport()) { Function &F = I.getMF()->getFunction(); - DiagnosticInfoUnsupported NoFpRet( - F, "intrinsic not supported on subtarget", I.getDebugLoc(), DS_Error); - F.getContext().diagnose(NoFpRet); + F.getContext().diagnose( + DiagnosticInfoUnsupported(F, "intrinsic not supported on subtarget", + I.getDebugLoc(), DS_Error)); return false; } break; diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp index eeb05f0acebed3..177750b639c67e 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp @@ -3014,10 +3014,9 @@ bool AMDGPULegalizerInfo::legalizeGlobalValue( GV->getName() != "llvm.amdgcn.module.lds" && !AMDGPU::isNamedBarrier(*cast(GV))) { const Function &Fn = MF.getFunction(); - DiagnosticInfoUnsupported BadLDSDecl( - Fn, "local memory global used by non-kernel function", MI.getDebugLoc(), - DS_Warning); - Fn.getContext().diagnose(BadLDSDecl); + Fn.getContext().diagnose(DiagnosticInfoUnsupported( + Fn, "local memory global used by non-kernel function", + MI.getDebugLoc(), DS_Warning)); // We currently don't have a way to correctly allocate LDS objects that // aren't directly associated with a kernel. We do force inlining of @@ -7046,11 +7045,9 @@ bool AMDGPULegalizerInfo::legalizeDebugTrap(MachineInstr &MI, // accordingly if (!ST.isTrapHandlerEnabled() || ST.getTrapHandlerAbi() != GCNSubtarget::TrapHandlerAbi::AMDHSA) { - DiagnosticInfoUnsupported NoTrap(B.getMF().getFunction(), - "debugtrap handler not supported", - MI.getDebugLoc(), DS_Warning); - LLVMContext &Ctx = B.getMF().getFunction().getContext(); - Ctx.diagnose(NoTrap); + Function &Fn = B.getMF().getFunction(); + Fn.getContext().diagnose(DiagnosticInfoUnsupported( + Fn, "debugtrap handler not supported", MI.getDebugLoc(), DS_Warning)); } else { // Insert debug-trap instruction B.buildInstr(AMDGPU::S_TRAP) @@ -7078,10 +7075,9 @@ bool AMDGPULegalizerInfo::legalizeBVHIntersectRayIntrinsic( Register TDescr = MI.getOperand(7).getReg(); if (!ST.hasGFX10_AEncoding()) { - DiagnosticInfoUnsupported BadIntrin(B.getMF().getFunction(), - "intrinsic not supported on subtarget", - MI.getDebugLoc()); - B.getMF().getFunction().getContext().diagnose(BadIntrin); + Function &Fn = B.getMF().getFunction(); + Fn.getContext().diagnose(DiagnosticInfoUnsupported( + Fn, "intrinsic not supported on subtarget", MI.getDebugLoc())); return false; } @@ -7231,10 +7227,9 @@ bool AMDGPULegalizerInfo::legalizeBVHDualOrBVH8IntersectRayIntrinsic( Register TDescr = MI.getOperand(10).getReg(); if (!ST.hasBVHDualAndBVH8Insts()) { - DiagnosticInfoUnsupported BadIntrin(B.getMF().getFunction(), - "intrinsic not supported on subtarget", - MI.getDebugLoc()); - B.getMF().getFunction().getContext().diagnose(BadIntrin); + Function &Fn = B.getMF().getFunction(); + Fn.getContext().diagnose(DiagnosticInfoUnsupported( + Fn, "intrinsic not supported on subtarget", MI.getDebugLoc())); return false; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp index 9847fbf108b0cb..7a2a7fc250e27f 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp @@ -128,12 +128,11 @@ static StringRef getAsConstantStr(Value *V) { } static void diagnoseInvalidFormatString(const CallBase *CI) { - DiagnosticInfoUnsupported UnsupportedFormatStr( + CI->getContext().diagnose(DiagnosticInfoUnsupported( *CI->getParent()->getParent(), "printf format string must be a trivially resolved constant string " "global variable", - CI->getDebugLoc()); - CI->getContext().diagnose(UnsupportedFormatStr); + CI->getDebugLoc())); } bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) { diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp index ade88a16193b85..b19fa4b47f91fc 100644 --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -2860,9 +2860,8 @@ SDValue SITargetLowering::LowerFormalArguments( bool IsError = false; if (Subtarget->isAmdHsaOS() && AMDGPU::isGraphics(CallConv)) { - DiagnosticInfoUnsupported NoGraphicsHSA( - Fn, "unsupported non-compute shaders with HSA", DL.getDebugLoc()); - DAG.getContext()->diagnose(NoGraphicsHSA); + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( + Fn, "unsupported non-compute shaders with HSA", DL.getDebugLoc())); IsError = true; } @@ -3086,11 +3085,10 @@ SDValue SITargetLowering::LowerFormalArguments( if (Arg.isOrigArg()) { Argument *OrigArg = Fn.getArg(Arg.getOrigArgIndex()); if (OrigArg->hasAttribute("amdgpu-hidden-argument")) { - DiagnosticInfoUnsupported NonPreloadHiddenArg( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( *OrigArg->getParent(), "hidden argument in kernel signature was not preloaded", - DL.getDebugLoc()); - DAG.getContext()->diagnose(NonPreloadHiddenArg); + DL.getDebugLoc())); } } @@ -7315,11 +7313,10 @@ SDValue SITargetLowering::lowerDEBUGTRAP(SDValue Op, SelectionDAG &DAG) const { if (!Subtarget->isTrapHandlerEnabled() || Subtarget->getTrapHandlerAbi() != GCNSubtarget::TrapHandlerAbi::AMDHSA) { - DiagnosticInfoUnsupported NoTrap(MF.getFunction(), - "debugtrap handler not supported", - Op.getDebugLoc(), DS_Warning); LLVMContext &Ctx = MF.getFunction().getContext(); - Ctx.diagnose(NoTrap); + Ctx.diagnose(DiagnosticInfoUnsupported(MF.getFunction(), + "debugtrap handler not supported", + Op.getDebugLoc(), DS_Warning)); return Chain; } @@ -8092,19 +8089,17 @@ SDValue SITargetLowering::lowerImplicitZextParam(SelectionDAG &DAG, SDValue Op, static SDValue emitNonHSAIntrinsicError(SelectionDAG &DAG, const SDLoc &DL, EVT VT) { - DiagnosticInfoUnsupported BadIntrin(DAG.getMachineFunction().getFunction(), - "non-hsa intrinsic with hsa target", - DL.getDebugLoc()); - DAG.getContext()->diagnose(BadIntrin); + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( + DAG.getMachineFunction().getFunction(), + "non-hsa intrinsic with hsa target", DL.getDebugLoc())); return DAG.getPOISON(VT); } static SDValue emitRemovedIntrinsicError(SelectionDAG &DAG, const SDLoc &DL, EVT VT) { - DiagnosticInfoUnsupported BadIntrin(DAG.getMachineFunction().getFunction(), - "intrinsic not supported on subtarget", - DL.getDebugLoc()); - DAG.getContext()->diagnose(BadIntrin); + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( + DAG.getMachineFunction().getFunction(), + "intrinsic not supported on subtarget", DL.getDebugLoc())); return DAG.getPOISON(VT); } @@ -8813,10 +8808,9 @@ SDValue SITargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, case Intrinsic::amdgcn_dispatch_ptr: case Intrinsic::amdgcn_queue_ptr: { if (!Subtarget->isAmdHsaOrMesa(MF.getFunction())) { - DiagnosticInfoUnsupported BadIntrin( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( MF.getFunction(), "unsupported hsa intrinsic without hsa target", - DL.getDebugLoc()); - DAG.getContext()->diagnose(BadIntrin); + DL.getDebugLoc())); return DAG.getPOISON(VT); } @@ -9925,10 +9919,9 @@ SDValue SITargetLowering::LowerINTRINSIC_VOID(SDValue Op, switch (IntrinsicID) { case Intrinsic::amdgcn_exp_compr: { if (!Subtarget->hasCompressedExport()) { - DiagnosticInfoUnsupported BadIntrin( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( DAG.getMachineFunction().getFunction(), - "intrinsic not supported on subtarget", DL.getDebugLoc()); - DAG.getContext()->diagnose(BadIntrin); + "intrinsic not supported on subtarget", DL.getDebugLoc())); } SDValue Src0 = Op.getOperand(4); SDValue Src1 = Op.getOperand(5); diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp index 85276bd24bcf4a..5416e543341cdb 100644 --- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -623,12 +623,12 @@ static void reportIllegalCopy(const SIInstrInfo *TII, MachineBasicBlock &MBB, MCRegister SrcReg, bool KillSrc, const char *Msg = "illegal VGPR to SGPR copy") { MachineFunction *MF = MBB.getParent(); - DiagnosticInfoUnsupported IllegalCopy(MF->getFunction(), Msg, DL, DS_Error); + LLVMContext &C = MF->getFunction().getContext(); - C.diagnose(IllegalCopy); + C.diagnose(DiagnosticInfoUnsupported(MF->getFunction(), Msg, DL, DS_Error)); BuildMI(MBB, MI, DL, TII->get(AMDGPU::SI_ILLEGAL_COPY), DestReg) - .addReg(SrcReg, getKillRegState(KillSrc)); + .addReg(SrcReg, getKillRegState(KillSrc)); } /// Handle copying from SGPR to AGPR, or from AGPR to AGPR on GFX908. It is not diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp index 56fec409d11ae0..d2de494a23ef74 100644 --- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp +++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp @@ -700,8 +700,8 @@ void diagnoseUnknownMMRAASName(const MachineInstr &MI, StringRef AS) { ListSeparator LS; for (const auto &[Name, Val] : ASNames) OS << LS << '\'' << Name << '\''; - DiagnosticInfoUnsupported BadTag(Fn, Str.str(), MI.getDebugLoc(), DS_Warning); - Fn.getContext().diagnose(BadTag); + Fn.getContext().diagnose( + DiagnosticInfoUnsupported(Fn, Str.str(), MI.getDebugLoc(), DS_Warning)); } /// Reads \p MI's MMRAs to parse the "amdgpu-as" MMRA. @@ -734,8 +734,8 @@ static SIAtomicAddrSpace getFenceAddrSpaceMMRA(const MachineInstr &MI, void SIMemOpAccess::reportUnsupported(const MachineBasicBlock::iterator &MI, const char *Msg) const { const Function &Func = MI->getParent()->getParent()->getFunction(); - DiagnosticInfoUnsupported Diag(Func, Msg, MI->getDebugLoc()); - Func.getContext().diagnose(Diag); + Func.getContext().diagnose( + DiagnosticInfoUnsupported(Func, Msg, MI->getDebugLoc())); } std::optional> diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index 1f7ab8ce3a0e08..e0b7bacaa5729c 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -2941,18 +2941,17 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, assert(!isARMFunc && !isDirect && "Cannot handle call to ARM function or direct call"); if (NumBytes > 0) { - DiagnosticInfoUnsupported Diag(DAG.getMachineFunction().getFunction(), - "call to non-secure function would " - "require passing arguments on stack", - dl.getDebugLoc()); - DAG.getContext()->diagnose(Diag); + DAG.getContext()->diagnose( + DiagnosticInfoUnsupported(DAG.getMachineFunction().getFunction(), + "call to non-secure function would require " + "passing arguments on stack", + dl.getDebugLoc())); } if (isStructRet) { - DiagnosticInfoUnsupported Diag( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( DAG.getMachineFunction().getFunction(), "call to non-secure function would return value through pointer", - dl.getDebugLoc()); - DAG.getContext()->diagnose(Diag); + dl.getDebugLoc())); } } @@ -3320,11 +3319,10 @@ ARMTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, if (AFI->isCmseNSEntryFunction() && MF.getFunction().hasStructRetAttr()) { // Note: using an empty SDLoc(), as the first line of the function is a // better place to report than the last line. - DiagnosticInfoUnsupported Diag( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( DAG.getMachineFunction().getFunction(), "secure entry function would return value through pointer", - SDLoc().getDebugLoc()); - DAG.getContext()->diagnose(Diag); + SDLoc().getDebugLoc())); } // Copy the result values into the output registers. @@ -4810,10 +4808,9 @@ SDValue ARMTargetLowering::LowerFormalArguments( VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getStackSize(), TotalArgRegsSaveSize); if (AFI->isCmseNSEntryFunction()) { - DiagnosticInfoUnsupported Diag( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( DAG.getMachineFunction().getFunction(), - "secure entry function must not be variadic", dl.getDebugLoc()); - DAG.getContext()->diagnose(Diag); + "secure entry function must not be variadic", dl.getDebugLoc())); } } @@ -4831,10 +4828,9 @@ SDValue ARMTargetLowering::LowerFormalArguments( AFI->setArgumentStackSize(StackArgSize); if (CCInfo.getStackSize() > 0 && AFI->isCmseNSEntryFunction()) { - DiagnosticInfoUnsupported Diag( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( DAG.getMachineFunction().getFunction(), - "secure entry function requires arguments on stack", dl.getDebugLoc()); - DAG.getContext()->diagnose(Diag); + "secure entry function requires arguments on stack", dl.getDebugLoc())); } return Chain; diff --git a/llvm/lib/Target/ARM/ARMMCInstLower.cpp b/llvm/lib/Target/ARM/ARMMCInstLower.cpp index 3e29428032a50a..6892db6eb52c46 100644 --- a/llvm/lib/Target/ARM/ARMMCInstLower.cpp +++ b/llvm/lib/Target/ARM/ARMMCInstLower.cpp @@ -183,12 +183,11 @@ void ARMAsmPrinter::EmitSled(const MachineInstr &MI, SledKind Kind) const MachineFunction *MF = MI.getParent()->getParent(); if (MF->getInfo()->isThumbFunction()) { const Function &Fn = MF->getFunction(); - DiagnosticInfoUnsupported Unsupported( + Fn.getContext().diagnose(DiagnosticInfoUnsupported( Fn, - "An attempt to perform XRay instrumentation for a" - " Thumb function (not supported). Detected when emitting a sled.", - MI.getDebugLoc()); - Fn.getContext().diagnose(Unsupported); + "An attempt to perform XRay instrumentation for a Thumb function (not " + "supported). Detected when emitting a sled.", + MI.getDebugLoc())); return; } static const int8_t NoopsInSledCount = 6; diff --git a/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp b/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp index c21a1d03630fa2..77bbeab3c27906 100644 --- a/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp +++ b/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp @@ -392,15 +392,14 @@ static bool foldGEPChainAsU8Access(SmallVector &GEPs, } static void reportNonStaticGEPChain(Instruction *Insn) { - auto Msg = DiagnosticInfoUnsupported( + Insn->getContext().diagnose(DiagnosticInfoUnsupported( *Insn->getFunction(), Twine("Non-constant offset in access to a field of a type marked " "with preserve_static_offset might be rejected by BPF verifier") .concat(Insn->getDebugLoc() ? "" : " (pass -g option to get exact location)"), - Insn->getDebugLoc(), DS_Warning); - Insn->getContext().diagnose(Msg); + Insn->getDebugLoc(), DS_Warning)); } static bool allZeroIndices(SmallVector &GEPs) { diff --git a/llvm/lib/Target/BPF/BPFRegisterInfo.cpp b/llvm/lib/Target/BPF/BPFRegisterInfo.cpp index 307f278025ff49..f8e3fcdac954bc 100644 --- a/llvm/lib/Target/BPF/BPFRegisterInfo.cpp +++ b/llvm/lib/Target/BPF/BPFRegisterInfo.cpp @@ -69,14 +69,13 @@ static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL, } const Function &F = MF.getFunction(); - DiagnosticInfoUnsupported DiagStackSize( + F.getContext().diagnose(DiagnosticInfoUnsupported( F, "Looks like the BPF stack limit is exceeded. " "Please move large on stack variables into BPF per-cpu array map. For " "non-kernel uses, the stack can be increased using -mllvm " "-bpf-stack-size.\n", - DL); - F.getContext().diagnose(DiagStackSize); + DL)); } } diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp index cfdd5247149c28..18b4c7117c9cd4 100644 --- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp +++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp @@ -57,9 +57,9 @@ class OpLowerer { if (Error E = ReplaceCall(CI)) { std::string Message(toString(std::move(E))); - DiagnosticInfoUnsupported Diag(*CI->getFunction(), Message, - CI->getDebugLoc()); - M.getContext().diagnose(Diag); + M.getContext().diagnose(DiagnosticInfoUnsupported( + *CI->getFunction(), Message, CI->getDebugLoc())); + return true; } } diff --git a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp index e0dce3d750ed1f..625de759eb831c 100644 --- a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp +++ b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp @@ -45,7 +45,8 @@ class DiagnosticInfoTranslateMD : public DiagnosticInfo { /// \p M is the module for which the diagnostic is being emitted. \p Msg is /// the message to show. Note that this class does not copy this message, so /// this reference must be valid for the whole life time of the diagnostic. - DiagnosticInfoTranslateMD(const Module &M, const Twine &Msg, + DiagnosticInfoTranslateMD(const Module &M, + const Twine &Msg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_Unsupported, Severity), Msg(Msg), Mod(M) {} diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp index f496e6f92bef2a..d6a134d9abafdf 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -1996,12 +1996,11 @@ SDValue NVPTXTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, if (STI.getPTXVersion() < 73 || STI.getSmVersion() < 52) { const Function &Fn = DAG.getMachineFunction().getFunction(); - DiagnosticInfoUnsupported NoDynamicAlloca( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( Fn, "Support for dynamic alloca introduced in PTX ISA version 7.3 and " "requires target sm_52.", - SDLoc(Op).getDebugLoc()); - DAG.getContext()->diagnose(NoDynamicAlloca); + SDLoc(Op).getDebugLoc())); auto Ops = {DAG.getConstant(0, SDLoc(), Op.getValueType()), Op.getOperand(0)}; return DAG.getMergeValues(Ops, SDLoc()); @@ -2037,12 +2036,11 @@ SDValue NVPTXTargetLowering::LowerSTACKRESTORE(SDValue Op, if (STI.getPTXVersion() < 73 || STI.getSmVersion() < 52) { const Function &Fn = DAG.getMachineFunction().getFunction(); - DiagnosticInfoUnsupported NoStackRestore( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( Fn, "Support for stackrestore requires PTX ISA version >= 7.3 and target " ">= sm_52.", - DL.getDebugLoc()); - DAG.getContext()->diagnose(NoStackRestore); + DL.getDebugLoc())); return Op.getOperand(0); } @@ -2060,12 +2058,11 @@ SDValue NVPTXTargetLowering::LowerSTACKSAVE(SDValue Op, if (STI.getPTXVersion() < 73 || STI.getSmVersion() < 52) { const Function &Fn = DAG.getMachineFunction().getFunction(); - DiagnosticInfoUnsupported NoStackSave( + DAG.getContext()->diagnose(DiagnosticInfoUnsupported( Fn, "Support for stacksave requires PTX ISA version >= 7.3 and target >= " "sm_52.", - DL.getDebugLoc()); - DAG.getContext()->diagnose(NoStackSave); + DL.getDebugLoc())); auto Ops = {DAG.getConstant(0, DL, Op.getValueType()), Op.getOperand(0)}; return DAG.getMergeValues(Ops, DL); } diff --git a/llvm/lib/Transforms/Instrumentation/KCFI.cpp b/llvm/lib/Transforms/Instrumentation/KCFI.cpp index bfed6788549435..f4cb4e2d1c9e19 100644 --- a/llvm/lib/Transforms/Instrumentation/KCFI.cpp +++ b/llvm/lib/Transforms/Instrumentation/KCFI.cpp @@ -37,7 +37,7 @@ class DiagnosticInfoKCFI : public DiagnosticInfo { const Twine &Msg; public: - DiagnosticInfoKCFI(const Twine &DiagMsg, + DiagnosticInfoKCFI(const Twine &DiagMsg LLVM_LIFETIME_BOUND, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {} void print(DiagnosticPrinter &DP) const override { DP << Msg; }