Skip to content

Commit 32d5351

Browse files
yonghong-songYonghong Song
andauthored
BPF: Emit an error for illegal LD_imm64 insn when LLVM_ENABLE_ASSERTI… (#74035)
…ONS=OFF Jose reported an issue ([1]) where for the below illegal asm code ``` r0 = 1 + w3 ll ``` clang actually supports it and generates the object code. Further investigation finds that clang actually intends to reject the above code as well but only when the clang is built with LLVM_ENABLE_ASSERTIONS=ON. I later found that clang16 (built by redhat and centos) in fedora system has the same issue since they also have LLVM_ENABLE_ASSERTIONS=OFF ([2]). So let BPF backend report an error for the above case regardless of the LLVM_ENABLE_ASSERTIONS setting. [1] https://lore.kernel.org/bpf/[email protected]/#t [2] https://lore.kernel.org/bpf/[email protected]/ Co-authored-by: Yonghong Song <[email protected]>
1 parent 0928312 commit 32d5351

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ void BPFInstPrinter::printInst(const MCInst *MI, uint64_t Address,
3636
}
3737

3838
static void printExpr(const MCExpr *Expr, raw_ostream &O) {
39-
#ifndef NDEBUG
4039
const MCSymbolRefExpr *SRE;
4140

4241
if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr))
4342
SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
4443
else
4544
SRE = dyn_cast<MCSymbolRefExpr>(Expr);
46-
assert(SRE && "Unexpected MCExpr type.");
45+
if (!SRE)
46+
report_fatal_error("Unexpected MCExpr type.");
4747

48+
#ifndef NDEBUG
4849
MCSymbolRefExpr::VariantKind Kind = SRE->getKind();
4950

5051
assert(Kind == MCSymbolRefExpr::VK_None);

0 commit comments

Comments
 (0)