bug in egcs-2.91.66 - builtin support for strlen is buggy

Vlad Harchev hvv@hippo.ru
Mon May 1 04:26:00 GMT 2000


system type: Linux RedHat 6.0 for x86
egcs version: egcs-2.91.66, stock complier
Options that cause ICE: -O or -On for n>0

 Warning - this code doesn't require any #includes. It's also reduced in size
as possible, so it doesn't do what it was originally for.
 This piece of code compiles fine when no flags related to optimization are
specified - e.g. 'c++ 1.cpp'.
 Feel free to ask me for any additional details.

 Thank you very much for maintaining nad greatly improving gcc and binutils.
  
 
 Best regards,
  -Vlad
------------------------------1.cpp
/*
 Very funny. ICE happens when compiling with optimization
 (-On, for n>0). But it compiles fine without optimization (no -O switch).
    If declaration of enum is moved to file scope, then no internal error 
         happens.
    If two last lines (that use enum) are commented, then no internal error 
	happens.
*/
extern "C" { int mystrlen(const char* s); }

//if this line is non-commented, then ICE will happen, and not otherwise.
//It looks like builtin support for strlen is buggy.
#define mystrlen(x) strlen(x)

void pretty_print_num(char* buf,double val)
{
    char thousands_sep = ',';
    char tbuf[100];
    enum { prec = 2, group_len =3 };//this declaration causes bug - moving
	//it out to file scope will eliminate ICE.
    char* numbers_start = tbuf;
    char* out = buf;
    char* in = numbers_start;
    int len = mystrlen(in);
    char* dotpos = in + len -3;
    int numlen = dotpos - in;

    int to_next_th_sep = numlen % group_len;
    if (to_next_th_sep==0)
	to_next_th_sep = group_len;
};



More information about the Gcc-bugs mailing list