Bug 58087

Summary: Huge memory consumption with #pragma GCC optimize, __attribute__ and long output paths
Product: gcc Reporter: Sandro Mani <manisandro>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal Keywords: opt-attribute
Priority: P3    
Version: 4.8.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Sandro Mani 2013-08-05 13:00:43 UTC
Using gcc version 4.8.1 20130717 (Red Hat 4.8.1-5) (GCC)

Any code containing #pragma GCC optimize, lots of __attribute__(()) will result in cc1 taking up huge amounts of memory _depending_ on the length of the output path.

Test case:
$ for i in $(seq 1 10000); do echo -e "void __attribute__(()) fz$i();" >> test.h; done

$ cat > test.c <<EOF
#pragma GCC optimize ("-O1")
#include "test.h"
int main(){ return 0; }

$ wget https://gist.github.com/netj/526585/raw/9044a9972fd71d215ba034a38174960c1c9079ad/memusg
$ chmod +x memusg

$ mkdir a
$ ./memusg gcc -c -o a/test.o test.c
memusg: peak=485796

$ mkdir aaaaaaaaaaaaaaaaaaaaaaa
$ ./memusg gcc -c -o aaaaaaaaaaaaaaaaaaaaaaa/test.o test.c
memusg: peak=4827100

- The "-O1" is not important, passing any other string to #pragma GCC optimize (regardless of whether it is valid or invalid) will also trigger the issue
- As noted, the memory consumption depends on the length of the output path
Comment 1 Sandro Mani 2014-01-18 16:18:01 UTC
Still applies to 4.8.2. Changing component to a (hopefully) more relevant one.