authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-02-21 02:21:39-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-02-21 02:32:49-05:00
log25a3c933b9d708d907293b1a46b6661641ccf9ea
tree684afa383b5d9228aabe4cc1a7ff220c9051bac3
parent828ac637b2703bfd3e40316a28e1f6b8315c6ed1

CBE: fix test failures


3 files changed, 24 insertions(+), 21 deletions(-)

lib/zig.h+4-4
......@@ -288,13 +288,13 @@ typedef char bool;
288288#endif
289289
290290#if __STDC_VERSION__ >= 201112L
291#define zig_noreturn _Noreturn void
291#define zig_noreturn _Noreturn
292292#elif zig_has_attribute(noreturn) || defined(zig_gnuc)
293#define zig_noreturn __attribute__((noreturn)) void
293#define zig_noreturn __attribute__((noreturn))
294294#elif _MSC_VER
295#define zig_noreturn __declspec(noreturn) void
295#define zig_noreturn __declspec(noreturn)
296296#else
297#define zig_noreturn void
297#define zig_noreturn
298298#endif
299299
300300#define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T))
src/codegen/c.zig+14-11
......@@ -1476,6 +1476,7 @@ pub const DeclGen = struct {
14761476 }
14771477 if (dg.decl.?.val.castTag(.function)) |func_payload|
14781478 if (func_payload.data.is_cold) try w.writeAll("zig_cold ");
1479 if (fn_info.return_type.tag() == .noreturn) try w.writeAll("zig_noreturn ");
14791480
14801481 const trailing = try renderTypePrefix(
14811482 dg.decl_index,
......@@ -2289,7 +2290,7 @@ fn renderTypeSuffix(
22892290 w,
22902291 param_type,
22912292 .suffix,
2292 CQualifiers.init(.{}),
2293 CQualifiers.init(.{ .@"const" = true }),
22932294 );
22942295 try w.print("{}a{d}", .{ trailing, param_i });
22952296 try renderTypeSuffix(decl, store, mod, w, param_type, .suffix);
......@@ -5737,26 +5738,28 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
57375738 const inst_ty = f.air.typeOfIndex(inst);
57385739 const writer = f.object.writer();
57395740 const local = try f.allocLocal(inst, inst_ty);
5740 try f.writeCValue(writer, local, .Other);
5741 const array_len = f.air.typeOf(ty_op.operand).elemType().arrayLen();
5741 const array_ty = f.air.typeOf(ty_op.operand).childType();
57425742
5743 try writer.writeAll(".ptr = ");
5743 try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });
5744 try writer.writeAll(" = ");
5745 // Unfortunately, C does not support any equivalent to
5746 // &(*(void *)p)[0], although LLVM does via GetElementPtr
57445747 if (operand == .undef) {
5745 // Unfortunately, C does not support any equivalent to
5746 // &(*(void *)p)[0], although LLVM does via GetElementPtr
57475748 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
57485749 try f.writeCValue(writer, CValue{ .undef = inst_ty.slicePtrFieldType(&buf) }, .Initializer);
5749 } else {
5750 } else if (array_ty.hasRuntimeBitsIgnoreComptime()) {
57505751 try writer.writeAll("&(");
57515752 try f.writeCValueDeref(writer, operand);
57525753 try writer.print(")[{}]", .{try f.fmtIntLiteral(Type.usize, Value.zero)});
5753 }
5754 } else try f.writeCValue(writer, operand, .Initializer);
5755 try writer.writeAll("; ");
57545756
5757 const array_len = array_ty.arrayLen();
57555758 var len_pl: Value.Payload.U64 = .{ .base = .{ .tag = .int_u64 }, .data = array_len };
57565759 const len_val = Value.initPayload(&len_pl.base);
5757 try writer.writeAll("; ");
5758 try f.writeCValue(writer, local, .Other);
5759 try writer.print(".len = {};\n", .{try f.fmtIntLiteral(Type.usize, len_val)});
5760 try f.writeCValueMember(writer, local, .{ .identifier = "len" });
5761 try writer.print(" = {};\n", .{try f.fmtIntLiteral(Type.usize, len_val)});
5762
57605763 return local;
57615764}
57625765
test/stage2/cbe.zig+6-6
......@@ -959,7 +959,7 @@ pub fn addCases(ctx: *TestContext) !void {
959959 \\ _ = a;
960960 \\}
961961 ,
962 \\zig_extern void start(zig_u8 const a0);
962 \\zig_extern void start(uint8_t const a0);
963963 \\
964964 );
965965 ctx.h("header with multiple param function", linux_x64,
......@@ -967,19 +967,19 @@ pub fn addCases(ctx: *TestContext) !void {
967967 \\ _ = a; _ = b; _ = c;
968968 \\}
969969 ,
970 \\zig_extern void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2);
970 \\zig_extern void start(uint8_t const a0, uint8_t const a1, uint8_t const a2);
971971 \\
972972 );
973973 ctx.h("header with u32 param function", linux_x64,
974974 \\export fn start(a: u32) void{ _ = a; }
975975 ,
976 \\zig_extern void start(zig_u32 const a0);
976 \\zig_extern void start(uint32_t const a0);
977977 \\
978978 );
979979 ctx.h("header with usize param function", linux_x64,
980980 \\export fn start(a: usize) void{ _ = a; }
981981 ,
982 \\zig_extern void start(zig_usize const a0);
982 \\zig_extern void start(uintptr_t const a0);
983983 \\
984984 );
985985 ctx.h("header with bool param function", linux_x64,
......@@ -993,7 +993,7 @@ pub fn addCases(ctx: *TestContext) !void {
993993 \\ unreachable;
994994 \\}
995995 ,
996 \\zig_extern zig_noreturn start(void);
996 \\zig_extern zig_noreturn void start(void);
997997 \\
998998 );
999999 ctx.h("header with multiple functions", linux_x64,
......@@ -1009,7 +1009,7 @@ pub fn addCases(ctx: *TestContext) !void {
10091009 ctx.h("header with multiple includes", linux_x64,
10101010 \\export fn start(a: u32, b: usize) void{ _ = a; _ = b; }
10111011 ,
1012 \\zig_extern void start(zig_u32 const a0, zig_usize const a1);
1012 \\zig_extern void start(uint32_t const a0, uintptr_t const a1);
10131013 \\
10141014 );
10151015}