Hi,
Recently I upgrade clang toolchain from 19 to 20 on my machine, finding that my Rust binding failed on unit tests. I've done some initial research on this problem and made a minimal version in c:
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "quickjs.c"
// assuming this file is ctest.c, build by:
// WIndows: clang -std=c11 -DWIN32_LEAN_AND_MEAN="_WIN32_WINNT=0x0601" -D_GNU_SOURCE=1 ctest.c cutils.c libregexp.c libunicode.c xsum.c -o ctest.exe
// Linux: clang -std=c11 -D_GNU_SOURCE=1 ctest.c cutils.c libregexp.c libunicode.c xsum.c -o ctest -lm
int main(void)
{
// -9223372036854775807n is ok, only values beyond i64 will cause an exception
static const char code[] = "-9223372036854775808n";
JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);
JSValue ret = JS_Eval(ctx, code, strlen(code), "<input>", JS_EVAL_TYPE_GLOBAL);
assert(!JS_IsException(ret));
JSValue s = js_bigint_to_string1(ctx, ret, 16);
if (JS_IsException(s)) {
JSValue e = JS_GetException(ctx);
printf("BigInt to string: %s\n", JS_ToCString(ctx, e));
JS_FreeValue(ctx, e);
}
JS_FreeValue(ctx, s);
JS_FreeValue(ctx, ret);
assert(!JS_HasException(ctx));
return 0;
}
As you can see above, I've reproduced the problem under both Windows and archlinux as either a pointer exception or a js exception of “out of memory”, one of which occurs at random.
Problems only occur when passing in values out of the i64 range under Clang 20, while no problem in any case under Clang 19.
Hi,
Recently I upgrade clang toolchain from 19 to 20 on my machine, finding that my Rust binding failed on unit tests. I've done some initial research on this problem and made a minimal version in c:
As you can see above, I've reproduced the problem under both Windows and archlinux as either a pointer exception or a js exception of “out of memory”, one of which occurs at random.
Problems only occur when passing in values out of the i64 range under Clang 20, while no problem in any case under Clang 19.