riscv / riscv-test-env

https://jira.riscv.org/browse/RVG-141
Other
42 stars 107 forks source link

False pass in CHECK_XLEN #38

Open wyvernSemi opened 2 years ago

wyvernSemi commented 2 years ago

The RVTEST_CODE_BEGIN macro, defined in riscv_test.h uses macro the CHECK_XLEN macro. This macro is defined as:

#if __riscv_xlen == 64
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bgez a0, 1f; RVTEST_PASS; 1:
#else
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 1f; RVTEST_PASS; 1:
#endif

I believe this is checking that if 1 is shifted 31 bits then this will be a negative for 32 bit and not negative for 64 bit lengths, and will branch if correct. If this is not correct then RVTEST_PASS is executed. I would expect this to be RVTEST_FAIL. A bug in an implementation meant that the code did not branch but then set the test 'passed' criteria and did the ecall. This gave a false positive. and was picked up because a smaller number of instructions were retired than expected.