From: swa@isi.edu (Steven Seger Augart)
Subject: I have made GCC's c1 pass get fatal signal 11 (SIGSEGV)
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 24 Jul 1992 05:14:58 GMT

I am running GCC on a Sun 3/140 under SunOS 4.1.1.

  swa@moz ~/gcc-err 111} gcc -v
  Reading specs from /local/gnu/gcc-2.1/lib/gcc-lib/sun3-sunos4.1.1/2.1/specs
  gcc version 2.1

Here is a record of my compilation attempt:

  cd /nfs/u5/swa/gcc-err/
  gcc -ggdb3 -Wall -pipe qsp.c
  qsp.c:339: unbalanced `#endif'
  qsp.c: In function `rawput':
  qsp.c:163: warning: address of register variable `n' requested
  gcc: Internal compiler error: program cc1 got fatal signal 11

  Compilation exited abnormally with code 1 at Fri Jul 24 11:46:29

The bug is that GCC's cc1 pass got fatal signal 11.  Obviously, the
source code has bugs, but (as the documentation says), the compiler
should never get an internal error no matter how invalid or poor the
input.   

The source program qsp.c follows.  I have run it through the C
preprocessor with the command line "gcc -E qsp.c > qsp.i"

Running the preprocessed version through gcc gives the same error
message:

  swa@moz ~/gcc-err 115} gcc qsp.i
  qsp.c: In function `rawput':
  qsp.c:163: warning: address of register variable `n' requested
  gcc: Internal compiler error: program cc1 got fatal signal 11
  swa@moz ~/gcc-err 116} gcc -v
  Reading specs from /local/gnu/gcc-2.1/lib/gcc-lib/sun3-sunos4.1.1/2.1/specs
  gcc version 2.1

-- Steven Augart

----------------qsp.i follows-------------------------------------------
# 1 "qsp.c"
 







 
 

 
























































 
























 













   
# 1 "/local/gnu/gcc-2.1/lib/gcc-lib/sun3-sunos4.1.1/2.1/include/stddef.h" 1 3






 


 





 


















typedef int ptrdiff_t;








 


















typedef int size_t;








 


















typedef short unsigned int wchar_t;










 




 





# 109 "qsp.c" 2

# 1 "/local/gnu/gcc-2.1/lib/gcc-lib/sun3-sunos4.1.1/2.1/include/stdarg.h" 1 3
 































 

 



typedef char *va_list;



 








void va_end (va_list);		 













# 110 "qsp.c" 2

# 1 "/usr/include/ctype.h" 1 3
 











extern	char	_ctype_[];














# 111 "qsp.c" 2





 




   

# 1 "/local/gnu/gcc-2.1/lib/gcc-lib/sun3-sunos4.1.1/2.1/include/limits.h" 1 3
 


# 1 "/usr/include/limits.h" 1 3
 





















 
















# 4 "/local/gnu/gcc-2.1/lib/gcc-lib/sun3-sunos4.1.1/2.1/include/limits.h" 2 3





 



 



 



 





 



 












 





 



 





 



 






 





# 123 "qsp.c" 2

 

 









size_t
qsprintf(char *buf, size_t buflen, char *fmt, ...)
# 146 "qsp.c"

{
    va_list ap;
    register int n = 0;          


    int am_quoting = 0;          



    auto inline int needs_quoting(char c) {
        return ((_ctype_+1)[c]&010 )  || c == '/' || c == '\'' || c == '+' || c == ',';
    }
    
    auto inline void rawput(char c) {
        if (buflen)
            *buf++ = c, --buflen;
        ++n;
    }
    
    auto inline void enable_quoting(void) {
        if (!am_quoting) {
            rawput('\'');
            ++am_quoting;
        }
    }

    auto inline void disable_quoting(void) {
        if (am_quoting) {
            rawput('\'');
            am_quoting = 0;
        }
    }

    auto inline void qput(char c) {
        if (needs_quoting(c)) {
            enable_quoting();
            if (c == '\'')       
                rawput('\'');
        }
        rawput(c);
    }

    auto inline void uqput(char c) {
        disable_quoting();
        rawput(c);
    }
            
# 208 "qsp.c"

        
    (ap = ((char *) __builtin_next_arg ())) ;
    do {
        if (*fmt == '%') {
            int do_quoting = 0;


            auto inline void put(char c) {
                if (do_quoting)
                    qput(c);
                else
                    uqput(c);
            }


        rescan:
            switch(*++fmt) {
            case '\'':           

                if (do_quoting)
                     ;

                ++do_quoting;
                goto rescan;

            case '%':

                if (do_quoting)
                     ;

                uqput('%');
                break;

            case 'd':
            {
                int i = (ap += (((sizeof ( int) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) ,	*(( int *) (ap - (((sizeof ( int) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) ))) ;
                char itoabuf[ ((sizeof "INT_MIN") - 2)  ];
                register char *bp;
                
                if (i < 0) {
                    put('-');
                    i = -i;
                }                
                bp = itoabuf;
                do {
                    *bp++ = "0123456789"[i % 10];
                } while ((i /= 10) > 0);
                 
                do {
                    put(*--bp);
                } while (bp > itoabuf);
            }
                break;

            case 'c':
                put((ap += (((sizeof ( int) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) ,	*(( int *) (ap - (((sizeof ( int) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) ))) );
                break;

            case 's':
            {
                register char *s = (ap += (((sizeof ( char *) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) ,	*(( char * *) (ap - (((sizeof ( char *) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) ))) ;


                 

                if (s == ((void *)0) )
                    s = "(NULL POINTER)";

                
                 


 
                if (do_quoting && *s == '\0')
                    enable_quoting();  

                while (*s)
                    put(*s++);
            }
                break;


            default:
                 ;
                 
                break;

            }
        } else {                 
            uqput(*fmt);
        }
    } while (*fmt++);
     

     ;
    return n;
}
 


# 1 "/local/gnu/gcc-2.1/lib/gcc-lib/sun3-sunos4.1.1/2.1/include/stdio.h" 1 3
 




extern	struct	_iobuf {
	int	_cnt;
	unsigned char *_ptr;
	unsigned char *_base;
	int	_bufsiz;
	short	_flag;
	char	_file;		 
} _iob[];








































extern struct _iobuf 	*fopen();
extern struct _iobuf 	*fdopen();
extern struct _iobuf 	*freopen();
extern struct _iobuf 	*popen();
extern struct _iobuf 	*tmpfile();
extern long	ftell();
extern char	*fgets();
extern char	*gets();
extern char	*sprintf();
extern char	*ctermid();
extern char	*cuserid();
extern char	*tempnam();
extern char	*tmpnam();






# 309 "qsp.c" 2


 
int
main()
{
    char sbuf[10]; 
    char ibuf[80];
    int d;
    int i;

    fputs("Gimme string -->>", (&_iob[1]) );
    fflush((&_iob[1]) );
    gets(ibuf);
    fputs("Gimme number -->", (&_iob[1]) );
    fflush((&_iob[1]) );
    if (scanf("%d", &d)!= 1) {
        fputs("That's not a number!\n", (&_iob[1]) );
        exit(1);
    }
    i = qsprintf(sbuf, sizeof sbuf, "String*2: %s%sEOL\nQuoted String*2: %'s%'sEOL\nNumber: %d\nQuoted Number: %'d\nNumber as Character: %c\nNumber as quoted character: %'c\n", 


                 ibuf, ibuf, ibuf, ibuf, d, d, d, d);
    fputs("Made it past the qsprintf!\n", (&_iob[2]) );
    printf("%*sEOS", (int) sizeof sbuf, sbuf);
    printf("qsprintf says sbuf had %d chars; strlen(sbuf) (if appropriate) said
%d\n", i, i > sizeof sbuf ? -1 : strlen(sbuf));
    return 0;
}

 
 
 

Newsgroups: gnu.gcc.bug