* [pushed] c++: contracts fixes
@ 2022-11-22 1:26 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-11-22 1:26 UTC (permalink / raw)
To: 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(-)
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)
{
base-commit: 8b7fee1de9a723ccc24d2de1c89d233f27b16a0a
--
2.31.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-22 1:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 1:26 [pushed] c++: contracts fixes Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).