From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3549 invoked by alias); 22 May 2011 11:12:39 -0000 Received: (qmail 3528 invoked by uid 22791); 22 May 2011 11:12:37 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 22 May 2011 11:12:22 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/49106] New: static variable is optimized away even though it is referenced by a nested constructor X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sun, 22 May 2011 11:15:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg01909.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: burnus@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; }