From 14ad364e17cced5e770bceb4027450853efc5a21 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 31 Mar 2022 14:47:04 +0900 Subject: [PATCH] [gamecode] Document the tests that fail under clang The tests fail due to differences in how clang and gcc treat floating point to unsigned integral type conversions when the values overflow. It wouldn't be so bad if clang was consistent with conversions to 32-bit unsigned integers, like it seems to be with conversion to 64-bit unsigned integers. With this, the "get QF building with clang" mini-project is done and I won't have to panic when someone comes to me and asks if it will work. At worst, there'll be a little bit-rot. --- libs/gamecode/test/test-conv4.c | 8 ++++++++ libs/gamecode/test/test-conv6.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/libs/gamecode/test/test-conv4.c b/libs/gamecode/test/test-conv4.c index 246b4bec3..3fb1b8d47 100644 --- a/libs/gamecode/test/test-conv4.c +++ b/libs/gamecode/test/test-conv4.c @@ -25,6 +25,14 @@ static pr_ivec4_t uint_conv_init[] = { { 0, 0, 0, 0}, }; +/* Note that these tests (specifically 1, 3a and 3b) fail when compiled with + * clang and optimzing due to difference between clang and gcc, and more + * interestingly, within clang itself: with optimization enabled, the entries + * marked with "undef?" produce 0x80000000 instead of 0, but with optimization + * disabled, the expected 0 is produced. + * Inspecting the results, it seems that clang sets negative floats and doubles + * to 0 when casting to unsigned long, but not consistently. + */ static pr_ivec4_t uint_conv_expect[] = { { 5, -5, 0x80000000, 0x7fffffff}, //int { 0x3fc00000, 0xbfc00000, 0x7149f2ca, 0xf149f2ca}, //float diff --git a/libs/gamecode/test/test-conv6.c b/libs/gamecode/test/test-conv6.c index b32cfc537..76bb018ed 100644 --- a/libs/gamecode/test/test-conv6.c +++ b/libs/gamecode/test/test-conv6.c @@ -33,6 +33,12 @@ static pr_ivec4_t ulong_conv_init[] = { { 0, 0, 0, 0}, }; +/* Note that these tests fail when compiled with clang due to difference + * between clang and gcc. However, unlike test-conv4, the failure is + * consistent between optimized and unoptimized: all tests fail either way. + * Inspecting the results, it seems that clang sets negative floats and doubles + * to 0 when casting to unsigned long. + */ static pr_ivec4_t ulong_conv_expect[] = { { 5, -5, 0x80000000, 0x7fffffff}, //int { 0x3fc00000, 0xbfc00000, 0x7149f2ca, 0xf149f2ca}, //float