Bug 21410 - Infinite memory usage in preprocessor
Summary: Infinite memory usage in preprocessor
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: memory-hog
Depends on:
Blocks:
 
Reported: 2005-05-06 02:05 UTC by lucier
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lucier 2005-05-06 02:05:15 UTC
You guys will like this one ...

The most recent test is with 4.0.0 on Red Hat Enterprise Linux 4.0, but it also
happens with 3.4.3 and 4.0.0 on sparc-sun-solaris2.9.

In

http://www.math.purdue.edu/~lucier/bugzilla/6/

you'll find compressed versions of test2.c and gambit.h.  With this command line

peano-66% /pkgs/gcc-4.0.0/bin/gcc -Wall -W -Wno-unused -O1 -fno-math-errno
-fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fomit-frame-pointer
-fPIC -fno-common -mieee-fp -rdynamic -shared -D___DYNAMIC -D___SINGLE_HOST -E
test2.c -v > ! test2.i
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/pkgs/gcc-4.0.0
Thread model: posix
gcc version 4.0.0
 /export/pkgs/gcc-4.0.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.0.0/cc1 -E
-quiet -v -iprefix
/export/pkgs/gcc-4.0.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.0.0/
-D___DYNAMIC -D___SINGLE_HOST test2.c -mieee-fp -mtune=k8 -Wall -W -Wno-unused
-fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing
-fomit-frame-pointer -fPIC -fno-common -O1
ignoring nonexistent directory
"/export/pkgs/gcc-4.0.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.0.0/../../../../x86_64-unknown-linux-gnu/include"
ignoring nonexistent directory "/usr/local/include"
ignoring duplicate directory
"/pkgs/gcc-4.0.0/lib/gcc/x86_64-unknown-linux-gnu/4.0.0/include"
ignoring nonexistent directory
"/pkgs/gcc-4.0.0/lib/gcc/x86_64-unknown-linux-gnu/4.0.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /export/pkgs/gcc-4.0.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.0.0/include
 /pkgs/gcc-4.0.0/include
 /usr/include
End of search list.

memory is rapidly exhausted (even with 16GB of virtual memory).

Brad
Comment 1 Serge Belyshev 2005-05-06 04:39:36 UTC
gamdit.h:2426:
#define
___FIXADDP(x,y)((((x)^(y))&___FIX(___MIN_FIX))<=(((y)^((x)+(y)))&___FIX(___MIN_FIX))?___FIXADD(x,y):___FAL)

test2.c:3500:
___SET_R2(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(
___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(
___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___FIXADDP(___STK(-25),___STK(-24)),
___STK(-23)),___STK(-22)),___STK(-21)),___STK(-20)),___STK(-19)),___STK(-18)
...

These cute macros are trying to expand into a 3^35 == 5E16 nodes, so no wonder
that gcc is out of memory. Here is small testcase demonstrating same "problem":

#define A(x) x;x;x;x;
A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(A(0))))))))))))))))
Comment 2 lucier 2005-05-06 09:25:59 UTC
Subject: Re:  Infinite memory usage in preprocessor

Ah, after I reported it I was afraid it might be something like this. 
Thank you for explaining this.

Brad

Comment 3 Serge Belyshev 2005-05-06 13:15:51 UTC
Ok, so closing as invalid.