From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C85813858C53 for ; Fri, 21 Jul 2023 00:31:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C85813858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689899512; 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=N7/8D1Nh5ersGJLfp2wrhm82wrl5M4x+AE5/Eho5ajE=; b=CNTRsysJaw5KjLM65kfxqvN9Qc6dMZT4UQkShBxvryBc8KotnLPyh4QxRZGzR859BDF1D0 U1WpMaLpNLbyacuJnMViRc7ocs6+rxzU1ARVo3U1HWXvjNW1b5rETzfgykT49ImnW2HEDf zcaseScrXvRLgkMiSj3DB0eQlronjAk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-125-diRceK2wNFWlZI_C3DrKgg-1; Thu, 20 Jul 2023 20:31:51 -0400 X-MC-Unique: diRceK2wNFWlZI_C3DrKgg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEDB886F124 for ; Fri, 21 Jul 2023 00:31:50 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.8.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B340200B41D; Fri, 21 Jul 2023 00:31:50 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: fix ICE on certain pointer subtractions [PR110387] Date: Thu, 20 Jul 2023 20:31:48 -0400 Message-Id: <20230721003148.339618-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-2688-g5a0aff76a99804. gcc/analyzer/ChangeLog: PR analyzer/110387 * region.h (struct cast_region::key_t): Support "m_type" being null by using "m_original_region" for empty/deleted slots. gcc/testsuite/ChangeLog: PR analyzer/110387 * gcc.dg/analyzer/out-of-bounds-pr110387.c: New test. --- gcc/analyzer/region.h | 16 +++++++++++----- .../gcc.dg/analyzer/out-of-bounds-pr110387.c | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/out-of-bounds-pr110387.c diff --git a/gcc/analyzer/region.h b/gcc/analyzer/region.h index 0c79490c9c0..2cbb9234728 100644 --- a/gcc/analyzer/region.h +++ b/gcc/analyzer/region.h @@ -1107,7 +1107,7 @@ public: key_t (const region *original_region, tree type) : m_original_region (original_region), m_type (type) { - gcc_assert (type); + gcc_assert (original_region); } hashval_t hash () const @@ -1124,10 +1124,16 @@ public: && m_type == other.m_type); } - void mark_deleted () { m_type = reinterpret_cast (1); } - void mark_empty () { m_type = NULL_TREE; } - bool is_deleted () const { return m_type == reinterpret_cast (1); } - bool is_empty () const { return m_type == NULL_TREE; } + void mark_deleted () + { + m_original_region = reinterpret_cast (1); + } + void mark_empty () { m_original_region = nullptr; } + bool is_deleted () const + { + return m_original_region == reinterpret_cast (1); + } + bool is_empty () const { return m_original_region == nullptr; } const region *m_original_region; tree m_type; diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-pr110387.c b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-pr110387.c new file mode 100644 index 00000000000..a046659c83e --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-pr110387.c @@ -0,0 +1,19 @@ +char a, b, c, d; +long x; + +void +_S_copy (long __n) +{ + __builtin_memcpy (&a, &d, __n); /* { dg-prune-output "-Wanalyzer-out-of-bounds" } */ + /* This only warns on some targets; the purpose of the test is to verify that + we don't ICE. */ +} + +void +_M_construct () +{ + x = &c - &b; + unsigned long __dnew = x; + if (__dnew > 1) + _S_copy (&c - &b); +} -- 2.26.3