Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

c_common_post_options limits flag_abi_version and flag_abi_compat_version to
actual ABI version numbers, but let's not do that for warn_abi_version; we
might want to add a warning relative to a future ABI version that isn't
available in the current release, such backporting the PR120012 warning.

Also allow plain -Wabi to include such a warning without complaining that
it's useless.

Also warn about an unsupported -fabi-version argument.

gcc/c-family/ChangeLog:

        * c-opts.cc (c_common_post_options): Let plain -Wabi warn
        about changes in a future version.
---
 gcc/c-family/c-opts.cc | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index 40163821948..f1c276f07cd 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1085,12 +1085,21 @@ c_common_post_options (const char **pfilename)
   /* Change flag_abi_version to be the actual current ABI level, for the
      benefit of c_cpp_builtins, and to make comparison simpler.  */
   const int latest_abi_version = 21;
+  /* Possibly different for non-default ABI fixes within a release.  */
+  const int default_abi_version = latest_abi_version;
   /* Generate compatibility aliases for ABI v18 (GCC 13) by default.  */
   const int abi_compat_default = 18;
 
+  if (flag_abi_version > latest_abi_version)
+    warning (0, "%<-fabi-version=%d%> is not supported, using =%d",
+            flag_abi_version, latest_abi_version);
+
+  SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+                      flag_abi_version, default_abi_version);
+
 #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
   clamp (flag_abi_version);
-  clamp (warn_abi_version);
+  /* Don't clamp warn_abi_version, let it be 0 or out of bounds.  */
   clamp (flag_abi_compat_version);
 #undef clamp
 
@@ -1101,24 +1110,17 @@ c_common_post_options (const char **pfilename)
     flag_abi_compat_version = warn_abi_version;
   else if (warn_abi_version == -1 && flag_abi_compat_version == -1)
     {
-      warn_abi_version = latest_abi_version;
-      if (flag_abi_version == latest_abi_version)
-       {
-         auto_diagnostic_group d;
-         if (warning (OPT_Wabi, "%<-Wabi%> won%'t warn about anything"))
-           {
-             inform (input_location, "%<-Wabi%> warns about differences "
-                     "from the most up-to-date ABI, which is also used "
-                     "by default");
-             inform (input_location, "use e.g. %<-Wabi=11%> to warn about "
-                     "changes from GCC 7");
-           }
-         flag_abi_compat_version = abi_compat_default;
-       }
+      warn_abi_version = 0;
+      if (flag_abi_version == default_abi_version)
+       flag_abi_compat_version = abi_compat_default;
       else
        flag_abi_compat_version = latest_abi_version;
     }
 
+  /* Allow warnings vs ABI versions beyond what we currently support.  */
+  if (warn_abi_version == 0)
+    warn_abi_version = 1000;
+
   /* By default, enable the new inheriting constructor semantics along with ABI
      11.  New and old should coexist fine, but it is a change in what
      artificial symbols are generated.  */

base-commit: a63d871eac0e57002b4ab4e1522f3f3851183b5e
-- 
2.49.0

Reply via email to