From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 1F888383B6C7 for ; Thu, 15 Dec 2022 20:29:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F888383B6C7 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=googlemail.com Received: by mail-wm1-x329.google.com with SMTP id o15so415446wmr.4 for ; Thu, 15 Dec 2022 12:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=W0nCi1+tO0Cj5IPVGbsqbSmwJTb0TsTEohsKmN6aQcQ=; b=KSmuVIAtAqAkqQQwdwkXyFgJqGTKdQ60BVthpd3GELRI3w7mUv+Aqjvt6Tbvu8IAKm h08ERkSm//nIwfl92HQPbgT3WYbOOUmcRaLvuf/8V4U9F6+N5qcrketxaJZM/WTVaSw9 fNoLKsS8W+1wNd9M23gftXLEnO0sJUfTu0GVlUx1ouTD4jd46py2hJmjL9BhOhHKew51 UAhDefqhFjQiIiUzJz6GTRR9wRAvaF/Vyn62ltHaiy6Blh3OWpndhhn3a78B6a03amar nMDusj81Ta3l0BBc88Y0UWj1esPVwwboNWBkGEHQwRC3iav9eH9W0rPeLj3moDCcnfaw WxRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W0nCi1+tO0Cj5IPVGbsqbSmwJTb0TsTEohsKmN6aQcQ=; b=s5PNBzfum0VSZrZz6SApUoRpdQ5OsktHthvtLDTkpZ/NHLd0aWerZVZgMRAm67x8Ss rHXS6vCJQj2glOUy0qGHMVWYa4/nYmn1rT0wHG5SIrjdERGM9V5NYRFW0LbEAPNPNRF3 SOqQhvhQPzY2V0YbBzWzj2JeF+/yEnmFYMP1eH9fKPaX9ak3agEKTjkPtzlcGxWE2R0u ixaSnnJFSVjNIVLXBPLQ6IbUWWsMkS58p7taZ6fIagsdJ+pK1O//rt7ChP80SUdsffxv RXK6+RQRAh0IoKNfL8KphAFgQgEB/Cikx+tiGJDWo8qYCZBeWsGYh+lo+OO1RSiicCco TFig== X-Gm-Message-State: ANoB5pmKGgTw7lC01l38bWy+KLuSMZJOh+J7KdQuHtAK2g0NkNshy3SB bUXnIhXbhQABaAZjc2SIPXQ= X-Google-Smtp-Source: AA0mqf6w4DYwyz77eDblMQKv7R1jpzytBdD2OXX73mw+bWK4JoMBCb1JJcFxrZuqNwozvkA0fYE9Og== X-Received: by 2002:a05:600c:3d19:b0:3d0:bd9:edd4 with SMTP id bh25-20020a05600c3d1900b003d00bd9edd4mr23502396wmb.0.1671136146815; Thu, 15 Dec 2022 12:29:06 -0800 (PST) Received: from smtpclient.apple (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.googlemail.com with ESMTPSA id f24-20020a1c6a18000000b003b95ed78275sm183081wmc.20.2022.12.15.12.29.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Dec 2022 12:29:06 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [PATCH] contracts: Stop relying on mangling for naming .pre/.post clones From: Iain Sandoe In-Reply-To: <86bko4ttho.fsf@aarsen.me> Date: Thu, 15 Dec 2022 20:29:05 +0000 Cc: Jason Merrill , GCC Patches Content-Transfer-Encoding: quoted-printable Message-Id: References: <20221210131356.3385654-1-arsen@aarsen.me> <5cc46cd6-5f08-e73a-0db2-ea165a6e7734@redhat.com> <86bko4ttho.fsf@aarsen.me> To: =?utf-8?Q?Arsen_Arsenovi=C4=87?= X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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: Hi Arsen, > On 15 Dec 2022, at 18:00, Arsen Arsenovi=C4=87 via Gcc-patches = wrote: > Jason Merrill writes: >=20 >> On 12/10/22 08:13, Arsen Arsenovi=C4=87 wrote: >>> If the mangler is relied on, functions with extern "C" on them emit = multiple >>> definitions of the same name. >>=20 >> 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. >=20 > 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. >=20 > How about this? Tested on x86_64-pc-linux-gnu via check-g++. >=20 > =46rom 2a2d98e94bdd7a8d7f862b2accda849927e4509e 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 >=20 > This fixes contract-checked extern "C" functions. >=20 > gcc/cp/ChangeLog: >=20 > * mangle.cc (write_encoding): Move contract pre/post function = mangling > from here... > (write_mangled_name): ... to here, and make it happen always. >=20 > gcc/testsuite/ChangeLog: >=20 > * g++.dg/contracts/contracts-externC.C: New test. > --- > 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 >=20 > diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc > index e363ef35b9f..074cf27ec7a 100644 > --- 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"); > } I think you want to use 'write_string (JOIN_STR =E2=80=9Cpre=E2=80=9D);=E2= =80=99 etc. since that handles targets that cannot use a period in symbol names. >=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 > - /* 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"); > - > /* 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/testsuite/g++.dg/contracts/contracts-externC.C > new file mode 100644 > index 00000000000..873056b742b > --- /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 = twice, > +// when wrapping functions in pre- and postconditions. > +// { dg-do link } > +// { dg-options "-std=3Dc++2a -fcontracts = -fcontract-continuation-mode=3Don" } > + > +volatile int x =3D 10; > + > +extern "C" void > +f () > + [[ pre: x < 10 ]] > +{ > +} > + > +int > +main () > + [[ post: x > 10 ]] > +{ > + f(); > +} > --=20 > 2.39.0 >=20 >=20 > I did run c++filt (afaik, it uses the libiberty demangler) on this > revision, and I got: >=20 > .type f(int) [clone .pre], @function > f(int) [clone .pre]: >=20 > out of ``void f(int x) [[ pre: x > 10 ]] {}'', which seems to match = your > description. >=20 > 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. If this is the right place, then I can update my patch for coroutines - = both Gor and Lewis replied that =E2=80=98extern =E2=80=9CC=E2=80=9D=E2=80=99 = coroutines seemed reasonable to them. Iain