LLVM Test Error: Could not turn '' into Itanium ABI triple

I want to do some test for riscv intrinsic functions, including clang and llvm;

based on test-suite Guide — LLVM 18.0.0git documentation

First, I will compile my LLVM (16.0.4) with the following configuration:

cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang" \
      -DLLVM_TARGETS_TO_BUILD="RISCV" \
      -DCMAKE_C_COMPILER=clang \
      -DCMAKE_CXX_COMPILER=clang++ \
      -DLLVM_ENABLE_LLD=ON \
      -DCMAKE_BUILD_TYPE="Release" \
      -DLLVM_INCLUDE_TESTS=ON \
      -DLLVM_BUILD_TESTS=ON \
      -DLLVM_BUILD_DOCS=OFF \
      -DLLVM_ENABLE_ASSERTIONS=ON \
      ../llvm

Then use the command to test clang :

llvm it clang/test/CodeGen/RISCV/rvv intrinsics automated/policy/overloaded/vfsub. c

The error message is as follows :

llvm-lit: /home/code/llvm/llvm-project/llvm/utils/lit/lit/llvm/config.py:459: note: using clang: /home/llvm/xpu/llvm-project/build/bin/clang
llvm-lit: /home/code/llvm/llvm-project/llvm/utils/lit/lit/llvm/config.py:324: fatal: Could not turn '' into Itanium ABI triple

because I am testing on an x86 machine, I suspect this may be related to cross compilation testing, but I don’t know how to configure it to make llvm lit recognize riscv;

Currently, I have found a way to update the configuration - DLLVM_ TARGET_ TO_ BUILD=“RISCV; X86” , then recompiled and this testcase passed , so what the reason is?

llvm-lit: /home/code/llvm/llvm-project/llvm/utils/lit/lit/llvm/config.py:459: note: using clang: /home/code/llvm/llvm-project/build/bin/clang
-- Testing: 1 tests, 1 workers --
PASS: Clang :: CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vfsub.c (1 of 1)

Testing Time: 0.22s
  Passed: 1

hope to receive your answer, thank you !

That error comes from llvm-project/llvm/utils/lit/lit/llvm/config.py at 3bcee8568a203c9c9a4c487ebdd0e95fea96f619 · llvm/llvm-project · GitHub.

So if you want to investigate, that’s the starting point.

I guess that the host triple is not detected early on and that means config.host_triple is empty later, but the code does guard against that already so there must be something more to it.

@DavidSpickett
yes , if my build_target is only riscv , the triple is empty;
if build_target is riscv and x86, the triple is x86_64-unknown-linux-gnu, and llvm-lit can run both riscv and x86 testcase.

One workaround is to set a default target for clang, add this to your CMake config:

-DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-linux-gnu"

(adjust as needed)

Your mileage may vary there though as testing without host target support is not very common. I know of downstream users who enable X86 (their host) in addition to their target just to get the test coverage and sidestep issues like this.

[llvm][lit] Handle case when there is no llvm default target triple by DavidSpickett · Pull Request #76934 · llvm/llvm-project · GitHub to make this work out of the box.

You will get a lot of failures when running the entire test suite though, so I’d just add the host target (x86) and save yourself some hassle later.

@DavidSpickett
Thank you for your help. The two solutions you provided are both works .