From patchwork Thu Oct 6 20:40:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1687179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=K1XBy87j; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mk3Hh6KZTz20Pd for ; Fri, 7 Oct 2022 07:41:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 73896384B80F for ; Thu, 6 Oct 2022 20:41:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73896384B80F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665088861; bh=IXZYdCQpnXiWeExUnOsPY+Pe7JWlLeEbsqxCDybLO30=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=K1XBy87jeyeNp8VFcG5iW57Rezx/UB3kh8iWJ33SgW/uaVw+CpdbpfYW2vpZ2/aLL zHk2sVm8S7d+ej7NdUvsrCxrSbB90e+6mxni+VCKGDpz6xz6l2ij322jRzVcyei9s1 PRUphu8Va+m1an7Di3Fefou7rln4C/vtqDHwPAwA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 735523858D37 for ; Thu, 6 Oct 2022 20:40:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 735523858D37 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-601-olsY6AE-OnKyW86TCijebw-1; Thu, 06 Oct 2022 16:40:40 -0400 X-MC-Unique: olsY6AE-OnKyW86TCijebw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D24FA811E67 for ; Thu, 6 Oct 2022 20:40:39 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83B8C40C945A; Thu, 6 Oct 2022 20:40:39 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 296KebUh1796216 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 6 Oct 2022 22:40:37 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 296Kebij1796215; Thu, 6 Oct 2022 22:40:37 +0200 To: GCC patches Subject: [COMMITTED] [PR107170] Avoid copying incompatible types in legacy VRP. Date: Thu, 6 Oct 2022 22:40:35 +0200 Message-Id: <20221006204035.1796190-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Legacy VRP is calling ranger deep inside the bowels, and then trying to copy an incompatible type. My previous patch in this area assumed that the only possibility out of vr_values::get_value_range for an unsupported type was VARYING, but UNDEFINED can also be returned. PR tree-optimization/107170 gcc/ChangeLog: * vr-values.cc (vr_values::range_of_expr): Do not die on unsupported types. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107170.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr107170.c | 8 ++++++++ gcc/vr-values.cc | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107170.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c new file mode 100644 index 00000000000..7a5a4a363f2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c @@ -0,0 +1,8 @@ +// { dg-do compile } +// { dg-options "-O2" } + +int main() { + double a; + if (__builtin_signbit(a)) + __builtin_abort(); +} diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index 626a9189472..71fed1e6a7e 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -184,21 +184,23 @@ vr_values::range_of_expr (vrange &r, tree expr, gimple *stmt) if (const value_range *vr = get_value_range (expr, stmt)) { + if (!vr->supports_type_p (TREE_TYPE (expr))) + { + // vr_values::extract_range_basic() use of ranger's + // fold_range() can create a situation where we are asked + // for the range of an unsupported legacy type. Since + // get_value_range() above will return varying or undefined + // for such types, avoid copying incompatible range types. + if (vr->undefined_p ()) + r.set_undefined (); + else + r.set_varying (TREE_TYPE (expr)); + return true; + } if (vr->undefined_p () || vr->constant_p ()) r = *vr; else { - if (!vr->supports_type_p (TREE_TYPE (expr))) - { - // vr_values::extract_range_basic() use of ranger's - // fold_range() can create a situation where we are - // asked for the range of an unsupported legacy type. - // Since get_value_range() above will return varying for - // such types, avoid copying incompatible range types. - gcc_checking_assert (vr->varying_p ()); - r.set_varying (TREE_TYPE (expr)); - return true; - } value_range tmp = *vr; tmp.normalize_symbolics (); r = tmp;