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/MachineBranchRelaxation.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'backend/lib/CodeGen/MachineBranchRelaxation.cpp') diff --git a/backend/lib/CodeGen/MachineBranchRelaxation.cpp b/backend/lib/CodeGen/MachineBranchRelaxation.cpp index c11ed8e..9f14fc4 100644 --- a/backend/lib/CodeGen/MachineBranchRelaxation.cpp +++ b/backend/lib/CodeGen/MachineBranchRelaxation.cpp @@ -47,11 +47,6 @@ struct MachineLayout final { return Contract; } -[[nodiscard]] Error prefixedError(const Error &Failure, std::string Prefix) { - Prefix.append(Failure.message()); - return Error(Failure.code(), std::move(Prefix)); -} - [[nodiscard]] Expected alignTo(std::uint64_t Value, std::uint64_t Alignment) { if (Alignment == 0 || (Alignment & (Alignment - 1U)) != 0) return makeUnexpected(ErrorCode::VerificationError, "block alignment is not a power of two"); @@ -118,7 +113,7 @@ MachineBranchRelaxationPass::run(MachineFunction &Function, const TargetDescript Function, Target, MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); if (!Trial) - return std::unexpected(prefixedError(Trial.error(), "branch relaxation setup failed: ")); + return std::unexpected(withErrorContext(Trial.error(), "branch relaxation setup failed: ")); MachineActionReplay Actions(Analyses, Trial->InstructionStableIDs); auto TrialResult = runImplementation(*Trial->ClonedFunction, Target, Actions); if (!TrialResult) @@ -126,7 +121,7 @@ MachineBranchRelaxationPass::run(MachineFunction &Function, const TargetDescript Actions.beginReplay(); auto Result = runImplementation(Function, Target, Actions); if (!Result) { - return std::unexpected(prefixedError( + return std::unexpected(withErrorContext( Result.error(), "branch relaxation diverged after a successful transaction preflight: ")); } auto Replayed = Actions.finishReplay(); -- cgit v1.2.3