Bug 18081 - [3.4 regression] Infinite memory allocation on -O3
Summary: [3.4 regression] Infinite memory allocation on -O3
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.2
: P2 normal
Target Milestone: 3.4.4
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords:
Depends on:
Blocks: 21503
  Show dependency treegraph
 
Reported: 2004-10-20 15:40 UTC by trauscher
Modified: 2006-05-17 08:48 UTC (History)
7 users (show)

See Also:
Host: i386-linux
Target: arm-rtems-elf
Build:
Known to work: 4.0.0 3.2.3
Known to fail:
Last reconfirmed: 2005-01-14 23:10:50


Attachments
Fix for the bug (302 bytes, patch)
2005-05-02 08:18 UTC, Grigory Tolstolytkin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description trauscher 2004-10-20 15:40:47 UTC
When compiling the following code, cc1
enters an infinite loop allocating memory until
virtual memory is exhausted.

arm-rtems-elf-gcc-3.4.2 -O3 -c -otest.o test.c

The bug disappears when using -O2 or when
using -O3 with -fno-inline-functions or
-fno-gcse
It also disappears by removing lines from the
program.

test.c:

int rd(int *p) {
  if (p<((int*)4)) return 0;
  return *p;
}

void wr(int *p) {
  if (p<((int*)4)) return;
  *p = 0;
}

void test(void *p)
{
  int i;
  int a[2];

  for(i=0;i<2;i++)
  {
    wr(p);
    a[i]=rd(p);
  }
}
Comment 1 Andrew Pinski 2004-10-22 18:02:20 UTC
Fixed on the mainline but I don't know if this is a regression.
Comment 2 Mark Mitchell 2004-11-01 00:46:37 UTC
Postponed until GCC 3.4.4.
Comment 3 Andrew Pinski 2005-01-14 23:10:50 UTC
Confirmed.
Comment 4 Grigory Tolstolytkin 2005-05-02 08:18:11 UTC
Created attachment 8789 [details]
Fix for the bug

I found a patch which fixes the bug. The patch was created by Richard Kenner
(kenner@vlsi1.ultra.nyu.edu) on 2004-02-12:
       * emit-rtl.c (set_mem_attributes_minus_bitpos): Don't kill
       previous MEM_VOLATILE in REF.

I did a bootstrap for arm-unknown-linux-gnu and it worked fine.
The patch is stiil exists in gcc-4.1.

Thanks,
Grigory.
Comment 5 Grigory Tolstolytkin 2005-05-04 10:11:30 UTC
The bug is also exists in gcc-3.4-20050429 (gcc.3.4.4-preleleise).
Comment 6 Giovanni Bajo 2005-05-04 12:12:08 UTC
Patch posted here:
http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00257.html

Mark, is it OK to backport this patch to 3.4.4, with a proper ChangeLog?
Comment 7 Mark Mitchell 2005-05-04 16:33:31 UTC
Subject: Re:  [3.4 regression] Infinite memory
 allocation on -O3

giovannibajo at libero dot it wrote:
> ------- Additional Comments From giovannibajo at libero dot it  2005-05-04 12:12 -------
> Patch posted here:
> http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00257.html
> 
> Mark, is it OK to backport this patch to 3.4.4, with a proper ChangeLog?

Yes, with proper testing.

Comment 8 Giovanni Bajo 2005-05-04 17:19:33 UTC
Greg, mind testing this also with a bootstrap on x86-linux?
Comment 9 Grigory Tolstolytkin 2005-05-08 13:50:08 UTC
I've done a build for i686-unknown-linux-gnu (3.4.4-20050506, glibc 2.3.2, linux
2.6.8). It seems to work fine too.

Thanks,
Grigory.
Comment 10 Grigory Tolstolytkin 2005-05-08 18:07:51 UTC
I meant that 20050506 build still has the bug. And the build with the patch
works fine for i686 too. I didn't mean that the bug was somehow fixed in 20050506 ;)

Thanks,
Grigory.
Comment 11 Andrew Pinski 2005-05-10 06:05:20 UTC
Fixed.
Comment 12 Andreas Schwab 2005-05-10 13:23:27 UTC
This is causing a regression in the Ada compiler: 
 
stage1/xgcc -Bstage1/ -B/usr/local/ia64-suse-linux/bin/ -c -g -O2      -gnatpg 
-gnata -g -O0 \ 
 -I- -I. -Iada -I../../gcc/ada ../../gcc/ada/memtrack.adb -o ada/memtrack.o  
+===========================GNAT BUG DETECTED==============================+ 
| 3.4.4 20050510 (prerelease) (ia64-suse-linux-gnu) GCC error:             | 
| in fixup_var_refs_1, at function.c:1876                                  | 
| Error detected at a-exexda.adb:252:65                                    | 
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            | 
| Include the entire contents of this bug box in the report.               | 
| Include the exact gcc or gnatmake command that you entered.              | 
| Also include sources listed below in gnatchop format                     | 
| (concatenated together with no headers between files).                   | 
+==========================================================================+ 
 
Comment 13 Andreas Schwab 2005-05-10 13:30:19 UTC
Actually the command line was this: 
 
stage1/xgcc -Bstage1/ -B/usr/local/ia64-suse-linux/bin/ -c -g -O2      -gnatpg 
-gnata -g -O1 -fno-inline \ 
 -I- -I. -Iada -I../../gcc/ada ../../gcc/ada/a-except.adb -o ada/a-except.o 
Comment 14 Mark Mitchell 2005-05-10 15:20:41 UTC
Subject: Re:  [3.4 regression] Infinite memory
 allocation on -O3

schwab at suse dot de wrote:
> ------- Additional Comments From schwab at suse dot de  2005-05-10 13:23 -------
> This is causing a regression in the Ada compiler: 
>  
> stage1/xgcc -Bstage1/ -B/usr/local/ia64-suse-linux/bin/ -c -g -O2      -gnatpg 
> -gnata -g -O0 \ 
>  -I- -I. -Iada -I../../gcc/ada ../../gcc/ada/memtrack.adb -o ada/memtrack.o  

Andreas, do you have time to look further into this?  That assertion is 
coming from a failed call to validate_replace_rtx; I wonder if there's 
something wrong with the IA64 machine description that's causing the 
problem.  If it were an easy, obvious thing to fix it might make sense 
to fix that.  Otherwise, I'll revert the patch; I don't want to be 
introducing churn for 3.4.4.

Comment 15 Andrew Pinski 2005-05-10 19:29:52 UTC
(In reply to comment #14)
> Andreas, do you have time to look further into this?  That assertion is 
> coming from a failed call to validate_replace_rtx; I wonder if there's 
> something wrong with the IA64 machine description that's causing the 
> problem.  If it were an easy, obvious thing to fix it might make sense 
> to fix that.  Otherwise, I'll revert the patch; I don't want to be 
> introducing churn for 3.4.4.

looks like it is on x86_64 also, see PR 21503.
Comment 16 H.J. Lu 2005-05-10 21:32:32 UTC
The patch is incomplete. I posted the rest of Kenner patch on 2004-02-12 at

http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00923.html
Comment 17 H.J. Lu 2005-05-10 21:35:13 UTC
BTW, the gcc-patch mailing list archive web interface for 2004-02 is broken.
You have to download the whole mailbox to see Kenner's patch.
Comment 18 Andrew Pinski 2005-05-10 22:42:40 UTC
Fixed.
Comment 19 Jim Huang 2006-05-17 08:48:30 UTC
I encountered the same problem with gcc-3.4.6 for ARM targets. Even I applied 18081.patch, the  situation of infinite memory allocation still exists. Since gcc-3.4 is closed, I wonder if there is a fix against gcc-3.4.6.