authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-01-26 00:45:40-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-29 15:04:13-05:00
loga9b68308b9eeb494524e2b7ab0d63cfa6b623cd0
tree0c6de0921db3a4f661be1d07415cb7a264234aa1
parent9177e0da4f8e3480f5a7fade6c42f2ec81f5ffd5

cbe: fixes for tls, support for not linking libc, and enabling tests

- cbe: Implement linksection support, to support TLS when not linking libc - cbe: Support under-aligned variables / struct fields - cbe: Support packed structs (in the C definition of packed) - windows: Fix regression with x86 _tls_array - compiler_rt: Add 128-bit atomics to compiler_rt - tests: Re-enable threadlocal tests on cbe+windows, and llvm+x86 - tests: Re-enable f80 tests that now pass - ci: change windows ci to run the CBE behaviour tests with -lc, to match how the compiler is bootstrapped - update zig1.wasm

10 files changed, 190 insertions(+), 33 deletions(-)

ci/x86_64-windows-debug.ps1+3-2
......@@ -76,7 +76,8 @@ Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
7676 -ofmt=c `
7777 -femit-bin="test-x86_64-windows-msvc.c" `
7878 --test-no-exec `
79 -target x86_64-windows-msvc
79 -target x86_64-windows-msvc `
80 -lc
8081CheckLastExitCode
8182
8283& "stage3-debug\bin\zig.exe" build-obj `
......@@ -99,7 +100,7 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\E
99100CheckLastExitCode
100101
101102Write-Output "Build and run behavior tests with msvc..."
102& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console -entry:wWinMainCRTStartup kernel32.lib ntdll.lib vcruntime.lib libucrt.lib
103& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
103104CheckLastExitCode
104105
105106& .\test-x86_64-windows-msvc.exe
ci/x86_64-windows-release.ps1+3-2
......@@ -76,7 +76,8 @@ Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
7676 -ofmt=c `
7777 -femit-bin="test-x86_64-windows-msvc.c" `
7878 --test-no-exec `
79 -target x86_64-windows-msvc
79 -target x86_64-windows-msvc `
80 -lc
8081CheckLastExitCode
8182
8283& "stage3-release\bin\zig.exe" build-obj `
......@@ -99,7 +100,7 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\E
99100CheckLastExitCode
100101
101102Write-Output "Build and run behavior tests with msvc..."
102& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console -entry:wWinMainCRTStartup kernel32.lib ntdll.lib vcruntime.lib libucrt.lib
103& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
103104CheckLastExitCode
104105
105106& .\test-x86_64-windows-msvc.exe
lib/compiler_rt/atomics.zig+104
......@@ -192,6 +192,10 @@ fn __atomic_load_8(src: *u64, model: i32) callconv(.C) u64 {
192192 return atomic_load_N(u64, src, model);
193193}
194194
195fn __atomic_load_16(src: *u128, model: i32) callconv(.C) u128 {
196 return atomic_load_N(u128, src, model);
197}
198
195199inline fn atomic_store_N(comptime T: type, dst: *T, value: T, model: i32) void {
196200 _ = model;
197201 if (@sizeOf(T) > largest_atomic_size) {
......@@ -219,6 +223,10 @@ fn __atomic_store_8(dst: *u64, value: u64, model: i32) callconv(.C) void {
219223 return atomic_store_N(u64, dst, value, model);
220224}
221225
226fn __atomic_store_16(dst: *u128, value: u128, model: i32) callconv(.C) void {
227 return atomic_store_N(u128, dst, value, model);
228}
229
222230fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
223231 const WideAtomic = std.meta.Int(.unsigned, smallest_atomic_fetch_exch_size * 8);
224232
......@@ -282,6 +290,10 @@ fn __atomic_exchange_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
282290 return atomic_exchange_N(u64, ptr, val, model);
283291}
284292
293fn __atomic_exchange_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
294 return atomic_exchange_N(u128, ptr, val, model);
295}
296
285297inline fn atomic_compare_exchange_N(
286298 comptime T: type,
287299 ptr: *T,
......@@ -327,6 +339,10 @@ fn __atomic_compare_exchange_8(ptr: *u64, expected: *u64, desired: u64, success:
327339 return atomic_compare_exchange_N(u64, ptr, expected, desired, success, failure);
328340}
329341
342fn __atomic_compare_exchange_16(ptr: *u128, expected: *u128, desired: u128, success: i32, failure: i32) callconv(.C) i32 {
343 return atomic_compare_exchange_N(u128, ptr, expected, desired, success, failure);
344}
345
330346inline fn fetch_op_N(comptime T: type, comptime op: std.builtin.AtomicRmwOp, ptr: *T, val: T, model: i32) T {
331347 _ = model;
332348 const Updater = struct {
......@@ -338,6 +354,8 @@ inline fn fetch_op_N(comptime T: type, comptime op: std.builtin.AtomicRmwOp, ptr
338354 .Nand => ~(old & new),
339355 .Or => old | new,
340356 .Xor => old ^ new,
357 .Max => @max(old, new),
358 .Min => @min(old, new),
341359 else => @compileError("unsupported atomic op"),
342360 };
343361 }
......@@ -374,6 +392,10 @@ fn __atomic_fetch_add_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
374392 return fetch_op_N(u64, .Add, ptr, val, model);
375393}
376394
395fn __atomic_fetch_add_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
396 return fetch_op_N(u128, .Add, ptr, val, model);
397}
398
377399fn __atomic_fetch_sub_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
378400 return fetch_op_N(u8, .Sub, ptr, val, model);
379401}
......@@ -390,6 +412,10 @@ fn __atomic_fetch_sub_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
390412 return fetch_op_N(u64, .Sub, ptr, val, model);
391413}
392414
415fn __atomic_fetch_sub_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
416 return fetch_op_N(u128, .Sub, ptr, val, model);
417}
418
393419fn __atomic_fetch_and_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
394420 return fetch_op_N(u8, .And, ptr, val, model);
395421}
......@@ -406,6 +432,10 @@ fn __atomic_fetch_and_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
406432 return fetch_op_N(u64, .And, ptr, val, model);
407433}
408434
435fn __atomic_fetch_and_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
436 return fetch_op_N(u128, .And, ptr, val, model);
437}
438
409439fn __atomic_fetch_or_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
410440 return fetch_op_N(u8, .Or, ptr, val, model);
411441}
......@@ -422,6 +452,10 @@ fn __atomic_fetch_or_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
422452 return fetch_op_N(u64, .Or, ptr, val, model);
423453}
424454
455fn __atomic_fetch_or_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
456 return fetch_op_N(u128, .Or, ptr, val, model);
457}
458
425459fn __atomic_fetch_xor_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
426460 return fetch_op_N(u8, .Xor, ptr, val, model);
427461}
......@@ -438,6 +472,10 @@ fn __atomic_fetch_xor_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
438472 return fetch_op_N(u64, .Xor, ptr, val, model);
439473}
440474
475fn __atomic_fetch_xor_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
476 return fetch_op_N(u128, .Xor, ptr, val, model);
477}
478
441479fn __atomic_fetch_nand_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
442480 return fetch_op_N(u8, .Nand, ptr, val, model);
443481}
......@@ -454,6 +492,50 @@ fn __atomic_fetch_nand_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
454492 return fetch_op_N(u64, .Nand, ptr, val, model);
455493}
456494
495fn __atomic_fetch_nand_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
496 return fetch_op_N(u128, .Nand, ptr, val, model);
497}
498
499fn __atomic_fetch_umax_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
500 return fetch_op_N(u8, .Max, ptr, val, model);
501}
502
503fn __atomic_fetch_umax_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
504 return fetch_op_N(u16, .Max, ptr, val, model);
505}
506
507fn __atomic_fetch_umax_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
508 return fetch_op_N(u32, .Max, ptr, val, model);
509}
510
511fn __atomic_fetch_umax_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
512 return fetch_op_N(u64, .Max, ptr, val, model);
513}
514
515fn __atomic_fetch_umax_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
516 return fetch_op_N(u128, .Max, ptr, val, model);
517}
518
519fn __atomic_fetch_umin_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
520 return fetch_op_N(u8, .Min, ptr, val, model);
521}
522
523fn __atomic_fetch_umin_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
524 return fetch_op_N(u16, .Min, ptr, val, model);
525}
526
527fn __atomic_fetch_umin_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
528 return fetch_op_N(u32, .Min, ptr, val, model);
529}
530
531fn __atomic_fetch_umin_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
532 return fetch_op_N(u64, .Min, ptr, val, model);
533}
534
535fn __atomic_fetch_umin_16(ptr: *u128, val: u128, model: i32) callconv(.C) u128 {
536 return fetch_op_N(u128, .Min, ptr, val, model);
537}
538
457539comptime {
458540 if (supports_atomic_ops and builtin.object_format != .c) {
459541 @export(__atomic_load, .{ .name = "__atomic_load", .linkage = linkage, .visibility = visibility });
......@@ -465,50 +547,72 @@ comptime {
465547 @export(__atomic_fetch_add_2, .{ .name = "__atomic_fetch_add_2", .linkage = linkage, .visibility = visibility });
466548 @export(__atomic_fetch_add_4, .{ .name = "__atomic_fetch_add_4", .linkage = linkage, .visibility = visibility });
467549 @export(__atomic_fetch_add_8, .{ .name = "__atomic_fetch_add_8", .linkage = linkage, .visibility = visibility });
550 @export(__atomic_fetch_add_16, .{ .name = "__atomic_fetch_add_16", .linkage = linkage, .visibility = visibility });
468551
469552 @export(__atomic_fetch_sub_1, .{ .name = "__atomic_fetch_sub_1", .linkage = linkage, .visibility = visibility });
470553 @export(__atomic_fetch_sub_2, .{ .name = "__atomic_fetch_sub_2", .linkage = linkage, .visibility = visibility });
471554 @export(__atomic_fetch_sub_4, .{ .name = "__atomic_fetch_sub_4", .linkage = linkage, .visibility = visibility });
472555 @export(__atomic_fetch_sub_8, .{ .name = "__atomic_fetch_sub_8", .linkage = linkage, .visibility = visibility });
556 @export(__atomic_fetch_sub_16, .{ .name = "__atomic_fetch_sub_16", .linkage = linkage, .visibility = visibility });
473557
474558 @export(__atomic_fetch_and_1, .{ .name = "__atomic_fetch_and_1", .linkage = linkage, .visibility = visibility });
475559 @export(__atomic_fetch_and_2, .{ .name = "__atomic_fetch_and_2", .linkage = linkage, .visibility = visibility });
476560 @export(__atomic_fetch_and_4, .{ .name = "__atomic_fetch_and_4", .linkage = linkage, .visibility = visibility });
477561 @export(__atomic_fetch_and_8, .{ .name = "__atomic_fetch_and_8", .linkage = linkage, .visibility = visibility });
562 @export(__atomic_fetch_and_16, .{ .name = "__atomic_fetch_and_16", .linkage = linkage, .visibility = visibility });
478563
479564 @export(__atomic_fetch_or_1, .{ .name = "__atomic_fetch_or_1", .linkage = linkage, .visibility = visibility });
480565 @export(__atomic_fetch_or_2, .{ .name = "__atomic_fetch_or_2", .linkage = linkage, .visibility = visibility });
481566 @export(__atomic_fetch_or_4, .{ .name = "__atomic_fetch_or_4", .linkage = linkage, .visibility = visibility });
482567 @export(__atomic_fetch_or_8, .{ .name = "__atomic_fetch_or_8", .linkage = linkage, .visibility = visibility });
568 @export(__atomic_fetch_or_16, .{ .name = "__atomic_fetch_or_16", .linkage = linkage, .visibility = visibility });
483569
484570 @export(__atomic_fetch_xor_1, .{ .name = "__atomic_fetch_xor_1", .linkage = linkage, .visibility = visibility });
485571 @export(__atomic_fetch_xor_2, .{ .name = "__atomic_fetch_xor_2", .linkage = linkage, .visibility = visibility });
486572 @export(__atomic_fetch_xor_4, .{ .name = "__atomic_fetch_xor_4", .linkage = linkage, .visibility = visibility });
487573 @export(__atomic_fetch_xor_8, .{ .name = "__atomic_fetch_xor_8", .linkage = linkage, .visibility = visibility });
574 @export(__atomic_fetch_xor_16, .{ .name = "__atomic_fetch_xor_16", .linkage = linkage, .visibility = visibility });
488575
489576 @export(__atomic_fetch_nand_1, .{ .name = "__atomic_fetch_nand_1", .linkage = linkage, .visibility = visibility });
490577 @export(__atomic_fetch_nand_2, .{ .name = "__atomic_fetch_nand_2", .linkage = linkage, .visibility = visibility });
491578 @export(__atomic_fetch_nand_4, .{ .name = "__atomic_fetch_nand_4", .linkage = linkage, .visibility = visibility });
492579 @export(__atomic_fetch_nand_8, .{ .name = "__atomic_fetch_nand_8", .linkage = linkage, .visibility = visibility });
580 @export(__atomic_fetch_nand_16, .{ .name = "__atomic_fetch_nand_16", .linkage = linkage, .visibility = visibility });
581
582 @export(__atomic_fetch_umax_1, .{ .name = "__atomic_fetch_umax_1", .linkage = linkage, .visibility = visibility });
583 @export(__atomic_fetch_umax_2, .{ .name = "__atomic_fetch_umax_2", .linkage = linkage, .visibility = visibility });
584 @export(__atomic_fetch_umax_4, .{ .name = "__atomic_fetch_umax_4", .linkage = linkage, .visibility = visibility });
585 @export(__atomic_fetch_umax_8, .{ .name = "__atomic_fetch_umax_8", .linkage = linkage, .visibility = visibility });
586 @export(__atomic_fetch_umax_16, .{ .name = "__atomic_fetch_umax_16", .linkage = linkage, .visibility = visibility });
587
588 @export(__atomic_fetch_umin_1, .{ .name = "__atomic_fetch_umin_1", .linkage = linkage, .visibility = visibility });
589 @export(__atomic_fetch_umin_2, .{ .name = "__atomic_fetch_umin_2", .linkage = linkage, .visibility = visibility });
590 @export(__atomic_fetch_umin_4, .{ .name = "__atomic_fetch_umin_4", .linkage = linkage, .visibility = visibility });
591 @export(__atomic_fetch_umin_8, .{ .name = "__atomic_fetch_umin_8", .linkage = linkage, .visibility = visibility });
592 @export(__atomic_fetch_umin_16, .{ .name = "__atomic_fetch_umin_16", .linkage = linkage, .visibility = visibility });
493593
494594 @export(__atomic_load_1, .{ .name = "__atomic_load_1", .linkage = linkage, .visibility = visibility });
495595 @export(__atomic_load_2, .{ .name = "__atomic_load_2", .linkage = linkage, .visibility = visibility });
496596 @export(__atomic_load_4, .{ .name = "__atomic_load_4", .linkage = linkage, .visibility = visibility });
497597 @export(__atomic_load_8, .{ .name = "__atomic_load_8", .linkage = linkage, .visibility = visibility });
598 @export(__atomic_load_16, .{ .name = "__atomic_load_16", .linkage = linkage, .visibility = visibility });
498599
499600 @export(__atomic_store_1, .{ .name = "__atomic_store_1", .linkage = linkage, .visibility = visibility });
500601 @export(__atomic_store_2, .{ .name = "__atomic_store_2", .linkage = linkage, .visibility = visibility });
501602 @export(__atomic_store_4, .{ .name = "__atomic_store_4", .linkage = linkage, .visibility = visibility });
502603 @export(__atomic_store_8, .{ .name = "__atomic_store_8", .linkage = linkage, .visibility = visibility });
604 @export(__atomic_store_16, .{ .name = "__atomic_store_16", .linkage = linkage, .visibility = visibility });
503605
504606 @export(__atomic_exchange_1, .{ .name = "__atomic_exchange_1", .linkage = linkage, .visibility = visibility });
505607 @export(__atomic_exchange_2, .{ .name = "__atomic_exchange_2", .linkage = linkage, .visibility = visibility });
506608 @export(__atomic_exchange_4, .{ .name = "__atomic_exchange_4", .linkage = linkage, .visibility = visibility });
507609 @export(__atomic_exchange_8, .{ .name = "__atomic_exchange_8", .linkage = linkage, .visibility = visibility });
610 @export(__atomic_exchange_16, .{ .name = "__atomic_exchange_16", .linkage = linkage, .visibility = visibility });
508611
509612 @export(__atomic_compare_exchange_1, .{ .name = "__atomic_compare_exchange_1", .linkage = linkage, .visibility = visibility });
510613 @export(__atomic_compare_exchange_2, .{ .name = "__atomic_compare_exchange_2", .linkage = linkage, .visibility = visibility });
511614 @export(__atomic_compare_exchange_4, .{ .name = "__atomic_compare_exchange_4", .linkage = linkage, .visibility = visibility });
512615 @export(__atomic_compare_exchange_8, .{ .name = "__atomic_compare_exchange_8", .linkage = linkage, .visibility = visibility });
616 @export(__atomic_compare_exchange_16, .{ .name = "__atomic_compare_exchange_16", .linkage = linkage, .visibility = visibility });
513617 }
514618}
lib/std/start_windows_tls.zig+5-3
......@@ -7,12 +7,14 @@ export var _tls_end: u8 linksection(".tls$ZZZ") = 0;
77export var __xl_a: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLA") = null;
88export var __xl_z: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLZ") = null;
99
10const tls_array: u32 = 0x2c;
1110comptime {
12 if (builtin.target.cpu.arch == .x86) {
11 if (builtin.target.cpu.arch == .x86 and builtin.zig_backend != .stage2_c) {
1312 // The __tls_array is the offset of the ThreadLocalStoragePointer field
1413 // in the TEB block whose base address held in the %fs segment.
15 @export(tls_array, .{ .name = "_tls_array" });
14 asm (
15 \\ .global __tls_array
16 \\ __tls_array = 0x2C
17 );
1618 }
1719}
1820
lib/zig.h+24
......@@ -93,6 +93,14 @@ typedef char bool;
9393#define zig_align zig_align_unavailable
9494#endif
9595
96#if zig_has_attribute(aligned)
97#define zig_under_align(alignment) __attribute__((aligned(alignment)))
98#elif _MSC_VER
99#define zig_under_align(alignment) zig_align(alignment)
100#else
101#define zig_align zig_align_unavailable
102#endif
103
96104#if zig_has_attribute(aligned)
97105#define zig_align_fn(alignment) __attribute__((aligned(alignment)))
98106#elif _MSC_VER
......@@ -101,6 +109,22 @@ typedef char bool;
101109#define zig_align_fn zig_align_fn_unavailable
102110#endif
103111
112#if zig_has_attribute(packed)
113#define zig_packed(definition) __attribute__((packed)) definition
114#elif _MSC_VER
115#define zig_packed(definition) __pragma(pack(1)) definition __pragma(pack())
116#else
117#define zig_packed(definition) zig_packed_unavailable
118#endif
119
120#if zig_has_attribute(section)
121#define zig_linksection(name, def, ...) def __attribute__((section(name)))
122#elif _MSC_VER
123#define zig_linksection(name, def, ...) __pragma(section(name, __VA_ARGS__)) __declspec(allocate(name)) def
124#else
125#define zig_linksection(name, def, ...) zig_linksection_unavailable
126#endif
127
104128#if zig_has_builtin(unreachable) || defined(zig_gnuc)
105129#define zig_unreachable() __builtin_unreachable()
106130#else
src/codegen/c.zig+39-15
......@@ -1663,6 +1663,22 @@ pub const DeclGen = struct {
16631663 defer buffer.deinit();
16641664
16651665 try buffer.appendSlice("struct ");
1666
1667 var needs_pack_attr = false;
1668 {
1669 var it = t.structFields().iterator();
1670 while (it.next()) |field| {
1671 const field_ty = field.value_ptr.ty;
1672 if (!field_ty.hasRuntimeBits()) continue;
1673 const alignment = field.value_ptr.abi_align;
1674 if (alignment != 0 and alignment < field_ty.abiAlignment(dg.module.getTarget())) {
1675 needs_pack_attr = true;
1676 try buffer.appendSlice("zig_packed(");
1677 break;
1678 }
1679 }
1680 }
1681
16661682 try buffer.appendSlice(name);
16671683 try buffer.appendSlice(" {\n");
16681684 {
......@@ -1672,7 +1688,7 @@ pub const DeclGen = struct {
16721688 const field_ty = field.value_ptr.ty;
16731689 if (!field_ty.hasRuntimeBits()) continue;
16741690
1675 const alignment = field.value_ptr.abi_align;
1691 const alignment = field.value_ptr.alignment(dg.module.getTarget(), t.containerLayout());
16761692 const field_name = CValue{ .identifier = field.key_ptr.* };
16771693 try buffer.append(' ');
16781694 try dg.renderTypeAndName(buffer.writer(), field_ty, field_name, .Mut, alignment, .Complete);
......@@ -1682,7 +1698,7 @@ pub const DeclGen = struct {
16821698 }
16831699 if (empty) try buffer.appendSlice(" char empty_struct;\n");
16841700 }
1685 try buffer.appendSlice("};\n");
1701 if (needs_pack_attr) try buffer.appendSlice("});\n") else try buffer.appendSlice("};\n");
16861702
16871703 const rendered = try buffer.toOwnedSlice();
16881704 errdefer dg.typedefs.allocator.free(rendered);
......@@ -2367,8 +2383,13 @@ pub const DeclGen = struct {
23672383 depth += 1;
23682384 }
23692385
2370 if (alignment != 0 and alignment > ty.abiAlignment(target)) {
2371 try w.print("zig_align({}) ", .{alignment});
2386 if (alignment != 0) {
2387 const abi_alignment = ty.abiAlignment(target);
2388 if (alignment < abi_alignment) {
2389 try w.print("zig_under_align({}) ", .{alignment});
2390 } else if (alignment > abi_alignment) {
2391 try w.print("zig_align({}) ", .{alignment});
2392 }
23722393 }
23732394 try dg.renderType(w, render_ty, kind);
23742395
......@@ -2860,27 +2881,30 @@ pub fn genDecl(o: *Object) !void {
28602881 const w = o.writer();
28612882 if (!is_global) try w.writeAll("static ");
28622883 if (variable.is_threadlocal) try w.writeAll("zig_threadlocal ");
2884 if (o.dg.decl.@"linksection") |section| try w.print("zig_linksection(\"{s}\", ", .{section});
28632885 try o.dg.renderTypeAndName(w, o.dg.decl.ty, decl_c_value, .Mut, o.dg.decl.@"align", .Complete);
2886 if (o.dg.decl.@"linksection" != null) try w.writeAll(", read, write)");
28642887 try w.writeAll(" = ");
28652888 try o.dg.renderValue(w, tv.ty, variable.init, .StaticInitializer);
28662889 try w.writeByte(';');
28672890 try o.indent_writer.insertNewline();
28682891 } else {
2892 const is_global = o.dg.module.decl_exports.contains(o.dg.decl_index);
2893 const fwd_decl_writer = o.dg.fwd_decl.writer();
28692894 const decl_c_value: CValue = .{ .decl = o.dg.decl_index };
28702895
2871 const fwd_decl_writer = o.dg.fwd_decl.writer();
2872 try fwd_decl_writer.writeAll("static ");
2873 try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, .Mut, o.dg.decl.@"align", .Complete);
2896 try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
2897 try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, .Const, o.dg.decl.@"align", .Complete);
28742898 try fwd_decl_writer.writeAll(";\n");
28752899
2876 const writer = o.writer();
2877 try writer.writeAll("static ");
2878 // TODO ask the Decl if it is const
2879 // https://github.com/ziglang/zig/issues/7582
2880 try o.dg.renderTypeAndName(writer, tv.ty, decl_c_value, .Mut, o.dg.decl.@"align", .Complete);
2881 try writer.writeAll(" = ");
2882 try o.dg.renderValue(writer, tv.ty, tv.val, .StaticInitializer);
2883 try writer.writeAll(";\n");
2900 const w = o.writer();
2901 if (!is_global) try w.writeAll("static ");
2902 if (o.dg.decl.@"linksection") |section| try w.print("zig_linksection(\"{s}\", ", .{section});
2903 try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, .Const, o.dg.decl.@"align", .Complete);
2904 if (o.dg.decl.@"linksection" != null) try w.writeAll(", read)");
2905 try w.writeAll(" = ");
2906 try o.dg.renderValue(w, tv.ty, tv.val, .StaticInitializer);
2907 try w.writeAll(";\n");
28842908 }
28852909}
28862910
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior/math.zig-3
......@@ -1332,7 +1332,6 @@ test "float remainder division using @rem" {
13321332 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
13331333 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
13341334 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1335 if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/12602
13361335
13371336 comptime try frem(f16);
13381337 comptime try frem(f32);
......@@ -1375,7 +1374,6 @@ test "float modulo division using @mod" {
13751374 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
13761375 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
13771376 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1378 if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/12602
13791377
13801378 comptime try fmod(f16);
13811379 comptime try fmod(f32);
......@@ -1438,7 +1436,6 @@ test "@round f80" {
14381436 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
14391437 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
14401438 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1441 if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/12602
14421439
14431440 try testRound(f80, 12.0);
14441441 comptime try testRound(f80, 12.0);
test/behavior/muladd.zig-2
......@@ -50,7 +50,6 @@ test "@mulAdd f80" {
5050 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
5151 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
5252 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
53 if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/12602
5453
5554 comptime try testMulAdd80();
5655 try testMulAdd80();
......@@ -178,7 +177,6 @@ test "vector f80" {
178177 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
179178 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
180179 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
181 if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/12602
182180
183181 comptime try vector80();
184182 try vector80();
test/behavior/threadlocal.zig+12-6
......@@ -7,8 +7,10 @@ test "thread local variable" {
77 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
88 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
99 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
10 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch != .x86_64) return error.SkipZigTest; // TODO
11 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // TODO
10 if (builtin.zig_backend == .stage2_llvm) switch (builtin.cpu.arch) {
11 .x86_64, .x86 => {},
12 else => return error.SkipZigTest,
13 }; // TODO
1214 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1315
1416 const S = struct {
......@@ -23,8 +25,10 @@ test "pointer to thread local array" {
2325 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
2426 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
2527 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
26 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch != .x86_64) return error.SkipZigTest; // TODO
27 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // TODO
28 if (builtin.zig_backend == .stage2_llvm) switch (builtin.cpu.arch) {
29 .x86_64, .x86 => {},
30 else => return error.SkipZigTest,
31 }; // TODO
2832 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2933
3034 const s = "Hello world";
......@@ -39,8 +43,10 @@ test "reference a global threadlocal variable" {
3943 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
4044 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
4145 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
42 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch != .x86_64) return error.SkipZigTest; // TODO
43 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // TODO
46 if (builtin.zig_backend == .stage2_llvm) switch (builtin.cpu.arch) {
47 .x86_64, .x86 => {},
48 else => return error.SkipZigTest,
49 }; // TODO
4450 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
4551
4652 _ = nrfx_uart_rx(&g_uart0);