Bug 15539

Summary: [3.3 Regression] With using strtol fonction : "internal compiler error: in propagate_one_insn, at flow.c:1642"
Product: gcc Reporter: Alexis Saettler <asbin>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P2 Keywords: ice-on-invalid-code
Version: 3.3.3   
Target Milestone: 3.4.0   
Host: Target: i686-pc-linux-gnu
Build: Known to work: 3.4.0 4.0.0 3.0.4
Known to fail: 3.3.3 3.3.1 3.2.3 Last reconfirmed: 2005-03-29 01:57:04
Attachments: All sources, .i file, output compilation

Description Alexis Saettler 2004-05-19 13:01:34 UTC
gcc -v output :
****************
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.3 (Debian 20040429)
****************


I was writing a fonction "isnumber" to find is a string is a number. So I used
strtol, but I made a mistake, which produce the text :
****************
isnumber.c: In function `isnumber':
isnumber.c:14: error: Attempt to delete prologue/epilogue insn:
(insn/f 80 79 81 0 (nil) (set (mem:SI (plus:SI (reg/f:SI 6 ebp)
                (const_int -4 [0xfffffffc])) [0 S4 A8])
        (reg:SI 3 ebx)) -1 (nil)
    (nil))
isnumber.c:14: internal compiler error: in propagate_one_insn, at flow.c:1642
Please submit a full bug report,
****************

After some tests, I found that this is produce only with some kinds of -O
optimization..

I have extracted two examples that doesn't compile :
****************
/* gcc flag
 *  -O0 : works
 *  -O1 : works
 *  -O2 : doesn't work
 *  -O3 : doesn't work
 */
int isnumber1_bug(const char *chaine) {
  char *endptr[1];
  endptr[1] = '\0';
  strtol(chaine,endptr,10);
  return *chaine != '\0' && **endptr == '\0';
}
****************
/* gcc flag
 *  -O0 : works
 *  -O1 : doesn't work
 *  -O2 : doesn't work
 *  -O3 : doesn't work
 */
int isnumber2_bug(const char *chaine) {
  char *endptr[1];
  endptr[1] = '\0';
  strtol(chaine,(char **)NULL,10);
  return *chaine != '\0';
}
****************

of course, the right way is to write "*endptr[1] = '\0';", that was my mistake...

but what is strange is that this :
****************
/* this works ! */
int isnumber1(const char *chaine) {
  char *endptr[1];
  endptr[1] = '\0';
  strtol(chaine,endptr,10);
  return **endptr == '\0';
}
****************
..is working : just the last line changed...

How-To-Repeat:
just with "gcc -O2 -c -o isnumber.o isnumber.c", and try with other -O
optimization flags...

;-]
Comment 1 Alexis Saettler 2004-05-19 13:06:44 UTC
Created attachment 6341 [details]
All sources, .i file, output compilation
Comment 2 Andrew Pinski 2004-05-19 13:07:11 UTC
Confirmed, of course this is all undefined code.
Comment 3 Gabriel Dos Reis 2004-09-28 13:32:31 UTC
Adjust milestone
Comment 4 Gabriel Dos Reis 2005-04-30 13:40:55 UTC
won't fix for 3.3.6.  Works in 3.4.0 and higher.