[llvm] BPF: Emit an error for illegal LD_imm64 insn when LLVM_ENABLE_ASSERTI… (PR #74035)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 16:27:23 PST 2023


yonghong-song wrote:

> For me, when assertions are enabled, the error is reported not in `printExpr`, but in `BPFMCCodeEmitter::getMachineOpValue`:
> ...
> 
> Subsequently, the following modification works with both assertions on and off:
> 
> ```diff
> diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
> index b807d6904004..4f4ebdabf810 100644
> --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
> +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
> @@ -89,6 +89,14 @@ unsigned BPFMCCodeEmitter::getMachineOpValue(const MCInst &MI,
>  
>    const MCExpr *Expr = MO.getExpr();
>  
> +  if (Expr->getKind() != MCExpr::SymbolRef) {
> +    std::string Msg;
> +    llvm::raw_string_ostream S(Msg);
> +    S << "getMachineOpValue: unexpected Expr->getKind() == "
> +      << (unsigned)Expr->getKind() << ": "
> +      << "'" << *Expr << "'" << "\n";
> +    report_fatal_error(StringRef(Msg));
> +  }
>    assert(Expr->getKind() == MCExpr::SymbolRef);
>  
>    if (MI.getOpcode() == BPF::JAL)
> ```
> 
> Still, I think that error should be reported earlier, when expressions are parsed.

The above code is in BPFMCCodeEmitter which is later than my crash point, so I suspect it won't affect my crash signature. Indeed, I applied the above change and my crash pattern remains the same.


https://github.com/llvm/llvm-project/pull/74035


More information about the llvm-commits mailing list