From patchwork Mon Dec 18 15:10:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 850103 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-469467-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GakDY0pl"; 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 3z0kxc4jcTz9sBW for ; Tue, 19 Dec 2017 02:10:44 +1100 (AEDT) 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=dH5hPE2Xx3eMvJi5f/Q2YPSoiLbN5/2zXEgbdmquz45O6vTfAx+la jxP3tie6qlpg8Hzvr5Hppr7WLengkZGNYUdBUwYp7lNFFSLh4or5GRBX7JN1QE0C TkvqInhFSMMZOl2n35Gn2Qkk5BP/Xl/Oh1WSceNvDsxdiNZN/fDvMU= 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:subject:message-id:mime-version:content-type; s= default; bh=AtvogmmP/hD0H1cCQz8aVWk2dPM=; b=GakDY0plikkHDMdFEiLz sVmC5DujiIt7JQAWE9zEkxqQoZhTStnZPgmWM1ymYbRnLXa8v3aSZV39kNnNhoYa g3elwxCNNrSbRBry9kZE+oDD3o5WLocN5fUdkOMLlG19/eAzPgxX2mEdScIkiqWS zQBrTQ2CauECICo5KOkE0HQ= Received: (qmail 98816 invoked by alias); 18 Dec 2017 15:10:37 -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 98806 invoked by uid 89); 18 Dec 2017 15:10:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= 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; Mon, 18 Dec 2017 15:10:36 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5604280C06 for ; Mon, 18 Dec 2017 15:10:35 +0000 (UTC) Received: from redhat.com (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9150B7F785; Mon, 18 Dec 2017 15:10:34 +0000 (UTC) Date: Mon, 18 Dec 2017 16:10:22 +0100 From: Marek Polacek To: GCC Patches , Martin Sebor Subject: PATCH to fix -Wrestrict ICE (PR middle-end/83463) Message-ID: <20171218151022.GL2605@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) I'm not entirely up to speed with this code, but this one seemed sufficiently obvious: check INTEGRAL_TYPE_P before looking at a tree's min/max value. Otherwise, go with maxobjsize. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-12-18 Marek Polacek PR middle-end/83463 * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Check if TYPE is INTEGRAL_TYPE_P before accessing its min/max values. * gcc.dg/pr83463.c: New test. Marek diff --git gcc/gimple-ssa-warn-restrict.c gcc/gimple-ssa-warn-restrict.c index 4d424735d2a..d1a376637a2 100644 --- gcc/gimple-ssa-warn-restrict.c +++ gcc/gimple-ssa-warn-restrict.c @@ -287,13 +287,15 @@ builtin_memref::builtin_memref (tree expr, tree size) else { gimple *stmt = SSA_NAME_DEF_STMT (offset); + tree type; if (is_gimple_assign (stmt) - && gimple_assign_rhs_code (stmt) == NOP_EXPR) + && gimple_assign_rhs_code (stmt) == NOP_EXPR + && (type = TREE_TYPE (gimple_assign_rhs1 (stmt))) + && INTEGRAL_TYPE_P (type)) { /* Use the bounds of the type of the NOP_EXPR operand even if it's signed. The result doesn't trigger warnings but makes their output more readable. */ - tree type = TREE_TYPE (gimple_assign_rhs1 (stmt)); offrange[0] = wi::to_offset (TYPE_MIN_VALUE (type)); offrange[1] = wi::to_offset (TYPE_MAX_VALUE (type)); } diff --git gcc/testsuite/gcc.dg/pr83463.c gcc/testsuite/gcc.dg/pr83463.c index e69de29bb2d..735ef3c6dc8 100644 --- gcc/testsuite/gcc.dg/pr83463.c +++ gcc/testsuite/gcc.dg/pr83463.c @@ -0,0 +1,17 @@ +/* PR middle-end/83463 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wrestrict" } */ + +int *a; +void *memcpy (); +void +m (void *p1) +{ + memcpy (0, p1, 0); +} + +void +p () +{ + m (p + (long) a); +}