diff mbox series

[pushed] c++: contracts fixes

Message ID 20221122012609.550872-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: contracts fixes | expand

Commit Message

Jason Merrill Nov. 22, 2022, 1:26 a.m. UTC
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 mbox series

Patch

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)
 	{