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

Collapse All | Expand All

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