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 570-611 find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp) Link Here
570
  return 0;
570
  return 0;
571
}
571
}
572
572
573
/* Return the value of darwin_macosx_version_min suitable for the
573
/* Given an OS X version VERSION_STR, return it as a statically-allocated array
574
   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro, so '10.4.2'
574
   of three integers. If VERSION_STR is invalid, return NULL.
575
   becomes 1040 and '10.10.0' becomes 101000.  The lowest digit is
575
576
   always zero, as is the second lowest for '10.10.x' and above.
576
   VERSION_STR must consist of one, two, or three tokens, each separated by
577
   Print a warning if the version number can't be understood.  */
577
   a single period.  Each token must contain only the characters '0' through
578
   '9' and is converted to an equivalent non-negative decimal integer. Omitted
579
   tokens become zeros.  For example:
580
581
        "10"              becomes       {10,0,0}
582
        "10.10"           becomes       {10,10,0}
583
        "10.10.1"         becomes       {10,10,1}
584
        "10.000010.1"     becomes       {10,10,1}
585
        "10.010.001"      becomes       {10,10,1}
586
        "000010.10.00001" becomes       {10,10,1}
587
        ".9.1"            is invalid
588
        "10..9"           is invalid
589
        "10.10."          is invalid  */
590
591
enum version_components { MAJOR, MINOR, TINY };
592
593
static const unsigned long *
594
parse_version (const char *version_str)
595
{
596
  size_t version_len;
597
  char *end;
598
  static unsigned long version_array[3];
599
600
  version_len = strlen (version_str);
601
  if (version_len < 1)
602
    return NULL;
603
604
  /* Version string must consist of digits and periods only.  */
605
  if (strspn (version_str, "0123456789.") != version_len)
606
    return NULL;
607
608
  if (!ISDIGIT (version_str[0]) || !ISDIGIT (version_str[version_len - 1]))
609
    return NULL;
610
611
  version_array[MAJOR] = strtoul (version_str, &end, 10);
612
  version_str = end + ((*end == '.') ? 1 : 0);
613
614
  /* Version string must not contain adjacent periods.  */
615
  if (*version_str == '.')
616
    return NULL;
617
618
  version_array[MINOR] = strtoul (version_str, &end, 10);
619
  version_str = end + ((*end == '.') ? 1 : 0);
620
621
  version_array[TINY] = strtoul (version_str, &end, 10);
622
623
  /* Version string must contain no more than three tokens.  */
624
  if (*end != '\0')
625
    return NULL;
626
627
  return version_array;
628
}
629
630
/* Given VERSION -- a three-component OS X version represented as an array of
631
   non-negative integers -- return a statically-allocated string suitable for
632
   the legacy __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.  If VERSION
633
   is invalid and cannot be coerced into a valid form, return NULL.
634
635
   The legacy format is a four-character string -- two chars for the major
636
   number and one each for the minor and tiny numbers.  Minor and tiny numbers
637
   from 10 through 99 are permitted but are clamped to 9 (for example, {10,9,10}
638
   produces "1099").  If VERSION contains numbers greater than 99, it is
639
   rejected.  */
640
641
static const char *
642
version_as_legacy_macro (const unsigned long *version)
643
{
644
  unsigned long major, minor, tiny;
645
  static char result[5];
646
647
  major = version[MAJOR];
648
  minor = version[MINOR];
649
  tiny = version[TINY];
650
651
  if (major > 99 || minor > 99 || tiny > 99)
652
    return NULL;
653
654
  minor = ((minor > 9) ? 9 : minor);
655
  tiny = ((tiny > 9) ? 9 : tiny);
656
657
  if (sprintf (result, "%lu%lu%lu", major, minor, tiny) != 4)
658
    return NULL;
659
660
  return result;
661
}
662
663
/* Given VERSION -- a three-component OS X version represented as an array of
664
   non-negative integers -- return a statically-allocated string suitable for
665
   the modern __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.  If VERSION
666
   is invalid, return NULL.
667
668
   The modern format is a six-character string -- two chars for each component,
669
   with zero-padding if necessary (for example, {10,10,1} produces "101001"). If
670
   VERSION contains numbers greater than 99, it is rejected.  */
671
578
static const char *
672
static const char *
579
version_as_macro (void)
673
version_as_modern_macro (const unsigned long *version)
580
{
674
{
581
  static char result[7] = "1000";
675
  unsigned long major, minor, tiny;
582
  int minorDigitIdx;
676
  static char result[7];
677
678
  major = version[MAJOR];
679
  minor = version[MINOR];
680
  tiny = version[TINY];
681
682
  if (major > 99 || minor > 99 || tiny > 99)
683
    return NULL;
684
685
  if (sprintf (result, "%02lu%02lu%02lu", major, minor, tiny) != 6)
686
    return NULL;
687
688
  return result;
689
}
583
690
584
  if (strncmp (darwin_macosx_version_min, "10.", 3) != 0)
691
/* Return the value of darwin_macosx_version_min, suitably formatted for the
692
   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro.  Values representing
693
   OS X 10.9 and earlier are encoded using the legacy four-character format,
694
   while 10.10 and later use a modern six-character format.  (For example,
695
   "10.9" produces "1090", and "10.10.1" produces "101001".)  If
696
   darwin_macosx_version_min is invalid and cannot be coerced into a valid
697
   form, print a warning and return "1000".  */
698
699
static const char *
700
macosx_version_as_macro (void)
701
{
702
  const unsigned long *version_array;
703
  const char *version_macro;
704
705
  version_array = parse_version (darwin_macosx_version_min);
706
  if (!version_array)
585
    goto fail;
707
    goto fail;
586
  if (! ISDIGIT (darwin_macosx_version_min[3]))
708
709
  if (version_array[MAJOR] != 10)
587
    goto fail;
710
    goto fail;
588
711
589
  minorDigitIdx = 3;
712
  if (version_array[MINOR] < 10)
590
  result[2] = darwin_macosx_version_min[minorDigitIdx++];
713
    version_macro = version_as_legacy_macro (version_array);
591
  if (ISDIGIT (darwin_macosx_version_min[minorDigitIdx]))
714
  else
592
  {
715
    version_macro = version_as_modern_macro (version_array);
593
    /* Starting with OS X 10.10, the macro ends '00' rather than '0',
716
594
       i.e. 10.10.x becomes 101000 rather than 10100.  */
717
  if (!version_macro)
595
    result[3] = darwin_macosx_version_min[minorDigitIdx++];
596
    result[4] = '0';
597
    result[5] = '0';
598
    result[6] = '\0';
599
  }
600
  if (darwin_macosx_version_min[minorDigitIdx] != '\0'
601
      && darwin_macosx_version_min[minorDigitIdx] != '.')
602
    goto fail;
718
    goto fail;
603
719
604
  return result;
720
  return version_macro;
605
721
606
 fail:
722
 fail:
607
  error ("unknown value %qs of -mmacosx-version-min",
723
  error ("unknown value %qs of -mmacosx-version-min",
608
	 darwin_macosx_version_min);
724
         darwin_macosx_version_min);
609
  return "1000";
725
  return "1000";
610
}
726
}
611
727
Lines 627-633 darwin_cpp_builtins (cpp_reader *pfile) Link Here
627
    builtin_define ("__CONSTANT_CFSTRINGS__");
743
    builtin_define ("__CONSTANT_CFSTRINGS__");
628
744
629
  builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
745
  builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
630
			     version_as_macro(), false);
746
			     macosx_version_as_macro(), false);
631
747
632
  /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the
748
  /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the
633
     following will cause a syntax error if one tries to compile gc attributed
749
     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