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: 24100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1938827wrr; Mon, 21 Nov 2022 17:27:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf61HvUvtt2D4jKgckFGX/z/RGMGimLQ0hdFbaQnqiTRYm90AGSCjfRgH/TRtKzekPpZT2T8 X-Received: by 2002:a05:6402:2887:b0:460:f0c0:f9c8 with SMTP id eg7-20020a056402288700b00460f0c0f9c8mr8831301edb.181.1669080468038; Mon, 21 Nov 2022 17:27:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669080468; cv=none; d=google.com; s=arc-20160816; b=EsXAK+6CUBi9TaCcIzY1Ti1tfuRfUaUKT3WOcFbJ8ama8fvr/sMRNY9VKQFidryLVk k77AB6EYaP//vfdQGhFI6oeaKeH+UlGsuLP73kLe+HSuPyED9MfmZfsqmbwcw0HgWXO1 NlwY1cB2DK1Ut3nUtJEfy2cjaMddjdkzawGXrywAIcoI5eDRUmNu5Bf8vGPIlGM8IpPP joid2WBpG5jFmIkcAsNvby9l1+xFD9S3LRNCOh+OhPIjUzbomlNycjkVtJAHNtqMSqpQ 6kGrFhHnwiX2lWq36/gZcJk2n0Y2egtBtrAhl/pRS0MB3RGp0Ai88eX4NDbF99WERURo F0yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=aK4eF0JSsgw7y5f38VFHlE7r9kqnnENZERrgD+3DIok=; b=l3tmeoC2c90QvPeHXspJqMszTSqvDj1XGGb0g5VIybpCFHDZzD23aYI1iGwwebCEpY Zy/kAeROD4uF6muzQV8XF6OqxxAmV7k9vAX3DozFDudXDbIEY81oPj4d16xP+igYeJ+i Moz5dAgWTiHLlsWPcvhChlvG6o3KlVzj1VebHJfafdeiBhguwlegpnQIgN+xGyuTPjHy QYy4baJhzAwFJveWG5G9VuFqOfoC0ZhjvdztcuEmd7Ns/9wfDKry71F5Z1ShRoVHd5PH 3kEmag8T6Sf74wJwwrQdtW+1zVbN5bugv3deaS54SpX6775h3NILJrWG/VL7/842/nws bdLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NgU2QJbc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dd16-20020a1709069b9000b0078e2d2d1a67si11094744ejc.344.2022.11.21.17.27.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 17:27:48 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NgU2QJbc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D4263851892 for ; Tue, 22 Nov 2022 01:27:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D4263851892 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669080466; bh=aK4eF0JSsgw7y5f38VFHlE7r9kqnnENZERrgD+3DIok=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NgU2QJbcULh8wW70HNW72pNb2rBZfDavo9Delkr6f8IxT38YqVtcohb67772rvc4Z +KVMHKj5GSwfutKUmBG7DlYA7dVkZk3ei7LlEsDORW/B3QjErqYZBCKhydNyUScbPd 2La7o3urSVvcGNU/YS6DWyhHvkIg0gFgqBzbZmKc= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750157720793920148?= X-GMAIL-MSGID: =?utf-8?q?1750157720793920148?= 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) {