Search

Visual Studio runs out of memory when compiling recursive inline templates in Release by Mooing Duck

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 699728
Opened: 11/7/2011 6:42:46 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
1
User(s) can reproduce this bug
When compiling C++ inline recursive template functions, compiler halts with error: "Fatal Error C1002: compiler is out of heap space in pass 2". This happens even with Minimize Size (/O1) flag set. This does not happen if inlining is disabled (/Ob0) or if function is __declspec(noinline).

As inline is a hint, the compiler should ignore it when inlining would be silly. A solution would be to measure how long a function is before any inlining, and stop inlining functions more than 2 opcodes after the function has grown more than 10-15 times it's original size.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010

Steps to reproduce

#include <iostream>
template <unsigned int depth>
//__declspec(noinline)
int not_quite_recursive(int input)
{
return not_quite_recursive<depth-1>(input) +
         not_quite_recursive<depth-1>(input);
}
template <>
int not_quite_recursive<0>(int input)
{ return input; }

int main()
{ std::cout << not_quite_recursive<100>(2); }

Product Language

English

Operating System

Windows XP

Operating System Language

English

Actual results

Fatal Error C1002: compiler is out of heap space in pass 2
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Expected results


1>Project Performance Summary:
1>    14141 ms E:\Code\Test\Test2010.vcxproj             1 calls
1>             14141 ms build                                     1 calls
1>Target Performance Summary:
1>     16 ms InitializeBuildStatus                     1 calls
1>     16 ms FinalizeBuildStatus                        1 calls
1>     47 ms _CheckForInvalidConfigurationAndPlatform 1 calls
1>     3578 ms ClCompile                                 1 calls
1>     4781 ms Link                                     1 calls
1>     5656 ms Manifest                                 1 calls
1>Task Performance Summary:
1>     16 ms Delete                                     2 calls
1>     16 ms WriteLinesToFile                         1 calls
1>     3562 ms CL                                         1 calls
1>     4781 ms Link                                     1 calls
1>     5656 ms Mt                                         1 calls
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 11/14/2011 at 12:09 PM
Hi, This bug will be fixed in upcoming VC++ Dev11 release. Thank you for reporting this bug.
Posted by MS-Moderator07 [Feedback Moderator] on 11/8/2011 at 1:03 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.


Posted by Dmitry Me on 11/7/2011 at 10:32 PM
I tried to repro this in cl.exe 16.00.40219.1 on a WinXP machine with Core2 Duo and 2GB RAM. link.exe ran for 25 minutes and according to TaskManager reached 600MB memory consumption and 1,15GB VM size and at that point I killed the process because it slowed my machine intolerably. I'd say it's overkill and totally unacceptable for an industry grade compiler. The recursion depth of one hundred in each of two directions is not that big and also it's trivial to optimize folding it in iterative manner so that the linker consumes less resources.

IMO this is an indication of a major compiler deficiency and should be addressed ASAP.
Posted by MS-Moderator01 on 11/7/2011 at 7:45 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Mooing Duck on 11/7/2011 at 6:43 PM
Add __declspec(noinline) to function