This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH v4 1/2] Fix __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
- From: James Clarke <jrtc27 at jrtc27 dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: James Clarke <jrtc27 at jrtc27 dot com>
- Date: Tue, 26 Aug 2014 19:11:31 +0100
- Subject: [PATCH v4 1/2] Fix __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
- Authentication-results: sourceware.org; auth=none
- References: <1409076692-65815-1-git-send-email-jrtc27 at jrtc27 dot com>
Previously, this macro had taken the form 10X0, where X is the minor
version number, e.g. 1090 for OS X 10.9 Mavericks. However, as of OS X
10.10 Yosemite, it should take the form 10XX00, i.e. 101000 for 10.10.
Added a test for the new format and fixed the formatting for the
existing ones.
gcc/ChangeLog:
* config/darwin-c.c (version_as_macro): Added extra 0 for OS X 10.10
and above
* config/darwin-driver.c (darwin_find_version_from_kernel): Removed
kernel version check to avoid incrementing it after every major OS X
release
gcc/testsuite/ChangeLog:
* gcc.db/darwin-minversion-1.c: Fixed formatting
* gcc.db/darwin-minversion-2.c: Fixed formatting
* gcc.db/darwin-minversion-3.c: Fixed formatting
* gcc.dg/darwin-minversion-4.c: Added test for OS X 10.10
---
gcc/config/darwin-c.c | 25 +++++++++++++++++++------
gcc/config/darwin-driver.c | 2 --
gcc/testsuite/gcc.dg/darwin-minversion-1.c | 3 ++-
gcc/testsuite/gcc.dg/darwin-minversion-2.c | 3 ++-
gcc/testsuite/gcc.dg/darwin-minversion-3.c | 3 ++-
gcc/testsuite/gcc.dg/darwin-minversion-4.c | 12 ++++++++++++
6 files changed, 37 insertions(+), 11 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/darwin-minversion-4.c
diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c
index 892ba35..7fe4b1f 100644
--- a/gcc/config/darwin-c.c
+++ b/gcc/config/darwin-c.c
@@ -571,21 +571,34 @@ find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp)
}
/* Return the value of darwin_macosx_version_min suitable for the
- __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro,
- so '10.4.2' becomes 1040. The lowest digit is always zero.
+ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro, so '10.4.2'
+ becomes 1040 and '10.10.0' becomes 101000. The lowest digit is
+ always zero, as is the second lowest for '10.10.x' and above.
Print a warning if the version number can't be understood. */
static const char *
version_as_macro (void)
{
- static char result[] = "1000";
+ static char result[7] = "1000";
+ int minorDigitIdx;
if (strncmp (darwin_macosx_version_min, "10.", 3) != 0)
goto fail;
if (! ISDIGIT (darwin_macosx_version_min[3]))
goto fail;
- result[2] = darwin_macosx_version_min[3];
- if (darwin_macosx_version_min[4] != '\0'
- && darwin_macosx_version_min[4] != '.')
+
+ minorDigitIdx = 3;
+ result[2] = darwin_macosx_version_min[minorDigitIdx++];
+ if (ISDIGIT (darwin_macosx_version_min[minorDigitIdx]))
+ {
+ /* Starting with OS X 10.10, the macro ends '00' rather than '0',
+ i.e. 10.10.x becomes 101000 rather than 10100. */
+ result[3] = darwin_macosx_version_min[minorDigitIdx++];
+ result[4] = '0';
+ result[5] = '0';
+ result[6] = '\0';
+ }
+ if (darwin_macosx_version_min[minorDigitIdx] != '\0'
+ && darwin_macosx_version_min[minorDigitIdx] != '.')
goto fail;
return result;
diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index 8b6ae93..eb478e8 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -57,8 +57,6 @@ darwin_find_version_from_kernel (char *new_flag)
version_p = osversion + 1;
if (ISDIGIT (*version_p))
major_vers = major_vers * 10 + (*version_p++ - '0');
- if (major_vers > 4 + 9)
- goto parse_failed;
if (*version_p++ != '.')
goto parse_failed;
version_pend = strchr(version_p, '.');
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-1.c b/gcc/testsuite/gcc.dg/darwin-minversion-1.c
index d8a3243..6221d61 100644
--- a/gcc/testsuite/gcc.dg/darwin-minversion-1.c
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-1.c
@@ -2,7 +2,8 @@
/* { dg-options "-mmacosx-version-min=10.1" } */
/* { dg-do run { target *-*-darwin* } } */
-int main(void)
+int
+main ()
{
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1010
fail me;
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-2.c b/gcc/testsuite/gcc.dg/darwin-minversion-2.c
index fd4975a..8e18d52 100644
--- a/gcc/testsuite/gcc.dg/darwin-minversion-2.c
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-2.c
@@ -2,7 +2,8 @@
/* { dg-options "-mmacosx-version-min=10.1 -mmacosx-version-min=10.3" } */
/* { dg-do run { target *-*-darwin* } } */
-int main(void)
+int
+main ()
{
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1030
fail me;
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-3.c b/gcc/testsuite/gcc.dg/darwin-minversion-3.c
index d0c5934..4fcb969 100644
--- a/gcc/testsuite/gcc.dg/darwin-minversion-3.c
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-3.c
@@ -2,7 +2,8 @@
/* { dg-options "-mmacosx-version-min=10.4.10" } */
/* { dg-do compile { target *-*-darwin* } } */
-int main(void)
+int
+main ()
{
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1040
fail me;
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-4.c b/gcc/testsuite/gcc.dg/darwin-minversion-4.c
new file mode 100644
index 0000000..1cb42eb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-4.c
@@ -0,0 +1,12 @@
+/* Test that major versions greater than 9 work and have the additional 0. */
+/* { dg-options "-mmacosx-version-min=10.10.0" } */
+/* { dg-do compile { target *-*-darwin* } } */
+
+int
+main ()
+{
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101000
+ fail me;
+#endif
+ return 0;
+}
--
2.1.0