This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the EGCS project.
Bug with enum defined inside function
- To: egcs-bugs@egcs.cygnus.com
- Subject: Bug with enum defined inside function
- From: Jonathan Perret <jperret@cybercable.fr>
- Date: Sat, 31 Jul 1999 13:16:19 +0200
Hello,
Here is a bit of code that will lead g++ (egcs 1.1.2, full version string below)
on x86 either to hogging huge amounts of virtual memory (possibly illimited - my
machine freezes anyway) or an internal error, when trying to optimise at -O2 or
-O1 (-O3 is OK).
I have tried to trim it down as much as possible so the code is pretty
meaningless now.
Here are the contents of the .cpp file :
---8<---
#if fix
enum E {
a
};
#endif
void f(int x)
{
#if !fix
enum E {
a
};
#endif
enum E e;
long long rbv;
switch (x) {
case 0:
e = 0;
}
switch(e) {
#if hog
case 0:
rbv = x + 1 & 1;
#if interror2
exit(rbv);
#else
printf("a", rbv);
#endif
#elif interror
case 0:
printf("a",x+1&1 ? x+1 | 0x80000000LL : x+1);
#endif
}
}
--->8---
Compile this code with -O1 -Dhog to have gcc eat all available memory :
> gcc -v -c -O1 -Dhog bug.cpp
Reading specs from /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release)
/usr/lib/gcc-lib/i486-linux/egcs-2.91.66/cpp -lang-c++ -v -undef -D__GNUC__=2
-D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386
-D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__
-D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -D__OPTIMIZE__
-Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di486
-D__i486 -D__i486__ -Dhog bug.cpp /tmp/ccZ9AefD.ii
GNU CPP version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release) (i386
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++-2
/usr/local/include
/usr/lib/gcc-lib/i486-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i486-linux/egcs-2.91.66/cc1plus /tmp/ccZ9AefD.ii -quiet
-dumpbase bug.cc -O1 -version -o /tmp/ccyFISYc.s
GNU C++ version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release) (i486-linux)
compiled by GNU C version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release).
bug.cpp: In function `void f(int)':
bug.cpp:21: warning: conversion from `int' to `enum f(int)::E'
bug.cpp:31: warning: implicit declaration of function `int printf(...)'
Compile it with -O1 -Dinterror to exhibit an internal error :
> gcc -v -c -O1 -Dinterror bug.cpp
Reading specs from /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release)
/usr/lib/gcc-lib/i486-linux/egcs-2.91.66/cpp -lang-c++ -v -undef -D__GNUC__=2
-D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386
-D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__
-D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -D__OPTIMIZE__
-Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di486
-D__i486 -D__i486__ -Dinterror bug.cpp /tmp/cct3vc8N.ii
GNU CPP version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release) (i386
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++-2
/usr/local/include
/usr/lib/gcc-lib/i486-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i486-linux/egcs-2.91.66/cc1plus /tmp/cct3vc8N.ii -quiet
-dumpbase bug.cc -O1 -version -o /tmp/ccSHOLPt.s
GNU C++ version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release) (i486-linux)
compiled by GNU C version egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release).
bug.cpp: In function `void f(int)':
bug.cpp:21: warning: conversion from `int' to `enum f(int)::E'
bug.cpp:35: warning: implicit declaration of function `int printf(...)'
bug.cpp:38: Internal compiler error.
bug.cpp:38: Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
bug.cpp:38: See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.
Adding -Dfix, which moves the enum definition outside of the function, will cure
both problems.
I have removed as much code as I could, but here are a few notes :
* You need both switches
* rbv needs to be long long (obviously there is some interaction with 64-bit
support code here)
* The complicated expression in the last printf is actually needed.
It seems that removing any operator from it will make the
errors disappear.
Furthermore the long long constant needs to have the high bit set.
* Defining 'interror2' together with 'hog' will cause another internal error
instead of memory hogging.
I have attached a .tar.gz file which contains the bug.cpp file above, plus .ii
files for each of the configurations mentioned.
Greetings,
--Jonathan
enum_bug.tar.gz