Skip to content

Commit 1bb2fe6

Browse files
cyanogilvieclaude
andcommitted
Fix Alpine/musl test-suite blockers: busybox diff, aarch64 wchar_t
- runtests.sh used diff --strip-trailing-cr unconditionally; busybox diff (Alpine) lacks that option, so every .expect comparison errored and counted as a mismatch. Probe for the option once. - c2mir's builtin aarch64 stddef.h declared 'typedef int wchar_t;', but wchar_t is unsigned int in AAPCS64 (and caarch64.h already says MIR_WCHAR_MIN 0). glibc never notices because its headers trust the compiler's stddef.h, but musl's bits/alltypes.h redeclares wchar_t per-arch ('typedef unsigned wchar_t;'), making every program that includes both fail with 'repeated declaration wchar_t' - this broke the c2m bootstrap on Alpine aarch64. Keep int on Apple (signed there), and fix the __WCHAR_MAX__/__WCHAR_MIN__ predefines on Linux to match gcc (4294967295u / 0u). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d867ffb commit 1bb2fe6

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

c-tests/runtests.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ else
3434
ARCH="other"
3535
fi
3636

37+
# busybox diff (e.g. on Alpine) lacks --strip-trailing-cr
38+
if diff --strip-trailing-cr /dev/null /dev/null >/dev/null 2>&1;then
39+
DIFF_STRIP_CR=--strip-trailing-cr
40+
else
41+
DIFF_STRIP_CR=
42+
fi
43+
3744
runtest () {
3845
t=$1
3946
if test -f $t.mach && ! $GREP -E "`uname -m`" $t.mach >/dev/null; then
@@ -57,14 +64,14 @@ runtest () {
5764
$TIMEOUT sh $execution_program $compiler $t $add_main 2>$stderrf >$outf
5865
code=$?
5966
if test $code = $expect_code; then
60-
if test x$expect_out != x && ! diff --strip-trailing-cr -up $expect_out $outf >$errf;then
67+
if test x$expect_out != x && ! diff $DIFF_STRIP_CR -up $expect_out $outf >$errf;then
6168
$ECHO Output mismatch
6269
cat $errf
6370
else
6471
ok=`expr $ok + 1`
6572
$ECHO -ne "OK \r"
6673
fi
67-
if test x$stderr_expect_out != x && ! diff --strip-trailing-cr -up $stderr_expect_out $stderrf >$errf;then
74+
if test x$stderr_expect_out != x && ! diff $DIFF_STRIP_CR -up $stderr_expect_out $stderrf >$errf;then
6875
$ECHO Stderr mismatch
6976
cat $errf
7077
else

c2mir/aarch64/mirc_aarch64_linux.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ static char aarch64_mirc[]
5252
"#define __UINT32_MAX__ (__INT32_MAX__ * 2u + 1u)\n"
5353
"#define __UINT64_MAX__ (__INT64_MAX__ * 2u + 1u)\n"
5454
#if defined(__linux__)
55-
"#define __WCHAR_MAX__ 0x7fffffff\n"
55+
/* wchar_t is unsigned int in AAPCS64 */
56+
"#define __WCHAR_MAX__ 4294967295u\n"
57+
"#define __WCHAR_MIN__ 0u\n"
5658
#else
5759
"#define __WCHAR_MAX__ 2147483647\n"
58-
#endif
5960
"#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)\n"
61+
#endif
6062
"#define __SCHAR_MAX__ __INT8_MAX__\n"
6163
"#define __SHRT_MAX__ __INT16_MAX__\n"
6264
"#define __INT_MAX__ __INT32_MAX__\n"

c2mir/aarch64/mirc_aarch64_stddef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ static char stddef_str[]
1010
"typedef long ptrdiff_t;\n"
1111
"typedef unsigned long size_t;\n"
1212
"typedef long double max_align_t;\n"
13+
#if defined(__APPLE__)
1314
"typedef int wchar_t;\n"
15+
#else
16+
/* unsigned in AAPCS64; matters because musl's alltypes.h redeclares it */
17+
"typedef unsigned int wchar_t;\n"
18+
#endif
1419
"\n"
1520
"#define NULL ((void *) 0)\n"
1621
"\n"

0 commit comments

Comments
 (0)