From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2100) id 635A9385DC17; Sat, 22 Aug 2020 21:45:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 635A9385DC17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598132729; bh=HUes4e00jslfc7bpnHen1k1OXislL6HZoGQAcLKfbl8=; h=From:To:Subject:Date:From; b=AGNj4w8yUzLvXmssep1cqkWI2T6GPsZNToxY86V3tA3UfMK2t26X0wCLlN7DV/WT+ TYSsZinWMN2/tu/s+jrgvgauWoj7TQlXv7N5XW67ta0DPgwqZWamXGWIX9GA9NwpIJ 5ls/VjiSGUYLiFF1ZqEaZX8zUlK5sAt+hltGe9ss= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Giuliano Belinassi To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/autopar_devel] expr: Fix fallout from optimize store_expr from STRING_CST [PR95052] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/devel/autopar_devel X-Git-Oldrev: b067d98d80c5494baf1af96ebc7bd64f2edf410f X-Git-Newrev: c78815ada99d4dea2118e2df1b01d65ebd7bb1b0 Message-Id: <20200822214529.635A9385DC17@sourceware.org> Date: Sat, 22 Aug 2020 21:45:29 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Aug 2020 21:45:29 -0000 https://gcc.gnu.org/g:c78815ada99d4dea2118e2df1b01d65ebd7bb1b0 commit c78815ada99d4dea2118e2df1b01d65ebd7bb1b0 Author: Jakub Jelinek Date: Sun May 31 10:45:21 2020 +0200 expr: Fix fallout from optimize store_expr from STRING_CST [PR95052] > Can't hurt, and debugging the assert tripping is likely a hell of a lot easier > than debugging the resultant incorrect code. So if it passes, then I'd say go > for it. Testing passed, so I've committed it with those asserts (and thankfully I've added them!) but it apparently broke Linux kernel build on arm. The problem is that if the STRING_CST is very short, while the full object has BLKmode, the short string could very well have QImode/HImode/SImode/DImode and in that case it wouldn't take the path that copies the string and then clears the remaining space, but different paths in which it will ICE because of those asserts and without those it would just emit wrong-code. The following patch fixes it by enforcing BLKmode for the string MEM, even if it is short, so that we copy it and memset the rest. 2020-05-31 Jakub Jelinek PR middle-end/95052 * expr.c (store_expr): For shortedned_string_cst, ensure temp has BLKmode. * gcc.dg/pr95052.c: New test. Diff: --- gcc/expr.c | 5 +++++ gcc/testsuite/gcc.dg/pr95052.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/gcc/expr.c b/gcc/expr.c index 049d3edf3ad..6b75028e7f1 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -5779,6 +5779,11 @@ store_expr (tree exp, rtx target, int call_param_p, (call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL), &alt_rtl, false); + if (shortened_string_cst) + { + gcc_assert (MEM_P (temp)); + temp = change_address (temp, BLKmode, NULL_RTX); + } } /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not diff --git a/gcc/testsuite/gcc.dg/pr95052.c b/gcc/testsuite/gcc.dg/pr95052.c new file mode 100644 index 00000000000..2ed1a037bce --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr95052.c @@ -0,0 +1,12 @@ +/* PR middle-end/95052 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fconserve-stack" } */ + +void bar (char *); + +void +foo (void) +{ + char buf[70] = ""; + bar (buf); +}