jkmcnk / sx-gcc

The GNU Compiler Collection port to NEC SX CPU architecture.
GNU General Public License v2.0
0 stars 2 forks source link

problem with builtin snprintf & friends #88

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
testcase gcc.c-torture/execute/builtins/snprintf-chk.c abort()s at
snprintf-chk.c:82, in test1() when built with -O>0. the buffer does not
contain '... - b ...' but '... - A ...'.

needs further checking, however, I have a hunch that this could be a
manifestation of issue 84 (that's my feminine, intuitive side again) again.
must check the generated assembly ...

Original issue reported on code.google.com by jmoc...@gmail.com on 12 Jan 2009 at 11:37

GoogleCodeExporter commented 8 years ago
probably sprintf-chk.c suffers from the same problem.

Original comment by jmoc...@gmail.com on 12 Jan 2009 at 11:38

GoogleCodeExporter commented 8 years ago
as suspected, the problem is in pointer dereferencing. here is a minimal 
testcase:

#include <stdarg.h>
#include <string.h>

int l = 0;
char *ptr = "blabla";
char *init = "1234567890";
char buf[32];
char b = 'b';

extern sprintf(char *s, char *fmt, ...);
extern void abort();

int
main(int argc, char *argv)
{
    strcpy(buf, init);
    sprintf(buf, "%d - %c", (int)(l + 12), *ptr);
    if(buf[5] != 'b')
        abort();
    return 0;
}

replacing *ptr with (char)'b' works. also putting an ordinary (not dereferenced 
ptr)
char var there works.

Original comment by jmoc...@gmail.com on 15 Jan 2009 at 11:52

GoogleCodeExporter commented 8 years ago
indeed, this is a dup of issue 84.

when minimal test case above is built with -O1, the initial expansion of the
dereferencing of the ptr loads mem from address in psuedo reg 147:

(insn 31 30 32 (set (reg:SI 148)
        (zero_extend:SI (mem:QI (reg/f:DI 147) [0 S1 A8]))) -1 (nil)
    (nil))

all fine and dandy, except for the fact that nothing was ever loaded to reg 
147, and
in particular not ptr address, which we'd expect ...

Original comment by jmoc...@gmail.com on 15 Jan 2009 at 12:20