[pushed] Darwin : Adjust handling of MACOSX_DEPLOYMENT_TARGET for macOS 11.

Message ID 5D0E9153-FCC2-4EB1-866C-757F79996843@sandoe.co.uk
State New
Headers show
Series
  • [pushed] Darwin : Adjust handling of MACOSX_DEPLOYMENT_TARGET for macOS 11.
Related show

Commit Message

Iain Sandoe Dec. 24, 2020, 10:24 p.m.
(resending, this never seemed to make it to patches@)

The shift to macOS version 11 also means that '11' without any
following '.x' is accepted as a valid version number.  This adjusts
the validation code to accept this and map it to 11.0.0 which
matches what the clang toolchain appears to do.

tested on x86_64-darwin20, x86_64-darwin16
pushed to master
thanks
Iain

gcc/ChangeLog:

	* config/darwin-driver.c (validate_macosx_version_min): Allow
	MACOSX_DEPLOYMENT_TARGET=11.
	(darwin_default_min_version): Adjust warning spelling to avoid
	an apostrophe.
---
 gcc/config/darwin-driver.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

-- 
2.24.1

Patch

diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index 4a9426ef273..c5ad44191aa 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -43,13 +43,13 @@  static const char *
 validate_macosx_version_min (const char *version_str)
 {
   size_t version_len;
-  unsigned long major, minor, tiny = 0;
+  unsigned long major, minor = 0, tiny = 0;
   char *end;
   const char *old_version = version_str;
   bool need_rewrite = false;
 
   version_len = strlen (version_str);
-  if (version_len < 4) /* The minimum would be 10.x  */
+  if (version_len < 2) /* The minimum would be 11  */
     return NULL;
 
   /* Version string must consist of digits and periods only.  */
@@ -63,18 +63,27 @@  validate_macosx_version_min (const char *version_str)
     need_rewrite = true;
 
   major = strtoul (version_str, &end, 10);
-  version_str = end + ((*end == '.') ? 1 : 0);
 
   if (major < 10 || major > 11 ) /* MacOS 10 and 11 are known. */
     return NULL;
 
-  /* Version string components must be present and numeric.  */
-  if (!ISDIGIT (version_str[0]))
+  /* Skip a separating period, if there's one.  */
+  version_str = end + ((*end == '.') ? 1 : 0);
+
+  if (major == 11 && *end != '\0' && !ISDIGIT (version_str[0]))
+     /* For MacOS 11, we allow just the major number, but if the minor is
+	there it must be numeric.  */
+    return NULL;
+  else if (major == 11 && *end == '\0')
+    /* We will rewrite 11 =>  11.0.0.  */
+    need_rewrite = true;
+  else if (major == 10 && (*end == '\0' || !ISDIGIT (version_str[0])))
+    /* Otherwise, minor version components must be present and numeric.  */
     return NULL;
 
   /* If we have one or more leading zeros on a component, then rewrite the
      version string.  */
-  if (version_str[0] == '0' && version_str[1] != '\0'
+  if (*end != '\0' && version_str[0] == '0' && version_str[1] != '\0'
       && version_str[1] != '.')
     need_rewrite = true;
 
@@ -220,7 +229,7 @@  darwin_default_min_version (void)
       const char *checked = validate_macosx_version_min (new_flag);
       if (checked == NULL)
 	{
-	  warning (0, "couldn%'t understand version %s", new_flag);
+	  warning (0, "could not understand version %s", new_flag);
 	  return NULL;
 	}
       new_flag = xstrndup (checked, strlen (checked));