From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050:0:465::201]) by sourceware.org (Postfix) with ESMTPS id F02B738493CE for ; Sat, 10 Dec 2022 13:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F02B738493CE 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 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 ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4NTpJX5Hm9z9sT3; Sat, 10 Dec 2022 14:14:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1670678076; 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=42XcM8JwAjQFagDRsoVI02BMY4HySAmyoQ+kMJI9tpY=; b=OHVfo7X6c8afTWEgvRcGlDd0o3fVZZ10JfXbRELxTeaTLlHoPQK8KjGyNBo7nsXXAvFxxC oQRl/qCz/5kqRX3fGdR+UQtRyj1C8aDhCSjw+7EWKlUV3HZlR0PZESlCfz+auol1jnBAVD XZ04jj0r5cc2x6HoYtKhWT8vs5gUREGfH4os6twiRmth8VS/JOw732fpu4IiaLhK+Tvp/J jZ0Hc0NMvwUZzAnn9bq4DUjFKt7hcMDPIMjfFaSs1LeX842KUMwLQhijLdmT953+SZY1B0 ITB8naJbbvdzHXYj9i80idoxOCowUQO9MeuV4GCrrz3dgEdhYAUNozQx/HH23A== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, jchapman@lock3software.com, =?UTF-8?q?Arsen=20Arsenovi=C4=87?= Subject: [PATCH] contracts: Stop relying on mangling for naming .pre/.post clones Date: Sat, 10 Dec 2022 14:13:56 +0100 Message-Id: <20221210131356.3385654-1-arsen@aarsen.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4NTpJX5Hm9z9sT3 X-Spam-Status: No, score=-11.4 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: If the mangler is relied on, functions with extern "C" on them emit multiple definitions of the same name. gcc/cp/ChangeLog: * contracts.cc (build_contract_condition_function): Add pre/post suffixes to pre- and postcondition clones. * mangle.cc (write_encoding): Don't mangle pre- and postconditions. gcc/testsuite/ChangeLog: * g++.dg/contracts/contracts-externC.C: New test. --- Afternoon, This change prevents contracts from emitting wrapper functions that have the same name as the original function, by moving the logic that disambiguates them from the mangler into the build_contract_condition_function helper. Thanks, have nice day. gcc/cp/contracts.cc | 3 +++ gcc/cp/mangle.cc | 7 ------- .../g++.dg/contracts/contracts-externC.C | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/contracts/contracts-externC.C diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc index 26316372389..f09eb87e283 100644 --- a/gcc/cp/contracts.cc +++ b/gcc/cp/contracts.cc @@ -161,6 +161,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-iterator.h" #include "print-tree.h" #include "stor-layout.h" +#include "cgraph.h" const int max_custom_roles = 32; static contract_role contract_build_roles[max_custom_roles] = { @@ -1451,6 +1452,8 @@ build_contract_condition_function (tree fndecl, bool pre) TREE_TYPE (fn) = build_method_type (class_type, TREE_TYPE (fn)); DECL_NAME (fn) = copy_node (DECL_NAME (fn)); + auto suffix = pre ? "pre" : "post"; + SET_DECL_ASSEMBLER_NAME (fn, clone_function_name (fn, suffix)); DECL_INITIAL (fn) = error_mark_node; DECL_ABSTRACT_ORIGIN (fn) = fndecl; diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index e363ef35b9f..e97428e8f30 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -856,13 +856,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(); +} -- 2.38.1