From patchwork Wed Aug 19 01:23:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1347377 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=rPorjX/b; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4BWVSB1n4hz9sPC for ; Wed, 19 Aug 2020 11:24:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 48EC83857C66; Wed, 19 Aug 2020 01:24:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48EC83857C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597800259; bh=zolMjLVxtjHpYDyLsciIkyG5OwnDN5NM5fKSZST0Wus=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rPorjX/boiH7agZVESUxXTSo9zVdIS8nt3T5Sg1XuJ8/cFijdrM8GHX6iHGPP8x8y kK0dvTRFqOcqoCI1zAbr1aQTjr/XFLSEqQpOJmUhtbw2Hdbc8ylVVW61gwOwPDtXnq o50205WjD5Tz5v30wtmtyMhLdC8+hlIELt0rxPGM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 8ACB13857C5B for ; Wed, 19 Aug 2020 01:24:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8ACB13857C5B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-529-4M4KPWqiOomwbEJsVOqvQA-1; Tue, 18 Aug 2020 21:23:57 -0400 X-MC-Unique: 4M4KPWqiOomwbEJsVOqvQA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B06DB1084C82 for ; Wed, 19 Aug 2020 01:23:56 +0000 (UTC) Received: from t470.redhat.com (ovpn-113-239.phx2.redhat.com [10.3.113.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ADF759; Wed, 19 Aug 2020 01:23:56 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: fix ICE with negative bit offsets [PR96648] Date: Tue, 18 Aug 2020 21:23:54 -0400 Message-Id: <20200819012354.28402-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" PR analyzer/96648 reports an ICE within get_field_at_bit_offset due to a negative bit offset, arising due to pointer arithmetic. This patch replaces an assertion with handling for this case, fixing the ICE. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to master as r11-2753-g400abebf48a90d0797718ab7c3864de331e85b70. gcc/analyzer/ChangeLog: PR analyzer/96648 * region.cc (get_field_at_bit_offset): Gracefully handle negative values for bit_offset. gcc/testsuite/ChangeLog: PR analyzer/96648 * gcc.dg/analyzer/pr96648.c: New test. --- gcc/analyzer/region.cc | 3 ++- gcc/testsuite/gcc.dg/analyzer/pr96648.c | 36 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr96648.c diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index eab1f2771cf..770e2cb849e 100644 --- a/gcc/analyzer/region.cc +++ b/gcc/analyzer/region.cc @@ -226,7 +226,8 @@ static tree get_field_at_bit_offset (tree record_type, bit_offset_t bit_offset) { gcc_assert (TREE_CODE (record_type) == RECORD_TYPE); - gcc_assert (bit_offset >= 0); + if (bit_offset < 0) + return NULL; /* Find the first field that has an offset > BIT_OFFSET, then return the one preceding it. diff --git a/gcc/testsuite/gcc.dg/analyzer/pr96648.c b/gcc/testsuite/gcc.dg/analyzer/pr96648.c new file mode 100644 index 00000000000..a6b0c727287 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr96648.c @@ -0,0 +1,36 @@ +/* { dg-additional-options "-O1" } */ + +struct vd { + struct vd *rs; +}; + +struct fh { + struct vd cl; +}; + +struct i3 { + struct fh *h4; +}; + +struct fh * +gm (void); + +void +j7 (struct vd *); + +inline void +mb (struct vd *e7) +{ + j7 (e7->rs); +} + +void +po (struct i3 *d2) +{ + struct i3 *s2; + + d2->h4 = gm (); + mb (&d2->h4->cl); + s2 = ({ d2 - 1; }); + po (s2); +}