From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 58839385841A; Tue, 22 Nov 2022 01:26:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58839385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669080387; bh=lvTzZ+vrsfB/MVYNH2LJMf7x565NMmasUQ3MCBC7Mmc=; h=From:To:Subject:Date:From; b=k6gBMSXoSonVOhSEf36ldfj7d5wCTDghYWzJAaPR3/Gn4VOgfQya3ALkqnckYtln9 IQue6L8TO+FrFdGHtr7P4f03dl9r5tKupxuEYW1AH1VLWPuKSlRCkc/J4m06OxvM10 rExpjZ5sx1vmFtO3H3CqKtvfQThC8zUmDH1Fs+vI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4223] c++: contracts fixes X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 8b7fee1de9a723ccc24d2de1c89d233f27b16a0a X-Git-Newrev: b20a3854c9f2923ac02c26385dac0c68f4df1e66 Message-Id: <20221122012627.58839385841A@sourceware.org> Date: Tue, 22 Nov 2022 01:26:26 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b20a3854c9f2923ac02c26385dac0c68f4df1e66 commit r13-4223-gb20a3854c9f2923ac02c26385dac0c68f4df1e66 Author: Jason Merrill Date: Mon Nov 21 17:58:07 2022 -0500 c++: contracts fixes Fixing -Wunused-parm warnings and link errors depending on where -fcontracts appears on the command line. gcc/cp/ChangeLog: * contracts.cc (build_contract_condition_function): Set DECL_ARTIFICIAL on return value parm. * g++spec.cc (lang_specific_driver): Add -lstdc++exp just before -lstdc++. Diff: --- gcc/cp/contracts.cc | 1 + gcc/cp/g++spec.cc | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc index 26396439361..f3afcc62ba0 100644 --- a/gcc/cp/contracts.cc +++ b/gcc/cp/contracts.cc @@ -1434,6 +1434,7 @@ build_contract_condition_function (tree fndecl, bool pre) tree name = get_identifier ("__r"); tree parm = build_lang_decl (PARM_DECL, name, value_type); DECL_CONTEXT (parm) = fn; + DECL_ARTIFICIAL (parm) = true; DECL_ARGUMENTS (fn) = chainon (DECL_ARGUMENTS (fn), parm); *last = build_tree_list (NULL_TREE, value_type); diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc index 257e49b7f3f..e599ac906f6 100644 --- a/gcc/cp/g++spec.cc +++ b/gcc/cp/g++spec.cc @@ -128,6 +128,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* By default, we throw on the math library if we have one. */ int need_math = (MATH_LIBRARY[0] != '\0'); + /* By default, we don't add -lstdc++exp. */ + bool need_experimental = false; + /* True if we saw -static. */ int static_link = 0; @@ -161,8 +164,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, switch (decoded_options[i].opt_index) { case OPT_fcontracts: - args[i] |= EXPERIMENTAL; - ++added; + need_experimental = true; break; case OPT_nostdlib: @@ -292,7 +294,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, #endif /* Add one for shared_libgcc or extra static library. */ - num_args = argc + added + need_math + (library > 0) * 4 + 1; + num_args = (argc + added + need_math + need_experimental + + (library > 0) * 4 + 1); /* For libc++, on most platforms, the ABI library (usually called libc++abi) is provided as a separate DSO, which we must also append. However, a platform might have the ability to forward the ABI library @@ -355,11 +358,6 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, &new_decoded_options[j]); } - if ((args[i] & EXPERIMENTAL) - && which_library == USE_LIBSTDCXX) - generate_option (OPT_l, "stdc++exp", 1, CL_DRIVER, - &new_decoded_options[++j]); - if ((args[i] & SKIPOPT) != 0) --j; @@ -370,6 +368,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* Add `-lstdc++' if we haven't already done so. */ if (library > 0) { + if (need_experimental && which_library == USE_LIBSTDCXX) + { + generate_option (OPT_l, "stdc++exp", 1, CL_DRIVER, + &new_decoded_options[j++]); + ++added_libraries; + } #ifdef HAVE_LD_STATIC_DYNAMIC if (library > 1 && !static_link) {