decompals / ido-static-recomp

IDO static recomp
43 stars 10 forks source link

`cfe` error-printing bug #58

Closed EllipticEllipsis closed 1 year ago

EllipticEllipsis commented 1 year ago

We've seen issues on decomp.me before with cfe printing invalid unicode in error messages. Here is a small example that does it: https://decomp.me/scratch/FM48C . This can be reproduced locally with the current branch of recomp, copy the contents of the scratch and run with

build/5.3/out/cfe  code.c -Xwoff649,838,712   -verbose   -XScode.T -Xcpluscomm -Xsigned -EB -Xg0 -O2 > code.B 

@AngheloAlf checked on qemu and it is a recomp bug rather than an IDO one

cfe: Error: code.c, line 777: 'sp108' undefined; reoccurrences will not be reported.
     for (var_s2_2 = 0; var_s2_2 < sp108; var_s2_2++) {
 ----------------------------------^
cfe: c code.c, c  780: 'temp_t9_9' undefined; reoccurrences will not be reported.
             temp_t9_9 = &st_pchdr->pfd[var_s1];
 ------------^

(it should say Error: code.c, line 780: etc.) The junk is affected by the file contents, it's not consistent: https://decomp.me/scratch/3VCNG

Compiler error: cfe: Error: code.c, line 441: 'temp_t4' undefined; reoccurrences will not be reported.
                             var_a2_2 = temp_t4;
 ---------------------------------------^
cfe: V\xd8code.c, V\xd8 442: 'temp_a3' undefined; reoccurrences will not be reported.
                             var_a1_2 = temp_a3;
 ---------------------------------------^

This appears to only happen when -verbose is passed, at least in this example. The function responsible for printing the errors is func_40ff80, which does a lot of strcpying and freading out of the err.english.cc file, at some point the pointer it uses seems to be dodgy but I haven't figured out why. The buffer it prints the wrong thing to is at 0x1001C7C8 in 5.3, and some of the wrong things look like addresses, for example

FREAD: 
DUMP OF MEMORY REGION 0x100E0010-0x100E0018:
100E0010  45 72 72 6F 72 3A 20 0A                          Error: .

STRCAT CALLED: DEST: ( 0x1001B7C8, "cfe: ", SRC: (0x1001C7C8, "Error: ")

vs

FREAD: 
DUMP OF MEMORY REGION 0x100DE184-0x100DE18C:
100DE184  10 06 62 F0 00 00 03 1D                          ..b.....

STRCAT CALLED: DEST: ( 0x1001B7C8, "cfe: ", SRC: (0x1001C7C8, "b�")

(the b one is the glitch I get locally, which is slightly different from the decomp.me one).

It's consistent between program runs, too, afaics.

EllipticEllipsis commented 1 year ago

https://decomp.me/scratch/CiO9u shows something I hadn't noticed before, that this bug is actually present for any error message that has a verbose part of length 0, and it can be reset by one that does not have length 0. I'm still not sure where the problem is, though...