From patchwork Fri Apr 12 07:10:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1084447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499155-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="k82pXEYF"; dkim-atps=neutral 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 44gTYf5jxGz9s4V for ; Fri, 12 Apr 2019 17:10:14 +1000 (AEST) 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=ihxkj9aavCeU3y7Xgo9ZZGqzjF271 aRiXtmif7L2VECrE3K3wX/f8yUBf8mPLdrl35DyEyJAlhykpa2sv5hFVcNutCriA LN0Ozpj3jCQmNqJ2iGS5qjs3671lNN4v7RfH9Ww5R031vd1sR07pIPt888ZLITph LTAggAaPdBlsXA= 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=qVCuqcL8Cwddsy0tC4TxhfHEjXg=; b=k82 pXEYFniu28JEIJ23mUBDCpuz3NQ6rJ77+wzmxHyqwRCrlnJ4GeJwgiY0kfBmjDqq 11aIeHy5yekHsgGRP3WysiWu2M1dzmVCRQikWE4JFH52e7Dfd9EtgtkqPGtCoD3C CwsEMReDkkhLwfbAzR1cagWGmFQDqM+/JPAtwJOA= Received: (qmail 112709 invoked by alias); 12 Apr 2019 07:10:07 -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 112679 invoked by uid 89); 12 Apr 2019 07:10:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=sk:lookup_, sk:handle_ 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; Fri, 12 Apr 2019 07:10:05 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F2503E2CE; Fri, 12 Apr 2019 07:10:04 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.40.205.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B418219746; Fri, 12 Apr 2019 07:10:03 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x3C7A1Z0026150; Fri, 12 Apr 2019 09:10:01 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x3C7A1es026149; Fri, 12 Apr 2019 09:10:01 +0200 Date: Fri, 12 Apr 2019 09:10:00 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix patchable_function_entry attribute handling (PR c/89946) Message-ID: <20190412071000.GG21066@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes Hi! The following patch fixes various issues in patchable_function_entry handling: 1) most importantly, it adds a warning if the argument(s) aren't integer constants or if they are negative and drops the attribute 2) if (tree_fits_uhwi_p (x)) y = tree_to_uhwi (x); else gcc_unreachable (); makes no sense, as tree_to_uhwi has the same gcc_assert already 3) list_length () > 1 might look cool, but we should have guaranteed it is only 1 or 2 argument and even if it was longer, computing whole length and then comparing it against 1 is inefficient 4) warnings shouldn't start with a capital letter 5) formatting fixes Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-04-12 Jakub Jelinek PR c/89946 * varasm.c (assemble_start_function): Don't use tree_fits_uhwi_p and gcc_unreachable if it fails, just call tree_to_uhwi which verifies that too. Test TREE_CHAIN instead of list_length > 1. Start warning message with a lower-case letter. Formatting fixes. c-family/ * c-attribs.c (handle_patchable_function_entry_attribute): Add function comment. Warn if arguments of the attribute are not positive integer constants. testsuite/ * c-c++-common/pr89946.c: New test. Jakub --- gcc/varasm.c.jj 2019-02-28 08:14:58.438559862 +0100 +++ gcc/varasm.c 2019-04-11 15:34:46.933248354 +0200 @@ -1865,28 +1865,20 @@ assemble_start_function (tree decl, cons tree pp_val = TREE_VALUE (patchable_function_entry_attr); tree patchable_function_entry_value1 = TREE_VALUE (pp_val); - if (tree_fits_uhwi_p (patchable_function_entry_value1)) - patch_area_size = tree_to_uhwi (patchable_function_entry_value1); - else - gcc_unreachable (); - + patch_area_size = tree_to_uhwi (patchable_function_entry_value1); patch_area_entry = 0; - if (list_length (pp_val) > 1) + if (TREE_CHAIN (pp_val) != NULL_TREE) { - tree patchable_function_entry_value2 = - TREE_VALUE (TREE_CHAIN (pp_val)); - - if (tree_fits_uhwi_p (patchable_function_entry_value2)) - patch_area_entry = tree_to_uhwi (patchable_function_entry_value2); - else - gcc_unreachable (); + tree patchable_function_entry_value2 + = TREE_VALUE (TREE_CHAIN (pp_val)); + patch_area_entry = tree_to_uhwi (patchable_function_entry_value2); } } if (patch_area_entry > patch_area_size) { if (patch_area_size > 0) - warning (OPT_Wattributes, "Patchable function entry > size"); + warning (OPT_Wattributes, "patchable function entry > size"); patch_area_entry = 0; } @@ -1906,7 +1898,8 @@ assemble_start_function (tree decl, cons /* And the area after the label. Record it if we haven't done so yet. */ if (patch_area_size > patch_area_entry) targetm.asm_out.print_patchable_function_entry (asm_out_file, - patch_area_size-patch_area_entry, + patch_area_size + - patch_area_entry, patch_area_entry == 0); if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl))) --- gcc/c-family/c-attribs.c.jj 2019-04-08 10:11:26.706250584 +0200 +++ gcc/c-family/c-attribs.c 2019-04-11 15:51:45.851326928 +0200 @@ -3988,10 +3988,29 @@ handle_fallthrough_attribute (tree *, tr return NULL_TREE; } +/* Handle a "patchable_function_entry" attributes; arguments as in + struct attribute_spec.handler. */ + static tree -handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *) +handle_patchable_function_entry_attribute (tree *, tree name, tree args, + int, bool *no_add_attrs) { - /* Nothing to be done here. */ + for (; args; args = TREE_CHAIN (args)) + { + tree val = TREE_VALUE (args); + if (val && TREE_CODE (val) != IDENTIFIER_NODE + && TREE_CODE (val) != FUNCTION_DECL) + val = default_conversion (val); + + if (!tree_fits_uhwi_p (val)) + { + warning (OPT_Wattributes, + "%qE attribute argument %qE is not an integer constant", + name, val); + *no_add_attrs = true; + return NULL_TREE; + } + } return NULL_TREE; } --- gcc/testsuite/c-c++-common/pr89946.c.jj 2019-04-11 15:52:33.616532035 +0200 +++ gcc/testsuite/c-c++-common/pr89946.c 2019-04-11 15:51:29.303602307 +0200 @@ -0,0 +1,7 @@ +/* PR c/89946 */ + +__attribute__((patchable_function_entry (-1))) void foo (void) {} /* { dg-warning "'patchable_function_entry' attribute argument '-1' is not an integer constant" } */ +__attribute__((patchable_function_entry (5, -5))) void bar (void) {} /* { dg-warning "'patchable_function_entry' attribute argument '-5' is not an integer constant" } */ +int i, j; +__attribute__((patchable_function_entry (i))) void baz (void) {} /* { dg-warning "'patchable_function_entry' attribute argument 'i' is not an integer constant" } */ +__attribute__((patchable_function_entry (2, j))) void qux (void) {} /* { dg-warning "'patchable_function_entry' attribute argument 'j' is not an integer constant" } */