diff --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp b/llvm/lib/Target/BPF/BPFISelLowering.cpp --- a/llvm/lib/Target/BPF/BPFISelLowering.cpp +++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp @@ -35,22 +35,20 @@ cl::Hidden, cl::init(false), cl::desc("Expand memcpy into load/store pairs in order")); -static void fail(const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg) { - MachineFunction &MF = DAG.getMachineFunction(); - DAG.getContext()->diagnose( - DiagnosticInfoUnsupported(MF.getFunction(), Msg, DL.getDebugLoc())); -} - -static void fail(const SDLoc &DL, SelectionDAG &DAG, const char *Msg, - SDValue Val) { - MachineFunction &MF = DAG.getMachineFunction(); +[[noreturn]] static void fail(const SDLoc &DL, SelectionDAG &DAG, + const Twine &Msg, + std::optional Val = std::nullopt) { std::string Str; raw_string_ostream OS(Str); - OS << Msg; - Val->print(OS); + Function &F = DAG.getMachineFunction().getFunction(); + OS << "in function " << F.getName() << ' ' << F.getFunctionType() << ": " + << Msg; + if (Val.has_value()) { + Val.value()->print(OS); + } + OS << '\n'; OS.flush(); - DAG.getContext()->diagnose( - DiagnosticInfoUnsupported(MF.getFunction(), Str, DL.getDebugLoc())); + report_fatal_error(Twine(Str)); } BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM, @@ -261,7 +259,8 @@ uint32_t Opcode = N->getOpcode(); switch (Opcode) { default: - report_fatal_error("Unhandled custom legalization"); + err_msg = "Unhandled custom legalization"; + break; case ISD::ATOMIC_LOAD_ADD: case ISD::ATOMIC_LOAD_AND: case ISD::ATOMIC_LOAD_OR: @@ -303,7 +302,7 @@ SelectionDAG &DAG, SmallVectorImpl &InVals) const { switch (CallConv) { default: - report_fatal_error("Unsupported calling convention"); + fail(DL, DAG, "Unsupported calling convention"); case CallingConv::C: case CallingConv::Fast: break; @@ -317,15 +316,17 @@ CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext()); CCInfo.AnalyzeFormalArguments(Ins, getHasAlu32() ? CC_BPF32 : CC_BPF64); - for (auto &VA : ArgLocs) { + size_t NumExcessArgs = 0; + for (size_t I = 0; I < ArgLocs.size(); ++I) { + auto &VA = ArgLocs[I]; if (VA.isRegLoc()) { // Arguments passed in registers EVT RegVT = VA.getLocVT(); MVT::SimpleValueType SimpleTy = RegVT.getSimpleVT().SimpleTy; switch (SimpleTy) { default: { - errs() << "LowerFormalArguments Unhandled argument type: " - << RegVT << '\n'; + errs() << "LowerFormalArguments Unhandled argument type: " << RegVT + << '\n'; llvm_unreachable(nullptr); } case MVT::i32: @@ -349,13 +350,19 @@ InVals.push_back(ArgValue); - break; + break; } } else { - fail(DL, DAG, "defined with too many args"); - InVals.push_back(DAG.getConstant(0, DL, VA.getLocVT())); + NumExcessArgs++; } } + if (NumExcessArgs != 0) { + std::string Str; + raw_string_ostream OS(Str); + OS << "attempts to read " << NumExcessArgs + << " args from the stack, defined with too many args"; + fail(DL, DAG, Str); + } if (IsVarArg || MF.getFunction().hasStructRetAttr()) { fail(DL, DAG, "functions with VarArgs or StructRet are not supported"); @@ -384,7 +391,7 @@ switch (CallConv) { default: - report_fatal_error("Unsupported calling convention"); + fail(CLI.DL, DAG, "Unsupported calling convention"); case CallingConv::Fast: case CallingConv::C: break;