[Bug c/60934] New: Strtoll Function Always Appears to Return 0 on Solaris

william.speak at sophos dot com gcc-bugzilla@gcc.gnu.org
Wed Apr 23 10:25:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60934

            Bug ID: 60934
           Summary: Strtoll Function Always Appears to Return 0 on Solaris
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: william.speak at sophos dot com

This bug seems to happen when two variables of `long long` and `double` are
declared in
a function with the same name.

A minimalistic example:

    // bug.c
    #include <stdio.h>
    #include <stdlib.h>

    int main(int argc, const char* argv[])
    {
            char* value = "12345";
            char* end = NULL;
            double bug;
            {
                    long long bug = 6789;
                    bug = strtoll(value, &end, 10);
                    printf("%ld\n", bug);
            }

            return 0;
    }

Compiling with `gcc bug.c -o bug` and running with `./bug` produces
the follwing output:

    $ ./bug
    0

The expected output would be `12345`. Changing the type of the inner
`bug` to `long` or renaming it fixes the issue and `12345` is printed.

Running `gcc --version`:

    gcc (GCC) 4.8.2
    Copyright (C) 2013 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Running `gcc -v`:
    Using built-in specs.
    COLLECT_GCC=gcc
   
COLLECT_LTO_WRAPPER=/opt/toolchain/libexec/gcc/sparc-sun-solaris2.9/4.8.2/lto-wrapper
    Target: sparc-sun-solaris2.9
    Configured with: ../gcc-4.8.2/configure --prefix=/opt/toolchain
--with-gmp=/opt/toolchain --with-mpfr=/opt/toolchain --with-mpc=/opt/toolchain
--with-gnu-as --with-as=/opt/toolchain/bin/as --without-gnu-ld
--with-ld=/usr/ccs/bin/ld --enable-languages=c,c++ --disable-lto
    Thread model: posix
    gcc version 4.8.2 (GCC)

Running `gcc bug.c -S` produces the following assembly

            .file   "bug.c"
            .section        ".rodata"
            .align 8
    .LLC0:
            .asciz  "12345"
            .align 8
    .LLC1:
            .asciz  "%ld\n"
            .section        ".text"
            .align 4
            .global main
            .type   main, #function
            .proc   04
    main:
            save    %sp, -120, %sp
            st      %i0, [%fp+68]
            st      %i1, [%fp+72]
            sethi   %hi(.LLC0), %g1
            or      %g1, %lo(.LLC0), %g1
            st      %g1, [%fp-4]
            st      %g0, [%fp-20]
            mov     0, %g2
            sethi   %hi(6144), %g3
            or      %g3, 645, %g3
            std     %g2, [%fp-16]
            add     %fp, -20, %g1
            ld      [%fp-4], %o0
            mov     %g1, %o1
            mov     10, %o2
            call    strtoll, 0
             nop
            std     %o0, [%fp-16]
            sethi   %hi(.LLC1), %g1
            or      %g1, %lo(.LLC1), %o0
            ld      [%fp-16], %o1
            ld      [%fp-12], %o2
            call    printf, 0
             nop
            mov     0, %g1
            mov     %g1, %i0
            return  %i7+8
             nop
            .size   main, .-main
            .ident  "GCC: (GNU) 4.8.2"

And finally `bug.i`:

    # 1 "bug.c"
    # 1 "<command-line>"
    # 1 "bug.c"
    # 1
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 1 3 4
    # 14
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    # 1 "/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include/stdarg.h" 1
3 4
    # 40 "/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include/stdarg.h" 3
4
    typedef __builtin_va_list __gnuc_va_list;
    # 15
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 2 3 4
    # 34
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    #pragma ident "@(#)stdio.h      1.79    01/04/16 SMI"

    # 1
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
1 3 4
    # 41
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
3 4
    #pragma ident "@(#)stdio_iso.h  1.2     99/10/25 SMI"


    # 1
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/sys/feature_tests.h"
1 3 4
    # 22
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/sys/feature_tests.h"
3 4
    #pragma ident "@(#)feature_tests.h      1.18    99/07/26 SMI"

    # 1 "/usr/include/sys/isa_defs.h" 1 3 4
    # 9 "/usr/include/sys/isa_defs.h" 3 4
    #pragma ident "@(#)isa_defs.h   1.20    99/05/04 SMI"
    # 25
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/sys/feature_tests.h"
2 3 4
    # 45
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
2 3 4
    # 1
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/sys/va_list.h"
1 3 4
    # 18
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/sys/va_list.h"
3 4
    #pragma ident "@(#)va_list.h    1.13    01/02/08 SMI"
    # 35
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/sys/va_list.h"
3 4
    typedef __builtin_va_list __va_list;
    # 46
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
2 3 4
    # 1
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio_tag.h" 1
3 4
    # 18
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio_tag.h" 3
4
    #pragma ident "@(#)stdio_tag.h  1.3     98/04/20 SMI"
    # 30
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio_tag.h" 3
4
    typedef struct __FILE __FILE;
    # 47
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
2 3 4
    # 1 "/usr/include/stdio_impl.h" 1 3 4
    # 9 "/usr/include/stdio_impl.h" 3 4
    #pragma ident "@(#)stdio_impl.h 1.13    01/11/16 SMI"
    # 22 "/usr/include/stdio_impl.h" 3 4
    typedef int ssize_t;
    # 38 "/usr/include/stdio_impl.h" 3 4
    struct __FILE
    {




     ssize_t _cnt;
     unsigned char *_ptr;

     unsigned char *_base;
     unsigned char _flag;
     unsigned char _file;
     unsigned __orientation:2;
     unsigned __ionolock:1;
     unsigned __seekable:1;
     unsigned __filler:4;
    };
    # 48
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
2 3 4
    # 68
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
3 4
    typedef long long __longlong_t;
    # 84
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
3 4
    typedef __FILE FILE;







    typedef unsigned int size_t;




    typedef long fpos_t;
    # 156
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
3 4
    extern __FILE __iob[20];
    # 173
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/iso/stdio_iso.h"
3 4
    extern int remove(const char *);
    extern int rename(const char *, const char *);
    extern FILE *tmpfile(void);
    extern char *tmpnam(char *);
    extern int fclose(FILE *);
    extern int fflush(FILE *);
    extern FILE *fopen(const char *, const char *);
    extern FILE *freopen(const char *, const char *, FILE *);
    extern void setbuf(FILE *, char *);
    extern int setvbuf(FILE *, char *, int, size_t);

    extern int fprintf(FILE *, const char *, ...);

    extern int fscanf(FILE *, const char *, ...);

    extern int printf(const char *, ...);

    extern int scanf(const char *, ...);

    extern int sprintf(char *, const char *, ...);

    extern int sscanf(const char *, const char *, ...);
    extern int vfprintf(FILE *, const char *, __va_list);
    extern int vprintf(const char *, __va_list);
    extern int vsprintf(char *, const char *, __va_list);
    extern int fgetc(FILE *);
    extern char *fgets(char *, int, FILE *);
    extern int fputc(int, FILE *);
    extern int fputs(const char *, FILE *);


    extern int getc(FILE *);
    extern int putc(int, FILE *);



    extern int getchar(void);
    extern int putchar(int);

    extern char *gets(char *);
    extern int puts(const char *);
    extern int ungetc(int, FILE *);
    extern size_t fread(void *, size_t, size_t, FILE *);
    extern size_t fwrite(const void *, size_t, size_t, FILE *);
    extern int fgetpos(FILE *, fpos_t *);
    extern int fseek(FILE *, long, int);
    extern int fsetpos(FILE *, const fpos_t *);
    extern long ftell(FILE *);
    extern void rewind(FILE *);


    extern void clearerr(FILE *);
    extern int feof(FILE *);
    extern int ferror(FILE *);

    extern void perror(const char *);


    extern int __filbuf(FILE *);
    extern int __flsbuf(int, FILE *);
    # 37
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 2 3 4
    # 109
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    typedef long off_t;







    typedef __longlong_t off64_t;
    # 127
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    typedef __longlong_t fpos64_t;
    # 155
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    extern unsigned char _sibuf[], _sobuf[];
    # 197
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    extern unsigned char *_bufendtab[];
    extern FILE *_lastbuf;
    # 233
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    extern void setbuffer(FILE *, char *, size_t);
    extern int setlinebuf(FILE *);





    extern int vfscanf(FILE *, const char *, __gnuc_va_list);
    extern int vscanf(const char *, __gnuc_va_list);
    extern int vsscanf(const char *, const char *, __gnuc_va_list);





    extern int snprintf(char *, size_t, const char *, ...);




    extern int vsnprintf(char *, size_t, const char *, __gnuc_va_list);
    # 262
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    extern FILE *fdopen(int, const char *);
    extern char *ctermid(char *);
    extern int fileno(FILE *);
    # 288
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    extern FILE *popen(const char *, const char *);
    extern char *cuserid(char *);
    extern char *tempnam(const char *, const char *);
    extern int getopt(int, char *const *, const char *);

    extern int getsubopt(char **, char *const *, char **);

    extern char *optarg;
    extern int optind, opterr, optopt;
    extern int getw(FILE *);
    extern int putw(int, FILE *);
    extern int pclose(FILE *);







    extern int fseeko(FILE *, off_t, int);
    extern off_t ftello(FILE *);
    # 317
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdio.h" 3 4
    extern FILE *fopen64(const char *, const char *);
    extern FILE *freopen64(const char *, const char *, FILE *);
    extern FILE *tmpfile64(void);
    extern int fgetpos64(FILE *, fpos64_t *);
    extern int fsetpos64(FILE *, const fpos64_t *);
    extern int fseeko64(FILE *, off64_t, int);
    extern off64_t ftello64(FILE *);
    # 2 "bug.c" 2
    # 1
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdlib.h" 1 3
4
    # 25
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdlib.h" 3 4
    #pragma ident "@(#)stdlib.h     1.48    00/04/13 SMI"

    # 1 "/usr/include/iso/stdlib_iso.h" 1 3 4
    # 28 "/usr/include/iso/stdlib_iso.h" 3 4
    #pragma ident "@(#)stdlib_iso.h 1.3     01/03/09 SMI"
    # 37 "/usr/include/iso/stdlib_iso.h" 3 4
    extern unsigned char __ctype[];
    # 48 "/usr/include/iso/stdlib_iso.h" 3 4
    typedef struct {
     int quot;
     int rem;
    } div_t;

    typedef struct {
     long quot;
     long rem;
    } ldiv_t;
    # 84 "/usr/include/iso/stdlib_iso.h" 3 4
    typedef long wchar_t;





    extern void abort(void);
    extern int abs(int);
    extern int atexit(void (*)(void));
    extern double atof(const char *);
    extern int atoi(const char *);
    extern long int atol(const char *);
    extern void *bsearch(const void *, const void *, size_t, size_t,
     int (*)(const void *, const void *));
    extern void *calloc(size_t, size_t);
    extern div_t div(int, int);
    extern void exit(int);
    extern void free(void *);
    extern char *getenv(const char *);
    extern long int labs(long);
    extern ldiv_t ldiv(long, long);
    extern void *malloc(size_t);
    extern int mblen(const char *, size_t);
    extern size_t mbstowcs(wchar_t *, const char *, size_t);
    extern int mbtowc(wchar_t *, const char *, size_t);
    extern void qsort(void *, size_t, size_t,
     int (*)(const void *, const void *));
    extern int rand(void);
    extern void *realloc(void *, size_t);
    extern void srand(unsigned int);
    extern double strtod(const char *, char **);
    extern long int strtol(const char *, char **, int);
    extern unsigned long int strtoul(const char *, char **, int);
    extern int system(const char *);
    extern int wctomb(char *, wchar_t);
    extern size_t wcstombs(char *, const wchar_t *, size_t);
    # 28
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdlib.h" 2 3
4
    # 77
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdlib.h" 3 4
    typedef struct {
     long long quot;
     long long rem;
    } lldiv_t;







    typedef long uid_t;
    # 121
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdlib.h" 3 4
    extern void _exithandle(void);




    extern double drand48(void);
    extern double erand48(unsigned short *);
    extern long jrand48(unsigned short *);
    extern void lcong48(unsigned short *);
    extern long lrand48(void);
    extern long mrand48(void);
    extern long nrand48(unsigned short *);
    extern unsigned short *seed48(unsigned short *);
    extern void srand48(long);
    extern int putenv(char *);
    extern void setkey(const char *);
    # 153
"/opt/toolchain/lib/gcc/sparc-sun-solaris2.9/4.8.2/include-fixed/stdlib.h" 3 4
    extern void swab(const char *, char *, ssize_t);





    extern int mkstemp(char *);




    extern int mkstemp64(char *);





    extern long a64l(const char *);
    extern char *ecvt(double, int, int *, int *);
    extern char *fcvt(double, int, int *, int *);
    extern char *gcvt(double, int, char *);
    extern int getsubopt(char **, char *const *, char **);
    extern int grantpt(int);
    extern char *initstate(unsigned, char *, size_t);
    extern char *l64a(long);
    extern char *mktemp(char *);
    extern char *ptsname(int);
    extern long random(void);
    extern char *realpath(const char *, char *);
    extern char *setstate(const char *);
    extern void srandom(unsigned);
    extern int ttyslot(void);
    extern int unlockpt(int);
    extern void *valloc(size_t);




    extern void closefrom(int);
    extern int dup2(int, int);
    extern int fdwalk(int (*)(void *, int), void *);
    extern char *qecvt(long double, int, int *, int *);
    extern char *qfcvt(long double, int, int *, int *);
    extern char *qgcvt(long double, int, char *);
    extern char *getcwd(char *, size_t);
    extern const char *getexecname(void);
    extern char *getlogin(void);
    extern int getopt(int, char *const *, const char *);
    extern char *optarg;
    extern int optind, opterr, optopt;
    extern char *getpass(const char *);
    extern char *getpassphrase(const char *);
    extern int getpw(uid_t, char *);
    extern int isatty(int);
    extern void *memalign(size_t, size_t);
    extern char *ttyname(int);


    extern long long atoll(const char *);
    extern long long llabs(long long);
    extern lldiv_t lldiv(long long, long long);
    extern char *lltostr(long long, char *);
    extern long long strtoll(const char *, char **, int);
    extern unsigned long long strtoull(const char *, char **, int);
    extern char *ulltostr(unsigned long long, char *);
    # 3 "bug.c" 2

    int main(int argc, const char* argv[])
    {
     char* value = "12345";
     char* end = 0;
     double bug;
     {
      long long bug = 6789;
      bug = strtoll(value, &end, 10);
      printf("%ld\n", bug);
     }

     return 0;
    }



More information about the Gcc-bugs mailing list