Bug 53510 - [4.8 Regression] OOM while compile some code
Summary: [4.8 Regression] OOM while compile some code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Jakub Jelinek
URL:
Keywords: diagnostic, memory-hog
Depends on:
Blocks:
 
Reported: 2012-05-28 17:14 UTC by Andrew Pinski
Modified: 2012-05-31 12:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-05-29 00:00:00


Attachments
Testcase (274.11 KB, text/plain)
2012-05-28 17:16 UTC, Andrew Pinski
Details
gcc48-pr53510.patch (426 bytes, patch)
2012-05-29 07:30 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2012-05-28 17:14:32 UTC
While reducing PR 53500 for a different ICE on the trunk.  I ran into a case where it would cause all the memory to be eaten up.

Compile with -std=c++11.  Sorry it is a big testcase but it is hard to reduce as I have not set the limits yet,
Comment 1 Andrew Pinski 2012-05-28 17:16:03 UTC
Created attachment 27514 [details]
Testcase
Comment 2 Andrew Pinski 2012-05-28 17:21:05 UTC
#1  0x0000000000f7b7ea in read_line (file=0x18d9b50) at /home/pinskia/src/local/gcc/gcc/input.c:111
111		  memcpy (ptr, string, pos);
(gdb) p pos
$2 = 96889
(gdb) p/x pos
$3 = 0x17a79

So this is the error message which is causing the huge memory usage.
Comment 3 Paolo Carlini 2012-05-28 17:28:51 UTC
Stupid guess: does it happen with -fno-diagnostics-show-caret too?
Comment 4 Andrew Pinski 2012-05-28 17:29:46 UTC
(In reply to comment #3)
> Stupid guess: does it happen with -fno-diagnostics-show-caret too?

It does not happen with -fno-diagnostics-show-caret .
Comment 5 Paolo Carlini 2012-05-28 17:38:11 UTC
Let's ask Manuel to have a look.
Comment 6 Jakub Jelinek 2012-05-29 07:30:28 UTC
Created attachment 27515 [details]
gcc48-pr53510.patch

Ugh, that leaks like crazy.  Not only it forgets to free buffers, but also doubles the size of the allocation (which is fine) but only adds 2 to the expected allocated block length, so it allocates twice as much for every 2 bytes beyond 200 characters on a line.
Comment 7 Manuel López-Ibáñez 2012-05-29 07:53:37 UTC
(In reply to comment #6)
> Created attachment 27515 [details]
> gcc48-pr53510.patch
> 
> Ugh, that leaks like crazy.  Not only it forgets to free buffers, but also
> doubles the size of the allocation (which is fine) but only adds 2 to the
> expected allocated block length, so it allocates twice as much for every 2
> bytes beyond 200 characters on a line.

You are right. It is very weird what that code is doing. FWIW, I copied the function from gcov.c:read_line, so I guess that code has the same bug.
Comment 8 Jakub Jelinek 2012-05-29 11:34:42 UTC
Author: jakub
Date: Tue May 29 11:34:38 2012
New Revision: 187952

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187952
Log:
	PR middle-end/53510
	* input.c (read_line): Use XRESIZEVEC instead of XNEWVEC
	to avoid leaking memory.  No need to handle memory allocation
	failure.  Double string_len on each reallocation instead of
	adding 2.
	* gcov.c (read_line): Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gcov.c
    trunk/gcc/input.c
Comment 9 Jakub Jelinek 2012-05-31 12:10:09 UTC
Fixed.