Skip to content

Commit

Permalink
Fix casting issues (missing func_vt in riscvgen.c):
Browse files Browse the repository at this point in the history
When compiling a file like:

    long cast_charp_to_long (char const *i)
    {
      return (long)i;
    }

    long cast_int_to_long (int i)
    {
      return (long)i;
    }

    long cast_voidp_to_long (void const *i)
    {
      return (long)i;
    }

    void main(int argc, char* argv[]){
        unsigned long a = 19;
        char b = a;
        return;
    }

We had this error message:

    cannot cast from/to void

It happened because the return type of the functions (`func_vt`) was not
set properly by `riscv-gen.c` and it was VT_VOID by default. In the
`mob` branch they moved all this code to `tccgen.c` to avoid repeating
it in every single architecture, but that made me miss it during the
backport of the RISC-V backend.

This commit adds that piece of code but there might be more places where
a similar thing happens.
  • Loading branch information
ekaitz-zarraga committed Aug 5, 2023
1 parent aa727e5 commit 6fbd178
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion riscv64-gen.c
Expand Up @@ -928,8 +928,11 @@ ST_FUNC void gfunc_prolog(CType *func_type)
addr = 0;
/* if the function returns by reference, then add an
implicit pointer parameter */
func_vt = sym->type;
func_var = (sym->c == FUNC_ELLIPSIS);
size = type_size(&func_vt, &align);
if (size > 2 * XLEN) {
if (((func_vt.t & VT_BTYPE) == VT_STRUCT)
&& (size > 2 * XLEN)) {
loc -= 8;
func_vc = loc;
ES(0x23, 3, 8, 10 + areg[0]++, loc); // sd a0, loc(s0)
Expand Down

0 comments on commit 6fbd178

Please sign in to comment.