[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] compare problem on riscv target

From: Michael Matz
Subject: Re: [Tinycc-devel] compare problem on riscv target
Date: Thu, 16 Jul 2020 17:59:00 +0200 (CEST)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)


On Thu, 16 Jul 2020, Herman ten Brugge via Tinycc-devel wrote:

While testing gmp on the riscv target I discovered a compare bug.
(t-get_d test fails in directory tests/mpq)

The code:

#include <stdio.h>

int tst(void) {
  long value = 3;
  return -value;

int main(void) {
  printf ("%d\n", tst());
  if (tst() > 0) printf ("error\n");
  return 0;

prints "error" on the riscv target. The problem is that the value returned is
converted from long to int in gen_cast and is returned as 0xfffffffd from tst().

On riscv registers should always contain the sign-extended value of shorter values, so this here is the bug, and ...

The compare in the main code fails because it does a long compare

... this is the okay because of the above invariant.

TCCs other architectures expect either zero extension or don't care or natural extension about narrow values in large registers, so riscv was somewhat novel in that respect; obviously I didn't catch all corner cases yet, so thanks for the report.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]