From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 3EA1338582B7; Thu, 15 Dec 2022 21:48:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EA1338582B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671140909; bh=iphYcHzkLM9NnvJ2UesRdunqMk9tcWzCjqBTU8owoAc=; h=From:To:Subject:Date:From; b=gnVBnTbA5A4rPSBrhbvKfOh3jmOaPbhOLHUTqt9yYxixy3qOpH2bhWDD4wWx3Ih2a GnszFKEcuaOKLa5mjw/AA2Q3uTsBpIxFQhkJD1E9IsZ+Msj3TDwuHBCliKrb1SofDm Dogviq74TbPGDucm/z2SSyMlgTvfmXOHBpUyb+tk= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4732] c++: mangle contracts in write_mangled_name X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Arsen_Arsenovi=C4=87?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 147e276b580b674a46bc3b9c461ae7837fd48aba X-Git-Newrev: 52e7ff23ff5967fef52ebe31b6750a56f7103080 Message-Id: <20221215214829.3EA1338582B7@sourceware.org> Date: Thu, 15 Dec 2022 21:48:29 +0000 (GMT) List-Id: https://gcc.gnu.org/g:52e7ff23ff5967fef52ebe31b6750a56f7103080 commit r13-4732-g52e7ff23ff5967fef52ebe31b6750a56f7103080 Author: Arsen Arsenović Date: Thu Dec 15 18:56:59 2022 +0100 c++: mangle contracts in write_mangled_name 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. Diff: --- gcc/cp/mangle.cc | 14 +++++++------- gcc/testsuite/g++.dg/contracts/contracts-externC.C | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) 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"); } /* 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); - /* 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 = 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=c++2a -fcontracts -fcontract-continuation-mode=on" } + +volatile int x = 10; + +extern "C" void +f () + [[ pre: x < 10 ]] +{ +} + +int +main () + [[ post: x > 10 ]] +{ + f(); +}