From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by sourceware.org (Postfix) with ESMTPS id E53EF388C5FA for ; Thu, 15 Dec 2022 18:25:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E53EF388C5FA Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4NY0yJ512Rz9sTT; Thu, 15 Dec 2022 19:24:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1671128696; 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: in-reply-to:in-reply-to:references:references; bh=p2pKcqOVAnN6DA1ufKvZWvQTe6KLrouGGC/KIM75Lmw=; b=1V8H1wc9i1Tj5s4xFskgGa6yO/ldcz3DCMtnBsi+fjFxCyWQxBaN5J/EYT3KtoOKLAcizv ieOT/5VDghMay7UBYoL5+TQS1Tndj0ZiPa+Vuks44cOwoEbZg46Rzd/kp0cYMGPT4urSBb LOlOxzcuXkHEo7usbDA8E5FS4aT/Rxr0Je05U8gQEhBGGBu8W1PMvbADWxWz5HW/qeKqGE RyDtkKfbq20YbZDmclfG2mkQ6XQ2jzOc4x2uhJPxH0/VS4Hlus6DQzNegKr8pP9h1o4g03 c0A/IimvuVuJEl8s8YQNrzYONe80t/uX1P1rjuS6DgDcv6YsgnHP+36n2Scnkw== References: <20221210131356.3385654-1-arsen@aarsen.me> <5cc46cd6-5f08-e73a-0db2-ea165a6e7734@redhat.com> From: Arsen =?utf-8?Q?Arsenovi=C4=87?= To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] contracts: Stop relying on mangling for naming .pre/.post clones Date: Thu, 15 Dec 2022 19:00:56 +0100 In-reply-to: <5cc46cd6-5f08-e73a-0db2-ea165a6e7734@redhat.com> Message-ID: <86bko4ttho.fsf@aarsen.me> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Rspamd-Queue-Id: 4NY0yJ512Rz9sTT X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,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 List-Id: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Jason, Jason Merrill writes: > On 12/10/22 08:13, Arsen Arsenovi=C4=87 wrote: >> If the mangler is relied on, functions with extern "C" on them emit mult= iple >> definitions of the same name. > > But doing it here interferes with lazy mangling. How about appending the > suffix into write_mangled_name instead of write_encoding? The demangler > already expects "clone" suffixes at the end of the mangled name. Ah, sorry. I'm not well versed in the mangler code, so I didn't realize (frankly, I was initially surprised when I saw that DECL_ASSEMBLER_NAME was set that early, but went with it). That makes sense. How about this? Tested on x86_64-pc-linux-gnu via check-g++. --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=v2-0001-c-Mangle-contracts-in-write_mangled_name-uncondit.patch Content-Transfer-Encoding: quoted-printable Content-Description: c++: Mangle contracts in write_mangled_name unconditionally From=202a2d98e94bdd7a8d7f862b2accda849927e4509e Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Arsen=3D20Arsenovi=3DC4=3D87?=3D Date: Thu, 15 Dec 2022 18:56:59 +0100 Subject: [PATCH v2] c++: Mangle contracts in write_mangled_name unconditionally This fixes contract-checked extern "C" functions. gcc/cp/ChangeLog: * mangle.cc (write_encoding): Move contract pre/post function mangling from here... (write_mangled_name): ... to here, and make it happen always. gcc/testsuite/ChangeLog: * g++.dg/contracts/contracts-externC.C: New test. =2D-- gcc/cp/mangle.cc | 14 +++++++------- .../g++.dg/contracts/contracts-externC.C | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/contracts/contracts-externC.C diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index e363ef35b9f..074cf27ec7a 100644 =2D-- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -798,6 +798,13 @@ write_mangled_name (const tree decl, bool top_level) write_string ("_Z"); write_encoding (decl); } + + /* If this is the pre/post function for a guarded function, append + .pre/post, like something from create_virtual_clone. */ + if (DECL_IS_PRE_FN_P (decl)) + write_string (".pre"); + else if (DECL_IS_POST_FN_P (decl)) + write_string (".post"); } =20 /* Returns true if the return type of DECL is part of its signature, and @@ -856,13 +863,6 @@ write_encoding (const tree decl) mangle_return_type_p (decl), d); =20 =2D /* If this is the pre/post function for a guarded function, append =2D .pre/post, like something from create_virtual_clone. */ =2D if (DECL_IS_PRE_FN_P (decl)) =2D write_string (".pre"); =2D else if (DECL_IS_POST_FN_P (decl)) =2D write_string (".post"); =2D /* If this is a coroutine helper, then append an appropriate string = to identify which. */ if (tree ramp =3D DECL_RAMP_FN (decl)) diff --git a/gcc/testsuite/g++.dg/contracts/contracts-externC.C b/gcc/tests= uite/g++.dg/contracts/contracts-externC.C new file mode 100644 index 00000000000..873056b742b =2D-- /dev/null +++ b/gcc/testsuite/g++.dg/contracts/contracts-externC.C @@ -0,0 +1,19 @@ +// simple check to ensure we don't emit a function with the same name twic= e, +// when wrapping functions in pre- and postconditions. +// { dg-do link } +// { dg-options "-std=3Dc++2a -fcontracts -fcontract-continuation-mode=3Do= n" } + +volatile int x =3D 10; + +extern "C" void +f () + [[ pre: x < 10 ]] +{ +} + +int +main () + [[ post: x > 10 ]] +{ + f(); +} =2D-=20 2.39.0 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I did run c++filt (afaik, it uses the libiberty demangler) on this revision, and I got: .type f(int) [clone .pre], @function f(int) [clone .pre]: out of ``void f(int x) [[ pre: x > 10 ]] {}'', which seems to match your description. If I understand this right, write_xxx corresponds to xxx in the Itanium ABI mangling BNF, in which case, I believe I have the correct spot here. In that case, a similar change should happen for coroutines; I think Iain was working on that. Thanks, have a great day. =2D-=20 Arsen Arsenovi=C4=87 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iOYEARYKAI4WIQT+4rPRE/wAoxYtYGFSwpQwHqLEkwUCY5tmc18UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0RkVF MkIzRDExM0ZDMDBBMzE2MkQ2MDYxNTJDMjk0MzAxRUEyQzQ5MxAcYXJzZW5AYWFy c2VuLm1lAAoJEFLClDAeosST/KQBAPA2WNfy+RjLlk5P07KP9XlUD974Xb63o79d /UPCjVaTAP0RfVLmPJqzIvJ4AUf15pVZUV0whRrl7G09vs5kOMWYAg== =cWpS -----END PGP SIGNATURE----- --==-=-=--