[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
Fri Dec 1 08:25:45 PST 2023


yonghong-song wrote:

> I tried building with `LLVM_ENABLE_ASSERTIONS=OFF` and the following example still does not produce error:
> 
> ```
> $ cat test-asm-ll.c
> int foo(void)
> {
>   asm volatile ("r1 = 10 + w3 ll;");
>   return 0;
> }
> $ clang -target bpf -c test-asm-ll.c -o - | llvm-objdump -d -
> ...
> 0000000000000000 <foo>:
>        0:	18 01 00 00 0a 00 00 00 00 00 00 00 00 00 00 00	r1 = 0xa ll
>        2:	b7 00 00 00 00 00 00 00	r0 = 0x0
>        3:	95 00 00 00 00 00 00 00	exit
> ```

@eddyz87 The following is my cmake command line:
```
cd llvm-project/llvm/build
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja \
    -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" \
    -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
    -DLLVM_ENABLE_ASSERTIONS=OFF \
    -DLLVM_ENABLE_ZLIB=ON \
    -DCMAKE_INSTALL_PREFIX=$PWD/install

ninja && ninja install
```
And confirms assertion is indeed off with the build
```
[~/work/llvm-project/llvm/build (debug-asm)]$ grep LLVM_ENABLE_ASSERTIONS CMakeCache.txt 
LLVM_ENABLE_ASSERTIONS:BOOL=OFF
```
Top commit
```
commit a4d9a52927213dd5b0087704e52641741202f88b (HEAD -> debug-asm)
Author: Yonghong Song <yonghong.song at linux.dev>
Date:   Thu Nov 30 09:11:14 2023 -0800

    debug asm

commit ba523106579fd26d52e16c1a6f4eeb839d84351f
Author: Alexey Bataev <5361294+alexey-bataev at users.noreply.github.com>
Date:   Thu Nov 30 10:04:57 2023 -0500

    [SLP][NFC] Unify code for cost estimation/codegen for buildvector, NFC. (#73182)
    
    This just moves towards reusing same function for both cost
    estimation/codegen for buildvector.

[~/work/llvm-project/llvm/build (debug-asm)]$ git show
commit a4d9a52927213dd5b0087704e52641741202f88b (HEAD -> debug-asm)
Author: Yonghong Song <yonghong.song at linux.dev>
Date:   Thu Nov 30 09:11:14 2023 -0800

...

diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp
index 15ab55f95e69..c266538bec73 100644
--- a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp
+++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp
@@ -36,15 +36,16 @@ void BPFInstPrinter::printInst(const MCInst *MI, uint64_t Address,
 }
 
 static void printExpr(const MCExpr *Expr, raw_ostream &O) {
-#ifndef NDEBUG
   const MCSymbolRefExpr *SRE;
 
   if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr))
     SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
   else
     SRE = dyn_cast<MCSymbolRefExpr>(Expr);
-  assert(SRE && "Unexpected MCExpr type.");
+  if (!SRE)
+    report_fatal_error("Unexpected MCExpr type.");
 
+#ifndef NDEBUG
   MCSymbolRefExpr::VariantKind Kind = SRE->getKind();
 
   assert(Kind == MCSymbolRefExpr::VK_None);
```

The test
```
[~/tmp1]$ which clang                                                                                                                 
~/work/llvm-project/llvm/build/install/bin/clang                                                                                                         
[yhs at devbig309.ftw3 ~/tmp1]$ cat t.c                                                                                                                     
  int                                                                                                                                                    
  foo ()                                                                                                                                                 
  {                                                                                                                                                      
    asm volatile ("r1 = 10 + w3 ll");                                                                                                                    
    return 0;                                                                                                                                            
  }                                                                                                                                                      
[~/tmp1]$ clang --target=bpf -O2 -g -S t.c                                                                                            
fatal error: error in backend: Unexpected MCExpr type.                                                                                                   
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run scrip
t.                                                   
...
```

Did I miss anything?


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


More information about the llvm-commits mailing list