This is a completetest file: 10 lines are enough,
with only 3 lines of actual code

#include <stdio.h>
int main(void)
{
long  long x;
long  long y;
  x=3;
  y=5;
  printf ("%Ld %Ld %Ld %Ld  \n",x,y,x+y,x-y);
  return 0;
}

gives the obviously absurd output
0 3 0 5 

adding <inttypes.h> make no difference

The gcc version is
gcc (GCC) 4.1.1 20060331 (prerelease)

Compiled form sources on a SUN Blade 1000 Solaris 9
with the only configure option
--enable-languages=c 


below is the .i file:

# 1 "longlong.c"
# 1 "<interne>"
# 1 "<ligne de commande>"
# 1 "longlong.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 20 "/usr/include/stdio.h" 3 4
#pragma ident "@(#)stdio.h      1.79    01/04/16 SMI"

# 1 "/usr/include/iso/stdio_iso.h" 1 3 4
# 32 "/usr/include/iso/stdio_iso.h" 3 4
#pragma ident "@(#)stdio_iso.h  1.2     99/10/25 SMI"


# 1 "/usr/include/sys/feature_tests.h" 1 3 4
# 13 "/usr/include/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"
# 16 "/usr/include/sys/feature_tests.h" 2 3 4
# 36 "/usr/include/iso/stdio_iso.h" 2 3 4
# 1 "/usr/include/sys/va_list.h" 1 3 4
# 9 "/usr/include/sys/va_list.h" 3 4
#pragma ident "@(#)va_list.h    1.13    01/02/08 SMI"
# 26 "/usr/include/sys/va_list.h" 3 4
typedef void *__va_list;
# 37 "/usr/include/iso/stdio_iso.h" 2 3 4
# 1 "/usr/include/stdio_tag.h" 1 3 4
# 9 "/usr/include/stdio_tag.h" 3 4
#pragma ident "@(#)stdio_tag.h  1.3     98/04/20 SMI"
# 21 "/usr/include/stdio_tag.h" 3 4
typedef struct __FILE __FILE;
# 38 "/usr/include/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;
};
# 39 "/usr/include/iso/stdio_iso.h" 2 3 4
# 59 "/usr/include/iso/stdio_iso.h" 3 4
typedef long long __longlong_t;
# 75 "/usr/include/iso/stdio_iso.h" 3 4
typedef __FILE FILE;







typedef unsigned int size_t;




typedef long fpos_t;
# 147 "/usr/include/iso/stdio_iso.h" 3 4
extern __FILE __iob[20];
# 164 "/usr/include/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 *);
# 23 "/usr/include/stdio.h" 2 3 4
# 91 "/usr/include/stdio.h" 3 4
typedef long off_t;







typedef __longlong_t off64_t;
# 109 "/usr/include/stdio.h" 3 4
typedef __longlong_t fpos64_t;
# 137 "/usr/include/stdio.h" 3 4
extern unsigned char _sibuf[], _sobuf[];
# 179 "/usr/include/stdio.h" 3 4
extern unsigned char *_bufendtab[];
extern FILE *_lastbuf;
# 215 "/usr/include/stdio.h" 3 4
extern void setbuffer(FILE *, char *, size_t);
extern int setlinebuf(FILE *);





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





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




extern int vsnprintf(char *, size_t, const char *, __va_list);
# 244 "/usr/include/stdio.h" 3 4
extern FILE *fdopen(int, const char *);
extern char *ctermid(char *);
extern int fileno(FILE *);
# 270 "/usr/include/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 *);
# 299 "/usr/include/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 "longlong.c" 2

int main(void)
{
long long x;
long long y;
  x=3;
  y=5;
  printf ("%Ld %Ld %Ld %Ld  \n",x,y,x+y,x-y);
  return 0;
}


-- 
           Summary: wrong long long elementary computations
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jpvial at nerim dot net
 GCC build triplet: sparc-sun-solaris2.9
  GCC host triplet: sparc-sun-solaris2.9
GCC target triplet: sparc-sun-solaris2.9


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

Reply via email to