On Sun, 03 Jun 2007 00:16:04 +0200, Gregor H. <nomail@[EMAIL PROTECTED]
> wrote:
>On Sun, 03 Jun 2007 00:09:22 +0200, jacob navia
><jacob@[EMAIL PROTECTED]
> wrote:
>>
>> Consider this program:
>>
>> int fn(int a)
>> {
>>
>> if (a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>> a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>> a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>> a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>>
>> /* 4955 lines exactly the same as above elided */
>>
>> a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>> a == 6 || a == 7 || a == 4 || a == 67 || a == 78 )
>> return 1;
>> return 0;
>> }
>>
>> This program makes the lcc compiler crash with stack overflow.
>> The evaluation of this SINGLE statement is recursive, each clause
>> calls recursively the expr3() function in expr.c.
>>
>> What can I do here?
>>
>> Fixing this would have to change drastically the design of the
>> compiler. In the other hand leaving this as is would leave a
>> compiler that can crash in some cir***stances.
>
> Would be interesting to see how gcc (and some other c compilers)
> deal with this construction (with, say, >10.000 lines). :-)
gcc 4.2.0 on FreeBSD 7.0 works fine with at least 16384 lines:
% $ gcc -v
% Using built-in specs.
% Target: i386-undermydesk-freebsd
% Configured with: FreeBSD/i386 system compiler
% Thread model: posix
% gcc version 4.2.0 20070514 [FreeBSD]
% $ expand foo.c | \
% fgrep ' a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&' | \
% wc -l
% 16384
% $ for count in `jot 10 1 10` ; do \
% /usr/bin/time gcc -ansi -pedantic -c foo.c ; \
% done
% 6.14 real 5.36 user 0.74 sys
% 4.57 real 4.11 user 0.45 sys
% 4.57 real 4.24 user 0.31 sys
% 4.56 real 3.57 user 0.98 sys
% 4.56 real 3.94 user 0.60 sys
% 4.57 real 3.60 user 0.96 sys
% 4.56 real 3.81 user 0.74 sys
% 4.52 real 4.03 user 0.48 sys
% 4.57 real 4.09 user 0.47 sys
% 4.56 real 3.72 user 0.83 sys
% $
It does require and use a big amount of memoty (more than 140 MB of
virtual process size in some cases), but at least it doesn't crash.
The memory needed for building the function shoots as high as 512 MB
with more then 65536 lines, but given enough time and virtual memory
space GCC completes building the function after some time (when it
starts using large amounts of swap space, performance drops to a crawl
though).


|