From patchwork Fri Apr 5 07:35:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1920054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d9qNTMcO; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V9qzS6v9zz1yZH for ; Fri, 5 Apr 2024 18:36:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D7143846401 for ; Fri, 5 Apr 2024 07:36:01 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 37A36384772F for ; Fri, 5 Apr 2024 07:35:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37A36384772F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 37A36384772F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712302540; cv=none; b=ac3Qc3SHkNRwPfuv7NV0D51IwHpVdHclj66C1HyO577DPgI0GVppe0WbSFLIesQSXkrxeX4N6H6cxELydcu08uk4oJkL5Dse2I7P1hTBSDvUrX7Vg6MReOty+9QnPCaiu/PCa9wfXxAj/2hK0K/LeBVejN/dufu4do3nlSGO6KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712302540; c=relaxed/simple; bh=37YtSrJ9tro68lJ/m0LMNyFBHlrp2UuWUiZNCB3t2wM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=CXJ8p8rYIa3NYlkM+d4L6GaeUF5mn9X0Q0ddCqWj6/Maj2rSj66kTAEtVzw95A9l3Evfevt1SM3m7VLCxJYikoufJvjP/g9dZAi6ZAbmTpCFSz5Bnl+gav5zgA870I09MEvXgRuFZ9HXS1ZptF+9vhFyoF9RJPwsv3zqjyd2358= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712302538; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=1+vHsGM+X/hdN2/LlODDJZWOI4wqwIvtpzGT67eNhBA=; b=d9qNTMcObun0J4u0c+bkjEpvCppohbjFBQ7ADKtVAs0SJixktPMutgw6IdNW+blb+gydFL oPAYiMPDMYaYUHu1k9MbIiGDE9407A6JzBWSzXyxPDzi1Vxnca04qHbQWMBLgHfpgUeIh8 8Kk6yu1h+k7RBeBsd8SCmD6enKBfvIo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-12-YWMgG7lLP3-E-dSlrTv2Pg-1; Fri, 05 Apr 2024 03:35:36 -0400 X-MC-Unique: YWMgG7lLP3-E-dSlrTv2Pg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D477F3C0F199; Fri, 5 Apr 2024 07:35:35 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99D54200A386; Fri, 5 Apr 2024 07:35:35 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 4357ZTGf2322581 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 5 Apr 2024 09:35:29 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4357ZT7m2322580; Fri, 5 Apr 2024 09:35:29 +0200 Date: Fri, 5 Apr 2024 09:35:29 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] c++: Fix ICE with weird copy assignment operator [PR114572] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 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_H4, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! While ctors/dtors don't return anything (undeclared void or this pointer on arm) and copy assignment operators normally return a reference to *this, it isn't invalid to return uselessly some class object which might need destructing, but the OpenMP clause handling code wasn't expecting that. The following patch fixes that. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so far. 2024-04-05 Jakub Jelinek PR c++/114572 * cp-gimplify.cc (cxx_omp_clause_apply_fn): Call build_cplus_new on build_call_a result if it has class type. * testsuite/libgomp.c++/pr114572.C: New test. Jakub --- gcc/cp/cp-gimplify.cc.jj 2024-04-02 13:07:58.540385210 +0200 +++ gcc/cp/cp-gimplify.cc 2024-04-04 16:41:50.781008370 +0200 @@ -2480,6 +2480,8 @@ cxx_omp_clause_apply_fn (tree fn, tree a TREE_PURPOSE (parm), fn, i - is_method, tf_warning_or_error); t = build_call_a (fn, i, argarray); + if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t))) + t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error); t = fold_convert (void_type_node, t); t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); append_to_statement_list (t, &ret); @@ -2513,6 +2515,8 @@ cxx_omp_clause_apply_fn (tree fn, tree a TREE_PURPOSE (parm), fn, i - is_method, tf_warning_or_error); t = build_call_a (fn, i, argarray); + if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t))) + t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error); t = fold_convert (void_type_node, t); return fold_build_cleanup_point_expr (TREE_TYPE (t), t); } --- libgomp/testsuite/libgomp.c++/pr114572.C.jj 2024-04-04 16:45:27.070034421 +0200 +++ libgomp/testsuite/libgomp.c++/pr114572.C 2024-04-04 16:45:03.529358222 +0200 @@ -0,0 +1,24 @@ +// PR c++/114572 +// { dg-do run } +// { dg-options "-fopenmp -O0" } + +#include + +struct S +{ + S () : s (0) {} + ~S () {} + S operator= (const S &x) { s = x.s; return *this; } + int s; +}; + +int +main () +{ + S s; + #pragma omp parallel for lastprivate(s) + for (int i = 0; i < 10; ++i) + s.s = i; + if (s.s != 9) + abort (); +}