From patchwork Fri Jul 3 15:40:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1322457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from sourceware.org (server2.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 ozlabs.org (Postfix) with ESMTPS id 49yzh00FhNz9sRk for ; Sat, 4 Jul 2020 01:40:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 941EC384241C; Fri, 3 Jul 2020 15:40:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 177863844079 for ; Fri, 3 Jul 2020 15:40:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 177863844079 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mjambor@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 26265AFB2 for ; Fri, 3 Jul 2020 15:40:40 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: [PATCH] ipa-sra: Avoid transitive splits with type mismatches (PR 96040) User-Agent: Notmuch/0.29.3 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Fri, 03 Jul 2020 17:40:39 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-3038.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, PR 96040 revealed IPA-SRA, when checking whether an intended split is the same as the one in a called function does not also check if the types match and the transformation code does not handle any resulting type mismatches. This patch simply avoids the the split in the case of mismatches, so that we do not have to be careful about invalid floating-point values being passed in floating point registers and related issues. Bootstrapped and tested on x86_64-linux, pre-approved by Richi on IRC, I will push it to master in a moment and to the gcc-10 branch immediately after bootstrap on top of it finishes. Thanks, Martin gcc/ChangeLog: 2020-07-03 Martin Jambor PR ipa/96040 * ipa-sra.c (all_callee_accesses_present_p): Do not accept type mismatched accesses. gcc/testsuite/ChangeLog: 2020-07-03 Martin Jambor PR ipa/96040 * gcc.dg/ipa/pr96040.c: New test. --- gcc/ipa-sra.c | 4 ++- gcc/testsuite/gcc.dg/ipa/pr96040.c | 57 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr96040.c diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c index c81e8869e7a..03e3fc55daf 100644 --- a/gcc/ipa-sra.c +++ b/gcc/ipa-sra.c @@ -3271,7 +3271,9 @@ all_callee_accesses_present_p (isra_param_desc *param_desc, continue; param_access *pacc = find_param_access (param_desc, argacc->unit_offset, argacc->unit_size); - if (!pacc || !pacc->certain) + if (!pacc + || !pacc->certain + || !types_compatible_p (argacc->type, pacc->type)) return false; } return true; diff --git a/gcc/testsuite/gcc.dg/ipa/pr96040.c b/gcc/testsuite/gcc.dg/ipa/pr96040.c new file mode 100644 index 00000000000..af7e9c4ed94 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr96040.c @@ -0,0 +1,57 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -std=c99" } */ + + +int puts(const char *); +int snprintf(char *, unsigned long, const char *, ...); +unsigned long strspn(const char *, const char *); + +struct TValue { + union { + long long i; + double n; + } value_; + unsigned char tt_; +}; + +static int tostringbuff (struct TValue *num, char *str) { + int len; + if (num->tt_ == 3) { + len = snprintf(str,50,"%lld",num->value_.i); + } else { + len = snprintf(str,50,"%.14g",num->value_.n); + if (str[strspn(str, "-0123456789")] == '\0') { + str[len++] = '.'; + str[len++] = '0'; + } + } + return len; +} + +void unused (int *buff, struct TValue *num) { + char junk[50]; + *buff += tostringbuff(num, junk); +} + +char space[400]; + +void addnum2buff (int *buff, struct TValue *num) __attribute__((__noinline__)); +void addnum2buff (int *buff, struct TValue *num) { + *buff += tostringbuff(num, space); +} + +int __attribute__((noipa)) check_space (char *s) +{ + return (s[0] == '1' && s[1] == '.' && s[2] =='0' && s[3] == '\0'); +} + +int main(void) { + int buff = 0; + struct TValue num; + num.value_.n = 1.0; + num.tt_ = 19; + addnum2buff(&buff, &num); + if (!check_space(space)) + __builtin_abort (); + return 0; +}