The cross-compiler gcc-3.4.4 (or 3.4.3) for v850 generates wrong-code for example source bug2.c (see below). The cmp instruction in expression (ps1 ? 1 : 2) was lost in the first scheduling pass (see dump-file bug2.c.23.sched generated by compilation with -da option). The return value of sh_dir() (see below) is random and depends on state of PSW register at return from previous bprintf() call.
Shorted asm listing of wrong-code: ... jarl _x_bprintf,r31 # setf z,r10 # tmp73 add 1,r10 #, <result> ... The wrong-code may be work-arounded by -fno-sched-interblock option. The good-code - shorted asm listing: ... jarl _x_bprintf,r31 # cmp r0,r28 # ps <---(This is the lost instruction) setf z,r10 # tmp73 add 1,r10 #, <result> ... The problem was tested on several linux instalation (Redhat 7.2 on i686, RedHat Enterprise release 4 on x86_64, ...). The source file bug2.c follows: /*****************************************************************/ #define NULL 0 extern const char *f_cwd(const char *s); extern int x_strcmp(const char *s1, const char *s2); extern int x_strncmp(const char *s1, const char *s2, unsigned n); extern int x_bprintf(int f, const char *fmt, ...); typedef struct { char cline[202]; unsigned char out; unsigned short dir; } t_sloc; int sh_dir(t_sloc *sl) { const char *ps=NULL, *ps1; if (x_strcmp(sl->cline, "pwd") == 0) goto label01; if (x_strncmp(sl->cline, "cd ", 3) == 0 && sl->cline[3] > ' ') { ps = sl->cline + 3; label01: if ((ps1 = ps = f_cwd(ps)) == NULL) ps = f_cwd(NULL); if (!ps) return 2; x_bprintf(sl->out, "wd: %s\r\n", ps); sl->dir = ps[1] != 'M'; x_bprintf(1, "ps1=%p, %d\r\n", ps1, 2); /* This occurs wrong code: The state of Z flag of PSW register (cc0) * at end of previous call x_bprintf() * is evaluated instead of ps1 in next line. */ return ps1 ? 1 : 2; } return 0; } /* End of source file*/ /*****************************************************************/ The compiler command line: /usr/local/bin/gcc.v -Wall -Os -mspace -ep -mghs -mno-app-regs -mzda=8 -c -Wa,-a=bug2.lst -fverbose-asm -o bug2.o bug2.c The cross-compiler configure line: ../gcc-3.4.4/configure --prefix=/usr/local/ --host=i586-pc-linux-gnu --target=v850-linux-elf --program-suffix=.v -- Summary: wrong-code unless -fno-sched-interblock Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: seidl at feld dot cvut dot cz GCC build triplet: i586-pc-linux-gnu GCC host triplet: i586-pc-linux-gnu GCC target triplet: v850-linux-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24376