From patchwork Tue Jan 18 10:34:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1581204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=mn/KqoBD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JdQC83T4xz9sXM for ; Tue, 18 Jan 2022 21:35:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B4FA3857C46 for ; Tue, 18 Jan 2022 10:35:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B4FA3857C46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642502114; bh=wBSaGhUChQ05/fdKVBz92Pvz21+rqL7e3GlZDTGFWFA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=mn/KqoBDdZ6CF7P5KGfO48+GH9PaCC1u0ZEl7uKLLfR00LKrot4V3tnvSB9hvLHjk rYvupHLcoCovynaKeIhpMU7R6VM5o1DoVgQQqj+NykXu3YByqDqjFTvrzkwpL+Jrz9 p1BeIPGryZlLl+nXDxfW5a/5ja0dkdtPC/B705uo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 16C5C3858D39 for ; Tue, 18 Jan 2022 10:34:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16C5C3858D39 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20I7Qppq014305 for ; Tue, 18 Jan 2022 02:34:31 -0800 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3dn5ggbvpu-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 18 Jan 2022 02:34:31 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 Jan 2022 02:34:29 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 18 Jan 2022 02:34:29 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 58B343F705E; Tue, 18 Jan 2022 02:34:29 -0800 (PST) To: Subject: [PATCH] Fix tree-optimization/101941: IPA splitting out function with error attribute Date: Tue, 18 Jan 2022 02:34:25 -0800 Message-ID: <1642502065-2095-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 80LeoMNJqGvOXnYWt42c6KL3wDfggMou X-Proofpoint-GUID: 80LeoMNJqGvOXnYWt42c6KL3wDfggMou X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-18_02,2022-01-18_01,2021-12-02_01 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski The Linux kernel started to fail compile when the jump threader was improved (r12-2591-g2e96b5f14e4025691). This failure was due to the IPA splitting code decided now to split off the basic block which contained two functions, one of those functions included the error attribute on them. This patch fixes the problem by disallowing basic blocks from being split which contain functions that have either the error or warning attribute on them. The two new testcases are to make sure we still split the function for other places if we reject the one case. Committed as approved after Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/101941 gcc/ChangeLog: * ipa-split.cc (visit_bb): Disallow function calls where the function has either error or warning attribute. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr101941-1.c: New test. * gcc.dg/tree-ssa/pr101941-1.c: New test. --- gcc/ipa-split.cc | 74 ++++++++++++------- .../gcc.c-torture/compile/pr101941-1.c | 50 +++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr101941-1.c | 53 +++++++++++++ 3 files changed, 149 insertions(+), 28 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr101941-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr101941-1.c diff --git a/gcc/ipa-split.cc b/gcc/ipa-split.cc index fc6be8eadef..6ca45f3b745 100644 --- a/gcc/ipa-split.cc +++ b/gcc/ipa-split.cc @@ -873,7 +873,6 @@ visit_bb (basic_block bb, basic_block return_bb, gimple *stmt = gsi_stmt (bsi); tree op; ssa_op_iter iter; - tree decl; if (is_gimple_debug (stmt)) continue; @@ -899,33 +898,52 @@ visit_bb (basic_block bb, basic_block return_bb, can_split = false; } - /* Check builtins that prevent splitting. */ - if (gimple_code (stmt) == GIMPLE_CALL - && (decl = gimple_call_fndecl (stmt)) != NULL_TREE - && fndecl_built_in_p (decl, BUILT_IN_NORMAL)) - switch (DECL_FUNCTION_CODE (decl)) - { - /* FIXME: once we will allow passing non-parm values to split part, - we need to be sure to handle correct builtin_stack_save and - builtin_stack_restore. At the moment we are safe; there is no - way to store builtin_stack_save result in non-SSA variable - since all calls to those are compiler generated. */ - case BUILT_IN_APPLY: - case BUILT_IN_APPLY_ARGS: - case BUILT_IN_VA_START: - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, - "Cannot split: builtin_apply and va_start.\n"); - can_split = false; - break; - case BUILT_IN_EH_POINTER: - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, "Cannot split: builtin_eh_pointer.\n"); - can_split = false; - break; - default: - break; - } + /* Check calls that would prevent splitting. */ + if (gimple_code (stmt) == GIMPLE_CALL) + { + if (tree decl = gimple_call_fndecl (stmt)) + { + /* Check builtins that would prevent splitting. */ + if (fndecl_built_in_p (decl, BUILT_IN_NORMAL)) + switch (DECL_FUNCTION_CODE (decl)) + { + /* FIXME: once we will allow passing non-parm values to + split part, we need to be sure to handle correct + builtin_stack_save and builtin_stack_restore. At the + moment we are safe; there is no way to store + builtin_stack_save result in non-SSA variable since all + calls to those are compiler generated. */ + case BUILT_IN_APPLY: + case BUILT_IN_APPLY_ARGS: + case BUILT_IN_VA_START: + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Cannot split: builtin_apply and va_start.\n"); + can_split = false; + break; + case BUILT_IN_EH_POINTER: + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Cannot split: builtin_eh_pointer.\n"); + can_split = false; + break; + default: + break; + } + + /* Calls that function has either the warning or error + attribute on it should not be split off into another + function. */ + if (lookup_attribute ("warning", DECL_ATTRIBUTES (decl)) + || lookup_attribute ("error", DECL_ATTRIBUTES (decl))) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Cannot split: warning or error attribute.\n"); + can_split = false; + } + } + } FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_DEF) bitmap_set_bit (set_ssa_names, SSA_NAME_VERSION (op)); diff --git a/gcc/testsuite/gcc.c-torture/compile/pr101941-1.c b/gcc/testsuite/gcc.c-torture/compile/pr101941-1.c new file mode 100644 index 00000000000..0481a3835a6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr101941-1.c @@ -0,0 +1,50 @@ +/* { dg-additional-options "-fconserve-stack" } */ + +/* Check to make sure that if + rfc4106_set_hash_subkey gets split, + the error function does not gets split away + from the if statement conditionalizing it. */ + +struct crypto_aes_ctx { + char key_dec[128]; +}; + +int rfc4106_set_hash_subkey_hash_subkey; + +void __write_overflow(void)__attribute__((__error__(""))); +void __write_overflow1(void); +void aes_encrypt(void*); + +void fortify_panic(const char*) __attribute__((__noreturn__)) ; + +char *rfc4106_set_hash_subkey(struct crypto_aes_ctx *ctx) { + void *a = &ctx->key_dec[0]; + unsigned p_size = __builtin_object_size(a, 0); +#ifdef __OPTIMIZE__ + if (p_size < 16) { + __write_overflow1(); + fortify_panic(__func__); + } + if (p_size < 32) { + __write_overflow(); + fortify_panic(__func__); + } +#endif + aes_encrypt(ctx); + return ctx->key_dec; +} + +char *(*gg)(struct crypto_aes_ctx *) = rfc4106_set_hash_subkey; + +void a(void) +{ + struct crypto_aes_ctx ctx; + rfc4106_set_hash_subkey(&ctx); +} +void b(void) +{ + struct crypto_aes_ctx ctx; + ctx.key_dec[0] = 0; + rfc4106_set_hash_subkey(&ctx); +} + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr101941-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr101941-1.c new file mode 100644 index 00000000000..a1a342a253a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr101941-1.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fconserve-stack -fdump-tree-optimized" } */ +/* Check to make sure that if + rfc4106_set_hash_subkey gets split, + the error function does not gets split away + from the if statement conditionalizing it. + Checking this via the scan tree also. */ +struct crypto_aes_ctx { + char key_dec[128]; +}; + +int rfc4106_set_hash_subkey_hash_subkey; + +void __write_overflow(void)__attribute__((__error__(""))); +void __write_overflow1(void); +void aes_encrypt(void*); + +void fortify_panic(const char*) __attribute__((__noreturn__)) ; + +char *rfc4106_set_hash_subkey(struct crypto_aes_ctx *ctx) { + void *a = &ctx->key_dec[0]; + unsigned p_size = __builtin_object_size(a, 0); +#ifdef __OPTIMIZE__ + if (p_size < 16) { + __write_overflow1(); + fortify_panic(__func__); + } + if (p_size < 32) { + __write_overflow(); + fortify_panic(__func__); + } +#endif + aes_encrypt(ctx); + return ctx->key_dec; +} + +char *(*gg)(struct crypto_aes_ctx *) = rfc4106_set_hash_subkey; + +void a(void) +{ + struct crypto_aes_ctx ctx; + rfc4106_set_hash_subkey(&ctx); +} +void b(void) +{ + struct crypto_aes_ctx ctx; + ctx.key_dec[0] = 0; + rfc4106_set_hash_subkey(&ctx); +} + +/* This testcase should still split out one of the above basic blocks dealing + with __write_overflow. */ +/* { dg-final { scan-tree-dump-times "Function rfc4106_set_hash_subkey.part" 1 "optimized" } } */