From patchwork Sat Jan 22 17:48:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 80010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 473ECB710D for ; Sun, 23 Jan 2011 04:49:09 +1100 (EST) Received: (qmail 25237 invoked by alias); 22 Jan 2011 17:49:07 -0000 Received: (qmail 25224 invoked by uid 22791); 22 Jan 2011 17:49:06 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 22 Jan 2011 17:48:52 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 3170F9AC7EA; Sat, 22 Jan 2011 18:48:50 +0100 (CET) Date: Sat, 22 Jan 2011 18:48:50 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, jakuB@redhat.com, rguenther@suse.de Subject: PR tree-optimization/47190: ICE on weakref missing alias info Message-ID: <20110122174850.GB31129@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, this PR shows ICE on invalid static int i __attribute__ ((weakref)); according to docs, weakref attribute should be accompanied with an alias. This patch adds checking into cgraphunit.c. Bootstrapped/regtested x86_64-linux, OK? Honza PR tree-optimization/47190 * cgraphunit.c (process_common_attributes): New function. (process_function_and_variable_attributes): Use it. * gcc.dg/attr-weakref-3.c: New testcase. Index: cgraphunit.c =================================================================== --- cgraphunit.c (revision 169127) +++ cgraphunit.c (working copy) @@ -791,6 +791,23 @@ cgraph_analyze_function (struct cgraph_n current_function_decl = save; } +/* Process attributes common for vars and functions. */ + +static void +process_common_attributes (tree decl) +{ + tree weakref = lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)); + + if (weakref && !lookup_attribute ("alias", DECL_ATTRIBUTES (decl))) + { + error_at (DECL_SOURCE_LOCATION (decl), + "% attribute should be accompanied with" + " an % attribute"); + DECL_WEAK (decl) = 0; + remove_attribute ("weakref", DECL_ATTRIBUTES (decl)); + } +} + /* Look for externally_visible and used attributes and mark cgraph nodes accordingly. @@ -843,6 +860,7 @@ process_function_and_variable_attributes else if (node->local.finalized) cgraph_mark_needed_node (node); } + process_common_attributes (decl); } for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next) { @@ -869,6 +887,7 @@ process_function_and_variable_attributes else if (vnode->finalized) varpool_mark_needed_node (vnode); } + process_common_attributes (decl); } } Index: testsuite/gcc.dg/attr-weakref-3.c =================================================================== --- testsuite/gcc.dg/attr-weakref-3.c (revision 0) +++ testsuite/gcc.dg/attr-weakref-3.c (revision 0) @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-require-weak "" } */ +static int i __attribute__ ((weakref)); /* { dg-error "should be accompanied" } */