From patchwork Tue Nov 22 01:26:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 60954 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D391386187E for ; Tue, 22 Nov 2022 01:27:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D391386187E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669080447; bh=aK4eF0JSsgw7y5f38VFHlE7r9kqnnENZERrgD+3DIok=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=V3OL3M+ZtCzYRLxHcWzISBjf1gmhjB8WTbaR8nDOJBp5vG6/KxOJXZUrsw3mpkAKx e8KafjSsLnrE2bkm5tV+rJL9nzZU2bdpCWiM8r7fClKoWd8wQ5raoztV60AngD+Ud5 o/0gj1gVOynKCUQx625lmykYsmB5diBpVJfEbJ3k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id EE7A33858296 for ; Tue, 22 Nov 2022 01:26:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE7A33858296 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-164-Bpsae3meOX-giiWqfs9mmw-1; Mon, 21 Nov 2022 20:26:13 -0500 X-MC-Unique: Bpsae3meOX-giiWqfs9mmw-1 Received: by mail-qv1-f69.google.com with SMTP id nn2-20020a056214358200b004bb7bc3dfdcso12971579qvb.23 for ; Mon, 21 Nov 2022 17:26:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aK4eF0JSsgw7y5f38VFHlE7r9kqnnENZERrgD+3DIok=; b=TeNkN/gA0VHDKXK9BBpAkSeq4DI7LGMdg4twzj/shdOFnejFfnQx9afITvw3N4Zz3V JS3HFtJ752lMRfM2OTPhuN40pagmew+pqPqPofWrsc3t0bTam2GiC939CWM5jJV5rVNk ppIgAo+Kguga0fwCt7tJNDhjAUt4XQn2ECqLEDof7g2XSwZnHfetTTzoFn5K+a2Rybyt JNF/iETtRiPxSA28IHIWxWq3a0ZVR0w9dUh8SF01vCXCh5GXAft1CfflrQfUU2xa+ctg CGzZqmhsmIELPkBGkAp6qnhOU8p+PXvqXLZR6FaO0Pz7nluxnyKBCeM/rVsPRYrHspqc 7ucQ== X-Gm-Message-State: ANoB5pkYB8BgLkCmSySGDxMxrl8qgWc2XPNVc4aFe8esvBLTdClI5erm hsmJJuleRuS8iXjuNA2P8F2OnMWLoOMjcUzqzzVYcL2oixNidwVN0QY5hAL2kvzPdSZXuGq67ud /tHN64cRbOppKtHLw0Y49QpOd8vK7quzdtOYENnjlaxMnWgg1tHSj0+LquJWueHh8Tw== X-Received: by 2002:a0c:fe44:0:b0:4bb:6bc6:4276 with SMTP id u4-20020a0cfe44000000b004bb6bc64276mr1581372qvs.122.1669080372627; Mon, 21 Nov 2022 17:26:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf4rwImFwIraxEOtbwDZZQcAo5SgP0x8o4dHcDzdwuE9kZssuK4gxg+xCo39u6MApX79cGtgkw== X-Received: by 2002:a0c:fe44:0:b0:4bb:6bc6:4276 with SMTP id u4-20020a0cfe44000000b004bb6bc64276mr1581353qvs.122.1669080372225; Mon, 21 Nov 2022 17:26:12 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id bw6-20020a05622a098600b003988b3d5280sm7549958qtb.70.2022.11.21.17.26.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 17:26:11 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: contracts fixes Date: Mon, 21 Nov 2022 20:26:09 -0500 Message-Id: <20221122012609.550872-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- 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++. --- gcc/cp/contracts.cc | 1 + gcc/cp/g++spec.cc | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) base-commit: 8b7fee1de9a723ccc24d2de1c89d233f27b16a0a 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) {