http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49106
Summary: static variable is optimized away even though it is referenced by a nested constructor Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassig...@gcc.gnu.org ReportedBy: bur...@gcc.gnu.org In the following program, the function "test" is optimized way as the node is not marked as needed. Thus, the static variable "a" is removed - even though it is referenced in the nested constructor "_const_func". Result: Link error: /tmp/ccaIjMKk.o: In function `_const_func.1591': test.c:(.text+0x6): undefined reference to `a.1589' Expected: The local static should not be optimized way, i.e. the nested function lowering should properly update the cgraph ipa reference list. Side remark: For my purpose (coarray initialization in gfortran) it would be best if in such a case both the function and the constructor could be optimized away. Thus, if there would be some method on tree-level to tell this cgraph ... main () { void test (void) { static int a; void __attribute__((constructor)) _const_func(void) { a = 7; } } return 0; }