aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-11-21 17:58:07 -0500
committerJason Merrill <jason@redhat.com>2022-11-21 20:23:38 -0500
commitb20a3854c9f2923ac02c26385dac0c68f4df1e66 (patch)
tree1762adf561fe112881f68a469caa411a3121be5f /gcc/cp
parent8b7fee1de9a723ccc24d2de1c89d233f27b16a0a (diff)
downloadgcc-b20a3854c9f2923ac02c26385dac0c68f4df1e66.zip
gcc-b20a3854c9f2923ac02c26385dac0c68f4df1e66.tar.gz
gcc-b20a3854c9f2923ac02c26385dac0c68f4df1e66.tar.bz2
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++.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/contracts.cc1
-rw-r--r--gcc/cp/g++spec.cc20
2 files changed, 13 insertions, 8 deletions
diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index 2639643..f3afcc6 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 257e49b..e599ac9 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)
{