llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.05k stars 11.98k forks source link

clang riscv64 target accepts rv32 -march option (and vice versa) #90470

Open DavidSpickett opened 6 months ago

DavidSpickett commented 6 months ago

The following does not error or warn:

$ ./bin/clang /tmp/test.c -target riscv64 -march=rv32i -o - -S

And it produces code according to the value of -march:

        .text
        .attribute      4, 16
        .attribute      5, "rv32i2p1"

The opposite also works:

$ ./bin/clang /tmp/test.c -target riscv32 -march=rv64i -o - -S

I assume I have to pick one of -target riscv32 and -target riscv64 because if I use -target riscv I get:

$ ./bin/clang /tmp/test.c -target riscv -march=rv64i -o - -S
clang: error: unsupported option '-march=' for target 'riscv'

Which itself is a bit unclear because I'm not sure riscv is even a valid target to begin with, but this is not RISC-V specific:

$ ./bin/clang /tmp/test.c -target aardvark -march=rv64i -o - -S
clang: error: unsupported option '-march=' for target 'aardvark'
llvmbot commented 6 months ago

@llvm/issue-subscribers-backend-risc-v

Author: David Spickett (DavidSpickett)

The following does not error or warn: ``` $ ./bin/clang /tmp/test.c -target riscv64 -march=rv32i -o - -S ``` And it produces code according to the value of `-march`: ``` .text .attribute 4, 16 .attribute 5, "rv32i2p1" ``` The opposite also works: ``` $ ./bin/clang /tmp/test.c -target riscv32 -march=rv64i -o - -S ``` I assume I have to pick one of `-target riscv32` and `-target riscv64` because if I use `-target riscv` I get: ``` $ ./bin/clang /tmp/test.c -target riscv -march=rv64i -o - -S clang: error: unsupported option '-march=' for target 'riscv' ``` Which itself is a bit unclear because I'm not sure `riscv` is even a valid target to begin with, but this is not RISC-V specific: ``` $ ./bin/clang /tmp/test.c -target aardvark -march=rv64i -o - -S clang: error: unsupported option '-march=' for target 'aardvark' ```
asb commented 6 months ago

Thanks David, agreed this is potentially confusing. The logic that made -march override --target was added in https://reviews.llvm.org/D54214.

Options seem to be:

What do people think? CC @simonpcook as original patch author.

EDIT: Though the other configuration is how this interacts with however clang gets the target triple. e.g. if it's taken from a prefix on the binary name, then it arguably should be acceptable to override with -march. This matches what i can do with my distro-install riscv64-*-gcc toolchains, when I want to emit at least assembly for rv32 to check something.