Skip to content

Commit bd3d0c4

Browse files
committed
Add regression test for compiler bug with floats and varargs.
See CHERIoT-Platform/llvm-project#165 . This fails with current dev container but should pass once the above PR is merged and a new dev container built.
1 parent ca839e1 commit bd3d0c4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/softfloat-test.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdarg.h>
2+
13
#define TEST_NAME "Softfloat"
24
#include "stack_tests.h"
35
#include "tests.hh"
@@ -53,11 +55,37 @@ namespace
5355
}
5456
} // namespace
5557

58+
/**
59+
* Regression test for compiler bug with floats and varargs.
60+
* See https://github.com/CHERIoT-Platform/llvm-project/pull/165
61+
* The bug depends a bit on stack alignment so try a couple of different
62+
* argument types.
63+
*/
64+
double test_varargs(int c, ...)
65+
{
66+
va_list ap;
67+
va_start(ap, c);
68+
switch (c)
69+
{
70+
case 'i':
71+
va_arg(ap, int);
72+
break;
73+
case 'l':
74+
va_arg(ap, long long);
75+
break;
76+
}
77+
double f = va_arg(ap, double);
78+
va_end(ap);
79+
return f;
80+
}
81+
5682
int test_softfloat()
5783
{
5884
debug_log("Testing float");
5985
test<float>();
6086
debug_log("Testing double");
6187
test<double>();
88+
TEST_EQUAL(test_varargs('i', 1, 2.5), 2.5, "varargs i failed");
89+
TEST_EQUAL(test_varargs('l', 1ll, -1.0), -1.0, "varargs l failed");
6290
return 0;
6391
}

0 commit comments

Comments
 (0)