From patchwork Thu Mar 13 18:00:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 330071 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E8B162C00AF for ; Fri, 14 Mar 2014 05:01:09 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=uPdWyVdJdRhK0T9uaawKBTSSv6tav L4Bt2qH+3UO1Dej2CEx14r1rfD6p/oHW74R78XHGfPjJyM7mCL9OH6rlOqQcd9kE 8VBevHu3xwKwWbPv13QD7O/oRdGQhRMbVKAOdj+ujyc++NFBFYRK9djDfI6JP3VP 8n+RQCnqTnP/aI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=5PBbFDQ+GvxhnPFMbtziW++q/M4=; b=ecf Nt5yO++IWQotCVn0LnayyeHfZEHFdUaCUFP4X+86IlRImH2O6uuVs2jg8pjgunyo PhuORVNDWG0CKx68OVnyC8sI+oB/lpwSAS/UueIX/pteVQ9nUuM5N94lLs86M7V4 g1gyIm09MmgvFs6Hc1FjEYvZJamvu6lsR8o9Ars8= Received: (qmail 7616 invoked by alias); 13 Mar 2014 18:01:01 -0000 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 Received: (qmail 7601 invoked by uid 89); 13 Mar 2014 18:01:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Mar 2014 18:00:58 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2DI0qgB015526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Mar 2014 14:00:53 -0400 Received: from tucnak.zalov.cz (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2DI0k38022930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 13 Mar 2014 14:00:49 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.8/8.14.7) with ESMTP id s2DI0i6P004383; Thu, 13 Mar 2014 19:00:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.8/8.14.8/Submit) id s2DI0gq3004382; Thu, 13 Mar 2014 19:00:42 +0100 Date: Thu, 13 Mar 2014 19:00:42 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up #pragma weak handling (PR middle-end/36282) Message-ID: <20140313180042.GZ22862@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! We get bogus warning on the -1 and -4 testcases. The problem is that we accept without warning an __asm rename like: extern void *baz (void *dest, const void *src, __SIZE_TYPE__ n); extern __typeof (baz) baz __asm("bazfn"); only if it doesn't have DECL_ASSEMBLER_NAME_SET_P yet, after it is set we just warn and ignore the rename. But for #pragma weak, if there are any pending #pragma weak pragmas, we actually set DECL_ASSEMBLER_NAME right away. Fixed by computing DECL_ASSEMBLER_NAME for the #pragma weak handling just temporarily if it hasn't been set yet (yeah, it is duplicate work then, but hopefully not very common), plus also fixing the early outs - if a decl matching some #pragma weak is found, that vector entry is removed from pending_weaks, but we were only testing if pending_weaks is NULL, which it will never be after it has been allocated once. Thus, for the most common case (well, most code doesn't use #pragma weak at all) where you have #pragma weak followed by corresponding prototype or say a couple of #pragma weak directives followed by corresponding prototypes, there should be either no or just very small amount of extra decl_assembler_name invocations. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-03-13 Jakub Jelinek PR middle-end/36282 * c-pragma.c (apply_pragma_weak): Only look at TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) if DECL_ASSEMBLER_NAME_SET_P (decl). (maybe_apply_pending_pragma_weaks): Exit early if vec_safe_is_empty (pending_weaks) rather than only when !pending_weaks. (maybe_apply_pragma_weak): Likewise. If !DECL_ASSEMBLER_NAME_SET_P, set assembler name back to NULL afterwards. * c-c++-common/pr36282-1.c: New test. * c-c++-common/pr36282-2.c: New test. * c-c++-common/pr36282-3.c: New test. * c-c++-common/pr36282-4.c: New test. Jakub --- gcc/c-family/c-pragma.c.jj 2014-03-06 13:05:17.000000000 +0100 +++ gcc/c-family/c-pragma.c 2014-03-13 14:39:44.200586561 +0100 @@ -263,6 +263,7 @@ apply_pragma_weak (tree decl, tree value if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl) && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */ + && DECL_ASSEMBLER_NAME_SET_P (decl) && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))) warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use " "results in unspecified behavior", decl); @@ -280,7 +281,7 @@ maybe_apply_pragma_weak (tree decl) /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */ /* No weak symbols pending, take the short-cut. */ - if (!pending_weaks) + if (vec_safe_is_empty (pending_weaks)) return; /* If it's not visible outside this file, it doesn't matter whether it's weak. */ @@ -292,7 +293,13 @@ maybe_apply_pragma_weak (tree decl) if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL) return; - id = DECL_ASSEMBLER_NAME (decl); + if (DECL_ASSEMBLER_NAME_SET_P (decl)) + id = DECL_ASSEMBLER_NAME (decl); + else + { + id = DECL_ASSEMBLER_NAME (decl); + SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE); + } FOR_EACH_VEC_ELT (*pending_weaks, i, pe) if (id == pe->name) @@ -313,7 +320,7 @@ maybe_apply_pending_pragma_weaks (void) pending_weak *pe; symtab_node *target; - if (!pending_weaks) + if (vec_safe_is_empty (pending_weaks)) return; FOR_EACH_VEC_ELT (*pending_weaks, i, pe) --- gcc/testsuite/c-c++-common/pr36282-1.c.jj 2014-03-13 14:31:03.752580696 +0100 +++ gcc/testsuite/c-c++-common/pr36282-1.c 2014-03-13 14:31:56.110270219 +0100 @@ -0,0 +1,12 @@ +/* PR middle-end/36282 */ +/* { dg-do compile } */ + +#pragma weak bar + +extern void *baz (void *dest, const void *src, __SIZE_TYPE__ n); +extern __typeof (baz) baz __asm("bazfn"); /* { dg-bogus "asm declaration ignored due to conflict with previous rename" } */ + +void +foo (void) +{ +} --- gcc/testsuite/c-c++-common/pr36282-2.c.jj 2014-03-13 14:31:03.752580696 +0100 +++ gcc/testsuite/c-c++-common/pr36282-2.c 2014-03-13 14:32:01.264247933 +0100 @@ -0,0 +1,10 @@ +/* PR middle-end/36282 */ +/* { dg-do compile } */ + +extern void *baz (void *dest, const void *src, __SIZE_TYPE__ n); +extern __typeof (baz) baz __asm("bazfn"); /* { dg-bogus "asm declaration ignored due to conflict with previous rename" } */ + +void +foo (void) +{ +} --- gcc/testsuite/c-c++-common/pr36282-3.c.jj 2014-03-13 14:31:03.752580696 +0100 +++ gcc/testsuite/c-c++-common/pr36282-3.c 2014-03-13 14:32:07.243209260 +0100 @@ -0,0 +1,13 @@ +/* PR middle-end/36282 */ +/* { dg-do compile } */ + +void bar (void); +#pragma weak bar + +extern void *baz (void *dest, const void *src, __SIZE_TYPE__ n); +extern __typeof (baz) baz __asm("bazfn"); /* { dg-bogus "asm declaration ignored due to conflict with previous rename" } */ + +void +foo (void) +{ +} --- gcc/testsuite/c-c++-common/pr36282-4.c.jj 2014-03-13 14:31:03.752580696 +0100 +++ gcc/testsuite/c-c++-common/pr36282-4.c 2014-03-13 14:32:12.831177682 +0100 @@ -0,0 +1,13 @@ +/* PR middle-end/36282 */ +/* { dg-do compile } */ + +#pragma weak bar +void bar (void); + +extern void *baz (void *dest, const void *src, __SIZE_TYPE__ n); +extern __typeof (baz) baz __asm("bazfn"); /* { dg-bogus "asm declaration ignored due to conflict with previous rename" } */ + +void +foo (void) +{ +}