From patchwork Tue Aug 4 08:39:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1340733 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=8.43.85.97; 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=iz6F/yVs; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4BLSqB2rLmz9sRR for ; Tue, 4 Aug 2020 18:39:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95A013842419; Tue, 4 Aug 2020 08:39:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95A013842419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596530369; bh=Yr+8zEK8WEvz76cF6KwidRD+aFB98LVqZDotMZE+L4Y=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=iz6F/yVsTlWq5RjHTXf5/+S6hZmSJBF/vv7hc+XenpQ4rzToRXnkodjc8EcRSIdAB XCKBjEtkWaMfItF84XqajA+IkuUj+SPZ+MWBm823ZJsgLPpYii7Qo54j5kNj4J/gVo 7KmXMF4fkOxMcJBm6Ou/NkHWaUYXmKdfPGyCks6k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id F29B4384403F for ; Tue, 4 Aug 2020 08:39:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F29B4384403F 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-126-Nogrkpt5Mo-sp91bGc_Ulg-1; Tue, 04 Aug 2020 04:39:24 -0400 X-MC-Unique: Nogrkpt5Mo-sp91bGc_Ulg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BDF68800685; Tue, 4 Aug 2020 08:39:23 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-174.ams2.redhat.com [10.36.113.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5546374F58; Tue, 4 Aug 2020 08:39:23 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 0748dKwl031225; Tue, 4 Aug 2020 10:39:20 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 0748dJOX031224; Tue, 4 Aug 2020 10:39:19 +0200 Date: Tue, 4 Aug 2020 10:39:19 +0200 To: Richard Biener Subject: [PATCH] gimple-fold: Fix ICE in maybe_canonicalize_mem_ref_addr on debug stmt [PR96354] Message-ID: <20200804083919.GY2363@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! In debug stmts, we are less strict about what is and what is not accepted there, so this patch just punts on optimization of a debug stmt rather than ICEing. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-08-04 Jakub Jelinek PR debug/96354 * gimple-fold.c (maybe_canonicalize_mem_ref_addr): Add IS_DEBUG argument. Return false instead of gcc_unreachable if it is true and get_addr_base_and_unit_offset returns NULL. (fold_stmt_1) : Adjust caller. * g++.dg/opt/pr96354.C: New test. Jakub --- gcc/gimple-fold.c.jj 2020-07-28 15:39:09.908757602 +0200 +++ gcc/gimple-fold.c 2020-08-03 13:23:57.579436442 +0200 @@ -4875,7 +4875,7 @@ replace_stmt_with_simplification (gimple /* Canonicalize MEM_REFs invariant address operand after propagation. */ static bool -maybe_canonicalize_mem_ref_addr (tree *t) +maybe_canonicalize_mem_ref_addr (tree *t, bool is_debug = false) { bool res = false; tree *orig_t = t; @@ -4939,7 +4939,11 @@ maybe_canonicalize_mem_ref_addr (tree *t base = get_addr_base_and_unit_offset (TREE_OPERAND (addr, 0), &coffset); if (!base) - gcc_unreachable (); + { + if (is_debug) + return false; + gcc_unreachable (); + } TREE_OPERAND (*t, 0) = build_fold_addr_expr (base); TREE_OPERAND (*t, 1) = int_const_binop (PLUS_EXPR, @@ -5119,7 +5123,7 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, if (*val && (REFERENCE_CLASS_P (*val) || TREE_CODE (*val) == ADDR_EXPR) - && maybe_canonicalize_mem_ref_addr (val)) + && maybe_canonicalize_mem_ref_addr (val, true)) changed = true; } break; --- gcc/testsuite/g++.dg/opt/pr96354.C.jj 2020-07-29 11:25:15.701164242 +0200 +++ gcc/testsuite/g++.dg/opt/pr96354.C 2020-07-29 11:26:16.490291018 +0200 @@ -0,0 +1,24 @@ +// PR debug/96354 +// { dg-do compile } +// { dg-options "-O2 -g -fopenmp-simd" } + +template struct A { typedef double T[N]; }; +template struct B { typename A::T b; double *baz () { return b; } }; +template struct C { B d; C (); }; +template C::C () { double c = *d.baz (); } +template void operator- (C, const C &); +template struct D {}; +template C foo (D, C) { C t; return t; } +int e; +struct E { D<3> d; void bar (); }; + +void +E::bar () +{ +#pragma omp simd + for (int i = 0; i < e; i++) + { + C<3> f, g; + g - foo (d, f); + } +}