From patchwork Thu Dec 9 22:16:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 48731 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0BB543858430 for ; Thu, 9 Dec 2021 22:17:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BB543858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639088251; bh=eIstB/z6iPkvLxAXkeOI4Cc/GJ3ggE4meC330ESsyqc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=afewzLv3k3ZNDTgO5WwPgxM0VdZ1yO6y8xyVQVgYkJvHUyXeW1VUod7t9c84UnSe9 NHM61I/zwjyxidOj4IRFP1XmchfXxL4gO5xUdwHvLo6/EjJwkfoejRCMcHZm/rlAyj baXV7kajxvZLoCf+0Y0SJxmpCGyhXCBTPB+zAFus= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id 884933858C27 for ; Thu, 9 Dec 2021 22:17:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 884933858C27 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5D593116D4E; Thu, 9 Dec 2021 17:17:01 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id qwdBmnAhl0-o; Thu, 9 Dec 2021 17:17:01 -0500 (EST) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 2297D116D1A; Thu, 9 Dec 2021 17:17:00 -0500 (EST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 1B9MGmJC962403 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 9 Dec 2021 19:16:53 -0300 To: gcc-patches@gcc.gnu.org Subject: [PR100843] store by mult pieces: punt on max_len < min_len Organization: Free thinker, does not speak for AdaCore Date: Thu, 09 Dec 2021 19:16:47 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Cc: cnsun@uwaterloo.ca Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The testcase confuses the code that detects min and max len for the memset, so max_len ends up less than min_len. That shouldn't be possible, but the testcase requires us to handle this case. The store-by-mult-pieces algorithm actually relies on min and max lengths, so if we find them to be inconsistent, the best we can do is punting. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog PR middle-end/100843 * builtins.c (try_store_by_multiple_pieces): Fail if min_len is greater than max_len. for gcc/testsuite/ChangeLog PR middle-end/100843 * gcc.dg/pr100843.c: New. --- gcc/builtins.c | 3 ++- gcc/testsuite/gcc.dg/pr100843.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr100843.c diff --git a/gcc/builtins.c b/gcc/builtins.c index 03829c03a5a11..304d87dafb750 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3963,7 +3963,8 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len, else if (max_len == min_len) blksize = max_len; else - gcc_unreachable (); + /* Huh, max_len < min_len? Punt. See pr100843.c. */ + return false; if (min_len >= blksize) { min_len -= blksize; diff --git a/gcc/testsuite/gcc.dg/pr100843.c b/gcc/testsuite/gcc.dg/pr100843.c new file mode 100644 index 0000000000000..695a2ec3f6818 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100843.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -w" } */ + +char c; +void *memset(); +void test_integer_conversion_memset(void *d) { + memset(d, '\0', c); +}