From 8558f80b4077536d6aa46b97328d6df1210e261f Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Thu, 13 Aug 2026 13:18:05 +0800 Subject: [Support] Centralize error context handling --- backend/lib/CodeGen/MachineFallthrough.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'backend/lib/CodeGen/MachineFallthrough.cpp') diff --git a/backend/lib/CodeGen/MachineFallthrough.cpp b/backend/lib/CodeGen/MachineFallthrough.cpp index 608b703..3619155 100644 --- a/backend/lib/CodeGen/MachineFallthrough.cpp +++ b/backend/lib/CodeGen/MachineFallthrough.cpp @@ -36,11 +36,6 @@ namespace { return Contract; } -[[nodiscard]] Error prefixedError(const Error &Failure, std::string Prefix) { - Prefix.append(Failure.message()); - return Error(Failure.code(), std::move(Prefix)); -} - [[nodiscard]] Expected> normalizeFallthroughs(MachineFunction &Function, const TargetDescription &Target, const TargetInstrInfo &Info) { @@ -129,7 +124,7 @@ Expected MachineFallthroughPass::run(MachineFunction &Functio Function, Target, MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); if (!Trial) - return std::unexpected(prefixedError(Trial.error(), "fallthrough setup failed: ")); + return std::unexpected(withErrorContext(Trial.error(), "fallthrough setup failed: ")); MachineFunctionAnalysisManager TrialAnalyses; auto TrialLiveness = TrialAnalyses.getResult(*Trial->ClonedFunction, Target); @@ -147,8 +142,8 @@ Expected MachineFallthroughPass::run(MachineFunction &Functio return std::unexpected(Liveness.error()); auto ChangedBlocks = normalizeFallthroughs(Function, Target, *Info); if (!ChangedBlocks) { - return std::unexpected(prefixedError(ChangedBlocks.error(), - "fallthrough diverged after a successful preflight: ")); + return std::unexpected(withErrorContext(ChangedBlocks.error(), + "fallthrough diverged after a successful preflight: ")); } auto Repaired = repairPostRAMachineBlockLiveness(*ChangedBlocks, Target, **Liveness); if (!Repaired) -- cgit v1.2.3