View | Details | Return to bug 63810 | Differences between
and this patch

Collapse All | Expand All

(-)a/gcc/config/darwin-c.c (-26 / +142 lines)
Lines 599-640 find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp) Link Here
599
  return 0;
599
  return 0;
600
}
600
}
601
601
602
/* Return the value of darwin_macosx_version_min suitable for the
602
/* Given an OS X version VERSION_STR, return it as a statically-allocated array
603
   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro, so '10.4.2'
603
   of three integers. If VERSION_STR is invalid, return NULL.
604
   becomes 1040 and '10.10.0' becomes 101000.  The lowest digit is
604
605
   always zero, as is the second lowest for '10.10.x' and above.
605
   VERSION_STR must consist of one, two, or three tokens, each separated by
606
   Print a warning if the version number can't be understood.  */
606
   a single period.  Each token must contain only the characters '0' through
607
   '9' and is converted to an equivalent non-negative decimal integer. Omitted
608
   tokens become zeros.  For example:
609
610
        "10"              becomes       {10,0,0}
611
        "10.10"           becomes       {10,10,0}
612
        "10.10.1"         becomes       {10,10,1}
613
        "10.000010.1"     becomes       {10,10,1}
614
        "10.010.001"      becomes       {10,10,1}
615
        "000010.10.00001" becomes       {10,10,1}
616
        ".9.1"            is invalid
617
        "10..9"           is invalid
618
        "10.10."          is invalid  */
619
620
enum version_components { MAJOR, MINOR, TINY };
621
622
static const unsigned long *
623
parse_version (const char *version_str)
624
{
625
  size_t version_len;
626
  char *end;
627
  static unsigned long version_array[3];
628
629
  version_len = strlen (version_str);
630
  if (version_len < 1)
631
    return NULL;
632
633
  /* Version string must consist of digits and periods only.  */
634
  if (strspn (version_str, "0123456789.") != version_len)
635
    return NULL;
636
637
  if (!ISDIGIT (version_str[0]) || !ISDIGIT (version_str[version_len - 1]))
638
    return NULL;
639
640
  version_array[MAJOR] = strtoul (version_str, &end, 10);
641
  version_str = end + ((*end == '.') ? 1 : 0);
642
643
  /* Version string must not contain adjacent periods.  */
644
  if (*version_str == '.')
645
    return NULL;
646
647
  version_array[MINOR] = strtoul (version_str, &end, 10);
648
  version_str = end + ((*end == '.') ? 1 : 0);
649
650
  version_array[TINY] = strtoul (version_str, &end, 10);
651
652
  /* Version string must contain no more than three tokens.  */
653
  if (*end != '\0')
654
    return NULL;
655
656
  return version_array;
657
}
658
659
/* Given VERSION -- a three-component OS X version represented as an array of
660
   non-negative integers -- return a statically-allocated string suitable for
661
   the legacy __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.  If VERSION
662
   is invalid and cannot be coerced into a valid form, return NULL.
663
664
   The legacy format is a four-character string -- two chars for the major
665
   number and one each for the minor and tiny numbers.  Minor and tiny numbers
666
   from 10 through 99 are permitted but are clamped to 9 (for example, {10,9,10}
667
   produces "1099").  If VERSION contains numbers greater than 99, it is
668
   rejected.  */
669
670
static const char *
671
version_as_legacy_macro (const unsigned long *version)
672
{
673
  unsigned long major, minor, tiny;
674
  static char result[5];
675
676
  major = version[MAJOR];
677
  minor = version[MINOR];
678
  tiny = version[TINY];
679
680
  if (major > 99 || minor > 99 || tiny > 99)
681
    return NULL;
682
683
  minor = ((minor > 9) ? 9 : minor);
684
  tiny = ((tiny > 9) ? 9 : tiny);
685
686
  if (sprintf (result, "%lu%lu%lu", major, minor, tiny) != 4)
687
    return NULL;
688
689
  return result;
690
}
691
692
/* Given VERSION -- a three-component OS X version represented as an array of
693
   non-negative integers -- return a statically-allocated string suitable for
694
   the modern __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.  If VERSION
695
   is invalid, return NULL.
696
697
   The modern format is a six-character string -- two chars for each component,
698
   with zero-padding if necessary (for example, {10,10,1} produces "101001"). If
699
   VERSION contains numbers greater than 99, it is rejected.  */
700
607
static const char *
701
static const char *
608
version_as_macro (void)
702
version_as_modern_macro (const unsigned long *version)
609
{
703
{
610
  static char result[7] = "1000";
704
  unsigned long major, minor, tiny;
611
  int minorDigitIdx;
705
  static char result[7];
706
707
  major = version[MAJOR];
708
  minor = version[MINOR];
709
  tiny = version[TINY];
710
711
  if (major > 99 || minor > 99 || tiny > 99)
712
    return NULL;
713
714
  if (sprintf (result, "%02lu%02lu%02lu", major, minor, tiny) != 6)
715
    return NULL;
716
717
  return result;
718
}
612
719
613
  if (strncmp (darwin_macosx_version_min, "10.", 3) != 0)
720
/* Return the value of darwin_macosx_version_min, suitably formatted for the
721
   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.  Values representing
722
   OS X 10.9 and earlier are encoded using the legacy four-character format,
723
   while 10.10 and later use a modern six-character format.  (For example,
724
   "10.9" produces "1090", and "10.10.1" produces "101001".)  If
725
   darwin_macosx_version_min is invalid and cannot be coerced into a valid
726
   form, print a warning and return "1000".  */
727
728
static const char *
729
macosx_version_as_macro (void)
730
{
731
  const unsigned long *version_array;
732
  const char *version_macro;
733
734
  version_array = parse_version (darwin_macosx_version_min);
735
  if (!version_array)
614
    goto fail;
736
    goto fail;
615
  if (! ISDIGIT (darwin_macosx_version_min[3]))
737
738
  if (version_array[MAJOR] != 10)
616
    goto fail;
739
    goto fail;
617
740
618
  minorDigitIdx = 3;
741
  if (version_array[MINOR] < 10)
619
  result[2] = darwin_macosx_version_min[minorDigitIdx++];
742
    version_macro = version_as_legacy_macro (version_array);
620
  if (ISDIGIT (darwin_macosx_version_min[minorDigitIdx]))
743
  else
621
  {
744
    version_macro = version_as_modern_macro (version_array);
622
    /* Starting with OS X 10.10, the macro ends '00' rather than '0',
745
623
       i.e. 10.10.x becomes 101000 rather than 10100.  */
746
  if (!version_macro)
624
    result[3] = darwin_macosx_version_min[minorDigitIdx++];
625
    result[4] = '0';
626
    result[5] = '0';
627
    result[6] = '\0';
628
  }
629
  if (darwin_macosx_version_min[minorDigitIdx] != '\0'
630
      && darwin_macosx_version_min[minorDigitIdx] != '.')
631
    goto fail;
747
    goto fail;
632
748
633
  return result;
749
  return version_macro;
634
750
635
 fail:
751
 fail:
636
  error ("unknown value %qs of -mmacosx-version-min",
752
  error ("unknown value %qs of -mmacosx-version-min",
637
	 darwin_macosx_version_min);
753
         darwin_macosx_version_min);
638
  return "1000";
754
  return "1000";
639
}
755
}
640
756
Lines 656-662 darwin_cpp_builtins (cpp_reader *pfile) Link Here
656
    builtin_define ("__CONSTANT_CFSTRINGS__");
772
    builtin_define ("__CONSTANT_CFSTRINGS__");
657
773
658
  builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
774
  builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
659
			     version_as_macro(), false);
775
			     macosx_version_as_macro(), false);
660
776
661
  /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the
777
  /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the
662
     following will cause a syntax error if one tries to compile gc attributed
778
     following will cause a syntax error if one tries to compile gc attributed
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-10.c (+16 lines)
Line 0 Link Here
1
/* PR target/63810: Test that an OS X minimum version with zero-padded
2
   minor and tiny numbers less than 10 produces the correct
3
   four-character macro.  */
4
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
5
6
/* { dg-options "-mmacosx-version-min=10.07.02" } */
7
/* { dg-do compile { target *-*-darwin* } } */
8
9
int
10
main ()
11
{
12
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1072
13
  fail me;
14
#endif
15
  return 0;
16
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-11.c (+16 lines)
Line 0 Link Here
1
/* PR target/63810: Test that an OS X minimum version with outrageous
2
   zero-padding and a minor number greater than 9 still produces
3
   a six-character macro.  */
4
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
5
6
/* { dg-options "-mmacosx-version-min=00010.010.0000098" } */
7
/* { dg-do compile { target *-*-darwin* } } */
8
9
int
10
main ()
11
{
12
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101098
13
  fail me;
14
#endif
15
  return 0;
16
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-12.c (+16 lines)
Line 0 Link Here
1
/* PR target/63810: Test that an OS X minimum version with outrageous
2
   zero-padding and a minor number less than 10 still produces
3
   a four-character macro.  */
4
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
5
6
/* { dg-options "-mmacosx-version-min=010.008.000031" } */
7
/* { dg-do compile { target *-*-darwin* } } */
8
9
int
10
main ()
11
{
12
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1089
13
  fail me;
14
#endif
15
  return 0;
16
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-3.c (-3 / +3 lines)
Lines 1-11 Link Here
1
/* Test that most-minor versions greater than 9 work.  */
1
/* Test that most minor versions less than 10 work.  */
2
/* { dg-options "-mmacosx-version-min=10.4.10" } */
2
/* { dg-options "-mmacosx-version-min=10.4.1" } */
3
/* { dg-do compile { target *-*-darwin* } } */
3
/* { dg-do compile { target *-*-darwin* } } */
4
4
5
int
5
int
6
main ()
6
main ()
7
{
7
{
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1040
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1041
9
  fail me;
9
  fail me;
10
#endif
10
#endif
11
  return 0;
11
  return 0;
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-4.c (-3 / +3 lines)
Lines 1-11 Link Here
1
/* Test that major versions greater than 9 work and have the additional 0.  */
1
/* Test that minor versions greater than 9 produce a six-character macro.  */
2
/* { dg-options "-mmacosx-version-min=10.10.0" } */
2
/* { dg-options "-mmacosx-version-min=10.10.1" } */
3
/* { dg-do compile { target *-*-darwin* } } */
3
/* { dg-do compile { target *-*-darwin* } } */
4
4
5
int
5
int
6
main ()
6
main ()
7
{
7
{
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101000
8
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101001
9
  fail me;
9
  fail me;
10
#endif
10
#endif
11
  return 0;
11
  return 0;
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-5.c (+16 lines)
Line 0 Link Here
1
/* PR target/63810: Test that an OS X minimum version with minor number
2
   less than 10 and tiny number greater than 9 produces a four-character
3
   macro with the tiny number clamped to 9.  */
4
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
5
6
/* { dg-options "-mmacosx-version-min=10.9.10" } */
7
/* { dg-do compile { target *-*-darwin* } } */
8
9
int
10
main ()
11
{
12
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1099
13
  fail me;
14
#endif
15
  return 0;
16
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-6.c (+15 lines)
Line 0 Link Here
1
/* PR target/63810: Test that tiny numbers are preserved in
2
   six-character macros.  */
3
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
4
5
/* { dg-options "-mmacosx-version-min=10.10.11" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101011
12
  fail me;
13
#endif
14
  return 0;
15
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-7.c (+15 lines)
Line 0 Link Here
1
/* PR target/63810: Test that tiny numbers less than 10 are preserved in
2
   four-character macros.  */
3
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
4
5
/* { dg-options "-mmacosx-version-min=10.9.1" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1091
12
  fail me;
13
#endif
14
  return 0;
15
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-8.c (+16 lines)
Line 0 Link Here
1
/* PR target/63810: Test that an OS X minimum version with minor number
2
   greater than 9 and no tiny number produces a six-character macro
3
   ending in "00".  */
4
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
5
6
/* { dg-options "-mmacosx-version-min=10.11" } */
7
/* { dg-do compile { target *-*-darwin* } } */
8
9
int
10
main ()
11
{
12
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101100
13
  fail me;
14
#endif
15
  return 0;
16
}
(-)a/gcc/testsuite/gcc.dg/darwin-minversion-9.c (+15 lines)
Line 0 Link Here
1
/* PR target/63810: Test that an OS X minimum version with a zero-padded
2
   minor number less than 10 produces a four-character macro.  */
3
/* Added by Lawrence Velázquez <vq@larryv.me>.  */
4
5
/* { dg-options "-mmacosx-version-min=10.08.4" } */
6
/* { dg-do compile { target *-*-darwin* } } */
7
8
int
9
main ()
10
{
11
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1084
12
  fail me;
13
#endif
14
  return 0;
15
}

Return to bug 63810