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/MachineSink.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'backend/lib/CodeGen/MachineSink.cpp') diff --git a/backend/lib/CodeGen/MachineSink.cpp b/backend/lib/CodeGen/MachineSink.cpp index 176b75a..7c540e0 100644 --- a/backend/lib/CodeGen/MachineSink.cpp +++ b/backend/lib/CodeGen/MachineSink.cpp @@ -61,11 +61,6 @@ namespace { return Stage == MachineCodeMotionStage::SelectedSSA ? Selected : PostRA; } -[[nodiscard]] Error prefixedError(const Error &Failure, std::string Prefix) { - Prefix.append(Failure.message()); - return Error(Failure.code(), std::move(Prefix)); -} - [[nodiscard]] bool hasProtectedAttachment(const MachineInstr &Instruction) noexcept { return Instruction.debugInstrNumber() != 0 || Instruction.preInstrSymbol().has_value() || Instruction.postInstrSymbol().has_value() || Instruction.heapAllocMarker().has_value() || @@ -366,7 +361,8 @@ Expected MachineSinkPass::run(MachineFunction &Function, Function, Target, MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); if (!Trial) { - return std::unexpected(prefixedError(Trial.error(), "machine sink transaction setup failed: ")); + return std::unexpected( + withErrorContext(Trial.error(), "machine sink transaction setup failed: ")); } MachineFunctionAnalysisManager TrialAnalyses; auto TrialResult = runImplementation(*Trial->ClonedFunction, Target, TrialAnalyses); @@ -375,7 +371,7 @@ Expected MachineSinkPass::run(MachineFunction &Function, auto Result = runImplementation(Function, Target, Analyses); if (!Result) { - return std::unexpected(prefixedError( + return std::unexpected(withErrorContext( Result.error(), "machine sink diverged after a successful transaction preflight: ")); } return Result; -- cgit v1.2.3