History

macos: Adjust tcctest.c for clang

we need to disable or adjust some tests where clang behaves slightly different from GCC: * slight difference in __FILE__ behaviour * difference (to less useful vs GCC) in computed #include * difference in __builtin_constant_p * attribute(weak, alias) isn't supported by clang on MacOS (though it could be, as Mach-O has the capabilities for this) * the built-in assembler of clang is mediocre this was all checked with Apple LLVM version 10.0.1 (clang-1001.0.46.4)

Michael Matz committed 6 years ago

Commit 9ce5b4a1 parent 4eff2b51 file · +62 −14Browse files

Unified · Split

tests/tcctest.c+62−14
@@ -64,7 +64,13 @@ typedef __SIZE_TYPE__ uintptr_t; · 63 unmodified lines
6464 #define INC(name) <tests/name.h>
6565 #define funnyname 42test.h
6666 #define incdir tests/
67+#ifdef __clang__
68+/* clang's preprocessor is broken in this regard and adds spaces
69+ to the tokens 'incdir' and 'funnyname' when expanding */
70+#define incname <tests/42test.h>
71+#else
6772 #define incname < incdir funnyname >
73+#endif
6874 #define __stringify(x) #x
6975 #define stringify(x) __stringify(x)
7076 #include INC(42test)
@@ -411,10 +417,17 @@ comment · 340 unmodified lines
411417 comment. */
412418 TEST2 /* the comment */ ();
413419
414− printf("%s\n", get_basefile_from_header());
415− printf("%s\n", __BASE_FILE__);
416− printf("%s\n", get_file_from_header());
417− printf("%s\n", __FILE__);
420+ printf("basefromheader %s\n", get_basefile_from_header());
421+ printf("base %s\n", __BASE_FILE__);
422+ {
423+ /* Some compilers (clang) prepend './' to __FILE__ from included
424+ files. */
425+ const char *fn = get_file_from_header();
426+ if (fn[0] == '.' && fn[1] == '/')
427+ fn += 2;
428+ printf("filefromheader %s\n", fn);
429+ }
430+ printf("file %s\n", __FILE__);
418431
419432 /* Check that funnily named include was in fact included */
420433 have_included_42test_h = 1;
@@ -3330,6 +3343,8 @@ static __inline__ void sigdelset1(unsigned int *set, int _sig) · 2909 unmodified lines
33303343 asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc", "flags");
33313344 }
33323345
3346+#ifndef __APPLE__
3347+/* clang's inline asm is uncapable of 'xchgb %b0,%h0' */
33333348 static __inline__ __const__ unsigned int swab32(unsigned int x)
33343349 {
33353350 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
@@ -3339,6 +3354,7 @@ static __inline__ __const__ unsigned int swab32(unsigned int x) · 3 unmodified lines
33393354 : "0" (x));
33403355 return x;
33413356 }
3357+#endif
33423358
33433359 static __inline__ unsigned long long mul64(unsigned int a, unsigned int b)
33443360 {
@@ -3415,6 +3431,7 @@ void base_func(void) · 70 unmodified lines
34153431 printf ("asmc: base\n");
34163432 }
34173433
3434+#ifndef __APPLE__
34183435 extern void override_func1 (void);
34193436 extern void override_func2 (void);
34203437
@@ -3482,6 +3499,7 @@ void asm_local_label_diff (void) · 61 unmodified lines
34823499 {
34833500 printf ("asm_local_label_diff: %d %d\n", alld_stuff[0], alld_stuff[1]);
34843501 }
3502+#endif
34853503
34863504 /* This checks that static local variables are available from assembler. */
34873505 void asm_local_statics (void)
@@ -3630,8 +3648,10 @@ void test_asm_call(void) · 142 unmodified lines
36303648 tested here). */
36313649 /* two pushes so stack remains aligned */
36323650 asm volatile ("push %%rdi; push %%rdi; mov %0, %%rdi;"
3633−#if 1 && !defined(__TINYC__) && (defined(__PIC__) || defined(__PIE__))
3651+#if 1 && !defined(__TINYC__) && (defined(__PIC__) || defined(__PIE__)) && !defined(__APPLE__)
36343652 "call getenv@plt;"
3653+#elif defined(__APPLE__) && !defined(__TINYC__)
3654+ "call _getenv;"
36353655 #else
36363656 "call getenv;"
36373657 #endif
@@ -3656,21 +3676,31 @@ void asm_dot_test(void) · 18 unmodified lines
36563676 case 1:
36573677 asm(".text; lea S"RX",%eax; lea ."RX",%ecx; sub %ecx,%eax; S=.; jmp p0");
36583678 case 2:
3679+#ifndef __APPLE__
3680+ /* clangs internal assembler is broken */
36593681 asm(".text; jmp .+6; .int 123; mov .-4"RX",%eax; jmp p0");
3682+#else
3683+ asm(".text; mov $0, %eax; jmp p0");
3684+#endif
36603685 case 3:
3661−#ifndef _WIN32
3686+#if !defined(_WIN32) && !defined(__APPLE__)
36623687 asm(".pushsection \".data\"; Y=.; .int 999; X=Y; .int 456; X=.-4; .popsection");
36633688 #else
36643689 asm(".data; Y=.; .int 999; X=Y; .int 456; X=.-4; .text");
36653690 #endif
36663691 asm(".text; mov X"RX",%eax; jmp p0");
36673692 case 4:
3693+#ifdef __APPLE__
3694+ /* Bah! Clang! Doesn't want to redefine 'X' */
3695+ asm(".text; mov $123,%eax; jmp p0");
3696+#else
36683697 #ifndef _WIN32
36693698 asm(".data; X=.; .int 789; Y=.; .int 999; .previous");
36703699 #else
36713700 asm(".data; X=.; .int 789; Y=.; .int 999; .text");
36723701 #endif
36733702 asm(".text; mov X"RX",%eax; X=Y; jmp p0");
3703+#endif
36743704 case 0:
36753705 asm(".text; p0=.; mov %%eax,%0;" : "=m"(r)); break;
36763706 }
@@ -3731,8 +3761,11 @@ void asm_test(void) · 54 unmodified lines
37313761 __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc");
37323762 printf("set=0x%x\n", set);
37333763 val = 0x01020304;
3764+#ifndef __APPLE__
37343765 printf("swab32(0x%08x) = 0x%0x\n", val, swab32(val));
3766+#endif
37353767 #ifndef _WIN32
3768+#ifndef __APPLE__
37363769 override_func1();
37373770 override_func2();
37383771 /* The base_func ref from the following inline asm should find
@@ -3741,13 +3774,17 @@ void asm_test(void) · 2 unmodified lines
37413774 override_func3();
37423775 printf("asmstr: %s\n", get_asm_string());
37433776 asm_local_label_diff();
3777+#endif
37443778 asm_local_statics();
37453779 #endif
3780+#ifndef __APPLE__
3781+ /* clang can't deal with the type change */
37463782 /* Check that we can also load structs of appropriate layout
37473783 into registers. */
37483784 asm volatile("" : "=r" (asmret) : "0"(s2));
37493785 if (asmret != s2.addr)
37503786 printf("asmstr: failed\n");
3787+#endif
37513788 #ifdef BOOL_ISOC99
37523789 /* Check that the typesize correctly sets the register size to
37533790 8 bit. */
@@ -3809,14 +3846,19 @@ void builtin_test(void) · 55 unmodified lines
38093846 /* space is needed because tcc preprocessor introduces a space between each token */
38103847 COMPAT_TYPE(char * *, void *);
38113848 #endif
3812− printf("res = %d\n", __builtin_constant_p(1));
3813− printf("res = %d\n", __builtin_constant_p(1 + 2));
3814− printf("res = %d\n", __builtin_constant_p(&constant_p_var));
3815− printf("res = %d\n", __builtin_constant_p(constant_p_var));
3816− printf("res = %d\n", __builtin_constant_p(100000 / constant_p_var));
3817− printf("res = %d\n", __builtin_constant_p(i && 0));
3818− printf("res = %d\n", __builtin_constant_p(i && 1));
3819− printf("res = %d\n", __builtin_constant_p(i && 0 ? i : 34));
3849+ printf("res1 = %d\n", __builtin_constant_p(1));
3850+ printf("res2 = %d\n", __builtin_constant_p(1 + 2));
3851+ printf("res3 = %d\n", __builtin_constant_p(&constant_p_var));
3852+ printf("res4 = %d\n", __builtin_constant_p(constant_p_var));
3853+ printf("res5 = %d\n", __builtin_constant_p(100000 / constant_p_var));
3854+#ifndef __APPLE__
3855+ /* clang doesn't regard this as constant expression */
3856+ printf("res6 = %d\n", __builtin_constant_p(i && 0));
3857+#endif
3858+ printf("res7 = %d\n", __builtin_constant_p(i && 1));
3859+#ifndef __APPLE__
3860+ printf("res8 = %d\n", __builtin_constant_p(i && 0 ? i : 34));
3861+#endif
38203862 s = 1;
38213863 ll = 2;
38223864 i = __builtin_choose_expr (1 != 0, ll, s);
@@ -3850,14 +3892,18 @@ extern int weak_asm_v1 asm("weak_asm_v1x") __attribute · 27 unmodified lines
38503892 extern int __attribute((weak)) weak_asm_v2 asm("weak_asm_v2x") ;
38513893 extern int __attribute((weak)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak));
38523894
3895+#ifndef __APPLE__
38533896 static const size_t dummy = 0;
38543897 extern __typeof(dummy) weak_dummy1 __attribute__((weak, alias("dummy")));
38553898 extern __typeof(dummy) __attribute__((weak, alias("dummy"))) weak_dummy2;
38563899 extern __attribute__((weak, alias("dummy"))) __typeof(dummy) weak_dummy3;
3900+#endif
38573901
38583902 int some_lib_func(void);
38593903 int dummy_impl_of_slf(void) { return 444; }
3904+#ifndef __APPLE__
38603905 int some_lib_func(void) __attribute__((weak, alias("dummy_impl_of_slf")));
3906+#endif
38613907
38623908 int weak_toolate() __attribute__((weak));
38633909 int weak_toolate() { return 0; }
@@ -3881,7 +3927,9 @@ void __attribute__((weak)) weak_test(void) · 17 unmodified lines
38813927 printf("weak_asm_v1=%d\n",&weak_asm_v1 != NULL);
38823928 printf("weak_asm_v2=%d\n",&weak_asm_v2 != NULL);
38833929 printf("weak_asm_v3=%d\n",&weak_asm_v3 != NULL);
3930+#ifndef __APPLE__
38843931 printf("some_lib_func=%d\n", &some_lib_func ? some_lib_func() : 0);
3932+#endif
38853933 }
38863934
38873935 int __attribute__((weak)) weak_f2() { return 222; }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t