ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.27k stars 2.5k forks source link

"call to undeclared function 'zig_lo_big'" when formatting very large integers with -ofmt=c #20880

Closed MasonRemaley closed 2 months ago

MasonRemaley commented 2 months ago

Zig Version

0.14.0-dev.737+30b4a87db

Steps to Reproduce and Observed Behavior

Here's the code I'm running:

var buffer = std.ArrayList(u8).init(std.testing.allocator);
defer buffer.deinit();
const writer = buffer.writer();
try std.fmt.formatInt(680564733841876926926749214863536422912, 10, .lower, .{}, writer);
try std.testing.expectEqualSlices(u8, "680564733841876926926749214863536422912", buffer.items);
Here's the stack trace ```sh build/stage4/bin/zig test lib/std/std.zig -target x86_64-linux -ofmt=c -lc --test-filter "std.zon" /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:30980:16: error: call to undeclared function 'zig_lo_big'; ISO C99 and later do not support implicit function declarations memcpy(t7, zig_lo_big(t12), sizeof(zig_u128[2])); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:30980:12: error: incompatible integer to pointer conversion passing 'uintptr_t' (aka 'unsigned long') to parameter of type 'void *' memcpy(t7, zig_lo_big(t12), sizeof(zig_u128[2])); ^ lib/zig.h:335:44: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:30980:16: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' memcpy(t7, zig_lo_big(t12), sizeof(zig_u128[2])); ^~~~~~~~~~~~~~~ lib/zig.h:335:70: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31039:24: error: call to undeclared function 'zig_lo_big'; ISO C99 and later do not support implicit function declarations memcpy(t9, (uint8_t)zig_lo_big(t12), sizeof(zig_u128[2])); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31039:11: error: incompatible integer to pointer conversion passing 'uint8_t' (aka 'unsigned char') to parameter of type 'void *' memcpy(t9, (uint8_t)zig_lo_big(t12), sizeof(zig_u128[2])); ^ lib/zig.h:335:44: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31039:15: error: incompatible integer to pointer conversion passing 'uint8_t' (aka 'unsigned char') to parameter of type 'const void *' memcpy(t9, (uint8_t)zig_lo_big(t12), sizeof(zig_u128[2])); ^~~~~~~~~~~~~~~~~~~~~~~~ lib/zig.h:335:70: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31096:14: error: call to undeclared function 'zig_lo_big'; ISO C99 and later do not support implicit function declarations memcpy(t7, zig_lo_big(t12), sizeof(zig_u128[2])); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31096:10: error: incompatible integer to pointer conversion passing 'uintptr_t' (aka 'unsigned long') to parameter of type 'void *' memcpy(t7, zig_lo_big(t12), sizeof(zig_u128[2])); ^ lib/zig.h:335:44: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31096:14: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' memcpy(t7, zig_lo_big(t12), sizeof(zig_u128[2])); ^~~~~~~~~~~~~~~ lib/zig.h:335:70: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31111:8: error: call to undeclared function 'zig_make_big'; ISO C99 and later do not support implicit function declarations t5 = zig_make_big(0, a0); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31111:6: error: array type 'zig_u128[2]' (aka 'unsigned __int128[2]') is not assignable t5 = zig_make_big(0, a0); ~~~^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31158:23: error: call to undeclared function 'zig_lo_big'; ISO C99 and later do not support implicit function declarations memcpy(t9, (uint8_t)zig_lo_big(t21), sizeof(zig_u128[2])); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31158:10: error: incompatible integer to pointer conversion passing 'uint8_t' (aka 'unsigned char') to parameter of type 'void *' memcpy(t9, (uint8_t)zig_lo_big(t21), sizeof(zig_u128[2])); ^ lib/zig.h:335:44: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31158:14: error: incompatible integer to pointer conversion passing 'uint8_t' (aka 'unsigned char') to parameter of type 'const void *' memcpy(t9, (uint8_t)zig_lo_big(t21), sizeof(zig_u128[2])); ^~~~~~~~~~~~~~~~~~~~~~~~ lib/zig.h:335:70: note: passing argument to parameter here zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); ^ /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c:31165:6: error: array type 'zig_u128[2]' (aka 'unsigned __int128[2]') is not assignable t5 = zig_make_big(0, a0); ~~~^ error: the following test command failed with exit code 1: /home/mason/Documents/zig/build/stage4/bin/zig run -I lib -lc -target x86_64-linux /home/mason/Documents/zig/.zig-cache/o/1578b70c3aa1b4d8e3e64d703d0d4b7a/test.c ```

I'm not 100% sure whether this is a bug, or whether I need an additional flag for zig_lo_big to be defined or something.

Expected Behavior

I expected to successfully format the big integer.

tiehuis commented 2 months ago

See #19991.

MasonRemaley commented 2 months ago

Thanks for the link--closing as I believe this is a dup.