[llvm] Object: Don't error out on malformed bitcode files. (PR #96848)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 00:56:55 PDT 2024


================
@@ -9,37 +10,52 @@
 # RUN: llvm-as input.ll -o input.bc
 # RUN: cp input.bc good.bc
 # RUN: %python -c "with open('input.bc', 'a') as f: f.truncate(10)"
-# RUN: not llvm-ar rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1
+# RUN: llvm-ar rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=WARN1
+
+# llvm-nm will fail when it tries to read the malformed bitcode file, but
+# it's supposed to print the archive map first, which in this case it
+# won't because there won't be one.
+# RUN: not llvm-nm --print-armap bad.a | count 0
----------------
jh7370 wrote:

I must admit, I thought a `CHECK-FIRST` directive was added to FileCheck, to allow that, but evidently not. If you did want to check that something is the first line though, I think you can do something like this:
```
# CHECK: {{^}}
# CHECK-SAME: thing I'm interested in
```
This works, because the `{{^}}` matches the start of the line, and since every line has a start, it matches specifically the first line. The `CHECK-SAME` then pins the thing it's checking to the previously-matched line, i.e. the first line.

(I am ambivalent on whether you should do this for this specific case, but I think it may be worth a comment explaining why you're doing this llvm-nm invocation here either way)

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


More information about the llvm-commits mailing list