xref: /llvm-project/compiler-rt/test/builtins/TestCases/Darwin/platform_version_check_test.c (revision 9808f484534f503e9975d367082ff6933676ca20)
1 // RUN: %clang %s -o %t -mmacosx-version-min=10.7 -framework CoreFoundation -DMAJOR=%macos_version_major -DMINOR=%macos_version_minor -DSUBMINOR=%macos_version_subminor
2 // RUN: %run %t
3 
4 typedef int int32_t;
5 typedef unsigned int uint32_t;
6 
7 int32_t __isPlatformVersionAtLeast(uint32_t Platform, uint32_t Major,
8                                    uint32_t Minor, uint32_t Subminor);
9 
10 int32_t __isPlatformOrVariantPlatformVersionAtLeast(
11     uint32_t Platform, uint32_t Major, uint32_t Minor, uint32_t Subminor,
12     uint32_t Platform2, uint32_t Major2, uint32_t Minor2, uint32_t Subminor2);
13 
14 void exit(int status);
15 
16 #define PLATFORM_MACOS 1
17 #define PLATFORM_IOS 2
18 
19 int32_t check(uint32_t Major, uint32_t Minor, uint32_t Subminor) {
20   int32_t Result =
21       __isPlatformVersionAtLeast(PLATFORM_MACOS, Major, Minor, Subminor);
22   int32_t ResultVariant = __isPlatformOrVariantPlatformVersionAtLeast(
23       PLATFORM_MACOS, Major, Minor, Subminor, PLATFORM_IOS, 13, 0, 0);
24   if (Result != ResultVariant)
25     exit(-1);
26   return Result;
27 }
28 
29 int main() {
30   if (!check(MAJOR, MINOR, SUBMINOR))
31     return 1;
32   if (check(MAJOR, MINOR, SUBMINOR + 1))
33     return 1;
34   if (SUBMINOR && check(MAJOR + 1, MINOR, SUBMINOR - 1))
35     return 1;
36   if (SUBMINOR && !check(MAJOR, MINOR, SUBMINOR - 1))
37     return 1;
38   if (MAJOR && !check(MAJOR - 1, MINOR + 1, SUBMINOR))
39     return 1;
40 
41   return 0;
42 }
43