From patchwork Tue Feb 11 18:41:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1236429 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519361-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=D3tPAu/I; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XW3oDH4E; 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 48HBT10RZ0z9sP7 for ; Wed, 12 Feb 2020 05:41:56 +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:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=xco1hZmvKD72GN/t q3jXPxJTHJKYtuUfhnHs+txZgyzJpOu9VDcovg5r1PQ5GptzYUqraVoQtE2ecfkF thP3u04yWFyOtB1uqlv3NnCIcayeEUGkVs1UStac2Zx4SajiAw0A6REN+K74PRZu U1wqMq1NNx+EycP4sHh+x6H3aCM= 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:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=UGvl0YOz7rudxubIGxaRB9 lTldQ=; b=D3tPAu/Id6gBGEHFzgXMh87m0Wm8FQrD9LsgN94ne1JwoUQyISrO52 E0sgfNofEpqloQivA0LJDG1nD6URgcYEQi5aqiAPwQCOPiMTALsXxKJSUK8k1YRi Vcn0dD37RerkKS4pp8tVXYKflPjper6d3gR8Z8BfNxOdp4IHAiUeQ= Received: (qmail 109789 invoked by alias); 11 Feb 2020 18:41:48 -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 109775 invoked by uid 89); 11 Feb 2020 18:41:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 18:41:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581446505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=v+1VhCBe9vDF5NnULeZuH8LgRqRMBtJ7CMCGZ9uFiKQ=; b=XW3oDH4EVEHhMJ6jNDeEEJWKwAOmcvWd68kgYmCrlijNmFUU/khnf6Mbfm/lurSqccGLfH 9lIeYnDOgY1Uav+3ONW970d3lq1xbuQxV72Rj4TVoaaQ+O4bN3J7ETzIqEL6iOFHL6E3JX Qjz50v18XTNFTUrlazKWOp5T5cjTO6M= 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-348-CTTBxW83PKSooggCj1Bwaw-1; Tue, 11 Feb 2020 13:41:33 -0500 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 E9D56802722 for ; Tue, 11 Feb 2020 18:41:32 +0000 (UTC) Received: from t470.redhat.com (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id D422E60BF1; Tue, 11 Feb 2020 18:41:30 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: fix ICE with equiv_class constant (PR 93649) Date: Tue, 11 Feb 2020 13:41:28 -0500 Message-Id: <20200211184128.5109-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to master as r10-6580-gcd28b75921354c64fd4c8a1c238991e522abc38e. gcc/analyzer/ChangeLog: PR analyzer/93649 * constraint-manager.cc (constraint_manager::add_constraint): When merging equivalence classes and updating m_constant, also update m_cst_sid. (constraint_manager::validate): If m_constant is non-NULL assert that m_cst_sid is non-null and is valid. gcc/testsuite/ChangeLog: PR analyzer/93649 * gcc.dg/analyzer/torture/pr93649.c: New test. --- gcc/analyzer/constraint-manager.cc | 8 ++- .../gcc.dg/analyzer/torture/pr93649.c | 66 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/pr93649.c diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc index d5a6939e714..a6235435681 100644 --- a/gcc/analyzer/constraint-manager.cc +++ b/gcc/analyzer/constraint-manager.cc @@ -686,8 +686,8 @@ constraint_manager::add_constraint (equiv_class_id lhs_ec_id, if (rhs_ec_obj.m_constant) { - //gcc_assert (lhs_ec_obj.m_constant == NULL); lhs_ec_obj.m_constant = rhs_ec_obj.m_constant; + lhs_ec_obj.m_cst_sid = rhs_ec_obj.m_cst_sid; } /* Drop rhs equivalence class, overwriting it with the @@ -1516,7 +1516,11 @@ constraint_manager::validate () const gcc_assert (sid->as_int () < get_num_svalues ()); } if (ec->m_constant) - gcc_assert (CONSTANT_CLASS_P (ec->m_constant)); + { + gcc_assert (CONSTANT_CLASS_P (ec->m_constant)); + gcc_assert (!ec->m_cst_sid.null_p ()); + gcc_assert (ec->m_cst_sid.as_int () < get_num_svalues ()); + } #if 0 else gcc_assert (ec->m_vars.length () > 0); diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr93649.c b/gcc/testsuite/gcc.dg/analyzer/torture/pr93649.c new file mode 100644 index 00000000000..9d929395bb4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/pr93649.c @@ -0,0 +1,66 @@ +/* { dg-additional-options "-Wno-incompatible-pointer-types -Wno-analyzer-too-complex" } */ +/* TODO: ideally we shouldn't have -Wno-analyzer-too-complex above; it + appears to be needed due to the recursion. */ + +struct tz { + int qc; +}; + +struct wp { + struct tz *p2; +} *ov; + +struct dz { + struct wp *r5; +}; + +void +za (void); + +void +h5 (struct dz *); + +int +e7 (struct wp *f2) +{ + return f2 == ov; +} + +void +wr (struct wp *sw) +{ + if (sw != 0) + za (); +} + +void +m6 (const struct dz *gq) +{ + wr (gq->r5); + + asm ("" : "+m" (gq)); + + if (0) + { + asm ("" : "+m" (gq->r5->p2->qc)); + asm ("" : "+m" (gq->r5->p2->qc)); + } + + asm ("" : "+m" (gq->r5->p2->qc)); + + if (e7 (gq->r5)) + za (); +} + +void +ts (struct dz *cx) +{ + struct dz nt; + + if (nt.r5) + { + m6 (cx); + h5 (cx); + ts (&cx); + } +}