From patchwork Fri Apr 29 12:01:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 616696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3qxC3f082pz9t7j for ; Fri, 29 Apr 2016 22:01:49 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=twadtXp8; dkim-atps=neutral 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=JYpnQeP8s5K7OaqNmCp592Vvuqq3MRej1Jii5Mfwd/gwWuKSOIXlU Q1eKE1DiHe/H1k/fCA//CH7mW6x2VkuTrBGtW94JRcSI8bL0PEA57w8ZcBVm3fra sWhgZfaljoUaGDCoZV1OrG2xG7CTIVBPWKZZrULjtIbwBRWFJabmc4= 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=ljxs0gLEkkDiCOLcwnxzatwORPw=; b=twadtXp83tLXwSQ37+qE +4TJfIaqQB7R390oBngvAGFoYmZb5mVOQ7PqueWFhZHSRGabZVs8djFtsafhezA8 iZBqB1fZYnKjG3rnfNIyi4eJvxZ85jvbiAw3GpQv6vx3yo93sAWddj6r7VuSYkK8 5ltd6JJDCbBArRNclcNwrPo= Received: (qmail 113381 invoked by alias); 29 Apr 2016 12:01:42 -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 113366 invoked by uid 89); 29 Apr 2016 12:01:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1220 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 29 Apr 2016 12:01:40 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8780347046 for ; Fri, 29 Apr 2016 12:01:39 +0000 (UTC) Received: from redhat.com (ovpn-204-17.brq.redhat.com [10.40.204.17]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3TC1aJf007926 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 29 Apr 2016 08:01:38 -0400 Date: Fri, 29 Apr 2016 14:01:36 +0200 From: Marek Polacek To: GCC Patches Subject: [PATCH] Fix warn_for_memset ICE (PR c/70852) Message-ID: <20160429120136.GA5348@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.0 (2016-04-01) Here, we segv because we're checking TYPE_MAXVAL of domain that is actually null for "extern int a[];". The fix is trivial. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-04-29 Marek Polacek PR c/70852 * c-common.c (warn_for_memset): Check domain before accessing it. * gcc.dg/pr70852.c: New test. Marek diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index c086dee..88507a2 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -11796,6 +11796,7 @@ warn_for_memset (location_t loc, tree arg0, tree arg2, tree elt_type = TREE_TYPE (type); tree domain = TYPE_DOMAIN (type); if (!integer_onep (TYPE_SIZE_UNIT (elt_type)) + && domain != NULL_TREE && TYPE_MAXVAL (domain) && TYPE_MINVAL (domain) && integer_zerop (TYPE_MINVAL (domain)) diff --git gcc/testsuite/gcc.dg/pr70852.c gcc/testsuite/gcc.dg/pr70852.c index e69de29..2dec082 100644 --- gcc/testsuite/gcc.dg/pr70852.c +++ gcc/testsuite/gcc.dg/pr70852.c @@ -0,0 +1,11 @@ +/* PR c/70852 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +extern void *memset (void *, int, __SIZE_TYPE__); +extern int A[]; +void +fn1 (void) +{ + memset (A, 0, 1); +}