riscv-software-src / riscv-pk

RISC-V Proxy Kernel
Other
579 stars 306 forks source link

Eliminate Wuninitialized for Clang/LLVM #266

Closed ZenithalHourlyRate closed 2 years ago

ZenithalHourlyRate commented 2 years ago
/home/zenithal/T/playground/dependencies/riscv-pk/pk/console.c:68:43: error: variable 'ra' is uninitialized when used here [-Werror,-Wuninitialized]
  do_panic("assertion failed @ %p: %s\n", ra, s);
                                          ^~
/home/zenithal/T/playground/dependencies/riscv-pk/pk/console.c:67:24: note: initialize the variable 'ra' to silence this warning
  register uintptr_t ra asm ("ra");
                       ^
                        = 0
1 error generated.

Though this seems to be the fault of Clang.

aswaterman commented 2 years ago

Workaround seems fine.

MaskRay commented 2 years ago

Note this paragraph on https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables

Defining a register variable does not reserve the register.

register uintptr_t ra asm ("ra"); not used as an input into an asm statement does not guarantee the value. Consider __builtin_return_address().

See #268