[RISCV][CLANG][CODEGEN] Possible bug in clang

Good morning/day/night!

I was messing around with riscv inline assembly (just load a value into the specific register)

link:

on clang-riscv64 it shows me an error while on gcc-riscv64 it normally inlines that assembly into the resulting image

is there a bug in my code/a bug in gcc/a bug in clang?

thanks

I’m not into RISC-V, but this is worth a bug report at Issues · llvm/llvm-project · GitHub

1 Like

This seems like the implementation difference about operand constraint for the immediate operand, Simple Constraints (Using the GNU Compiler Collection (GCC)).

  • clang refuses any value if its constraint is ‘r’(general register), although gcc accepts value as an immediate value. Compiler Explorer
  • clang accepts any value if its constraint is ‘i’(immediate value), although gcc denies local scope variables. Compiler Explorer

Although I’m not sure about what is correct/better…

1 Like

I see. So it was a problem in my code and not clang’s issue

thanks for your explanation

TOPIC RESOLVED

1 Like

GCC doesn’t parse assembly, it merely generates it and, if you compile to a binary object (which Compiler Explorer does not do by default) will invoke the assembler on it, which would give an error that you’re trying to use a register operand as the immediate value for li if enabled. Clang/LLVM, meanwhile, will parse the assembly even if it’s emitting assembly again, using its integrated assembler (contrasting with GCC where the assembler is a separate program from a separate project, binutils) and so always gives that error. Your code is wrong and neither toolchain will produce an object file for it, but GCC will let you produce assembly for it.

1 Like

thanks for your reply

not only inline assembly is wrong, but also riscv does not have an “a15” register

my example is absolute garbage and MUST BE burned down with a flamethrower