From patchwork Mon Jul 29 12:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Arsen_Arsenovi=C4=87?= X-Patchwork-Id: 1965975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aarsen.me header.i=@aarsen.me header.a=rsa-sha256 header.s=MBO0001 header.b=wpiW2xJy; 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 4WXcvH0WvNz1yYq for ; Mon, 29 Jul 2024 22:22:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 52C0E3858408 for ; Mon, 29 Jul 2024 12:22:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by sourceware.org (Postfix) with ESMTPS id 948AD3858CDA for ; Mon, 29 Jul 2024 12:22:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 948AD3858CDA Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 948AD3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.241.56.161 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722255747; cv=none; b=J/KrTcosKAthxp5ho4+6D9L1OBsb7SwZXcwQr928VnyPnXtKelGdiyEeGXMP7eucKUdWN4GYzyoQP+rU8KKu29IcmWs2ZS4VJ8t76Ax/pRmOJxgCDO7M1C1MfMg9q6f53H5I9jT2qKYQskOL1Q0l4nbU2eC8+PXd3i+xgwtcVpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722255747; c=relaxed/simple; bh=PYgqnwFFykVKuAbBxdKAnnnDLPjXVQbo1S1V6OLf0/0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dO2vFYQ7tRWPrzhj0oid5xgWxtAOxtGWZuqk123VFUsqGaFTTUr7fYes7uReZd4Y1y5aLtC6VU5UvAUpQk7/AAGkl0TRKGjcA/Rq99exi85J1FKG+dCeQFhGc538TZjHzI5lmQNxZCrk4mgJ4HZKpXhdq3HxwLvO/ojuSZyMEQY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 mout-p-103.mailbox.org (Postfix) with ESMTPS id 4WXctc1hdzz9ssC; Mon, 29 Jul 2024 14:22:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1722255736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hi84ubQhx6yWSYrJPmzV3Wen0AmtUav6giwOJZAfhUA=; b=wpiW2xJy21XEuBjYQRtmEoB5Ls1Xs2La2aUHa4LGYorNob7ZSUNJjdZ2yjR2Yj9DYk7abP 8QoLrTw5GsSViIyDRKWmUlB3MN7Tm+I2nmAY2otQ1LA5PbWehAwqgzL6rM8BKlYCTsaWe/ PELr/3f6B3wfGvYgcyomx0djkyObmcrYPqexsva48xinkL5EV50sE2jdcj4uHn9tHLlBEX Ej+ncCk7ERiDCtFyNkRvx1b4UAH55p8foD2VkEuz/pHY3lqlPHcc9liA3Z8Gh5LfMzHoMJ 1XNpL/dMMtOT4h91+JOXAQQr4yn/l0dufFIi4+MWNzw3wO5RvFqaMBRZodwbZQ== From: =?utf-8?q?Arsen_Arsenovi=C4=87?= To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Iain Sandoe , =?utf-8?q?Arsen_Arsenovi=C4=87?= Subject: [PATCH] c++: make BUILTIN_SOURCE_LOCATION follow DECL_RAMP_FN Date: Mon, 29 Jul 2024 14:20:19 +0200 Message-ID: <20240729122211.779156-1-arsen@aarsen.me> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4WXctc1hdzz9ssC X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org This fixes the value of current_function in compiler generated coroutine code. PR c++/110855 - std::source_location doesn't work with C++20 coroutine gcc/cp/ChangeLog: PR c++/110855 * cp-gimplify.cc (fold_builtin_source_location): Use the name of the DECL_RAMP_FN of the current function if present. gcc/testsuite/ChangeLog: PR c++/110855 * g++.dg/coroutines/pr110855.C: New test. --- Tested on x86_64-pc-linux-gnu. OK for trunk? TIA, have a lovely day. gcc/cp/cp-gimplify.cc | 9 +++- gcc/testsuite/g++.dg/coroutines/pr110855.C | 61 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr110855.C diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index e6629dea5fdc..651751312fbe 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -3929,7 +3929,14 @@ fold_builtin_source_location (const_tree t) const char *name = ""; if (current_function_decl) - name = cxx_printable_name (current_function_decl, 2); + { + /* If this is a coroutine, we should get the name of the user + function rather than the actor we generate. */ + if (tree ramp = DECL_RAMP_FN (current_function_decl)) + name = cxx_printable_name (ramp, 2); + else + name = cxx_printable_name (current_function_decl, 2); + } val = build_string_literal (name); } diff --git a/gcc/testsuite/g++.dg/coroutines/pr110855.C b/gcc/testsuite/g++.dg/coroutines/pr110855.C new file mode 100644 index 000000000000..6b5c0147ec83 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr110855.C @@ -0,0 +1,61 @@ +// { dg-do run } +// { dg-output {^} } +// { dg-output {ReturnObject bar\(int, char, bool\)(\n|\r\n|\r)} } +// { dg-output {ReturnObject bar\(int, char, bool\)(\n|\r\n|\r)} } +// { dg-output {ReturnObject bar\(int, char, bool\)(\n|\r\n|\r)} } +// { dg-output {ReturnObject bar\(int, char, bool\)(\n|\r\n|\r)} } +// { dg-output {ReturnObject bar\(int, char, bool\)(\n|\r\n|\r)} } +// { dg-output {$} } +// https://gcc.gnu.org/PR110855 +#include +#include + +struct ReturnObject { + struct promise_type { + auto + initial_suspend(const std::source_location location = + std::source_location::current()) { + __builtin_puts (location.function_name ()); + return std::suspend_never{}; + } + auto + final_suspend(const std::source_location location = + std::source_location::current()) noexcept { + __builtin_puts (location.function_name ()); + return std::suspend_never{}; + } + auto + get_return_object(const std::source_location location = + std::source_location::current()) { + __builtin_puts (location.function_name ()); + return ReturnObject{std::coroutine_handle::from_promise(*this)}; + } + auto + unhandled_exception() { } + auto return_void(const std::source_location location = + std::source_location::current()) { + __builtin_puts (location.function_name ()); + } + }; + std::coroutine_handle<> handle; +}; + +struct awaitable : std::suspend_never +{ + void await_resume(const std::source_location location = + std::source_location::current()) + { + __builtin_puts (location.function_name ()); + } +}; + +ReturnObject +bar(int, char, bool) { + co_await awaitable{}; + co_return; +} + +int +main() { + bar(1, 'a', false); +}