| author | |
| committer | |
| log | 25a3c933b9d708d907293b1a46b6661641ccf9ea |
| tree | 684afa383b5d9228aabe4cc1a7ff220c9051bac3 |
| parent | 828ac637b2703bfd3e40316a28e1f6b8315c6ed1 |
3 files changed, 24 insertions(+), 21 deletions(-)
lib/zig.h+4-4| ... | ... | @@ -288,13 +288,13 @@ typedef char bool; |
| 288 | 288 | #endif |
| 289 | 289 | |
| 290 | 290 | #if __STDC_VERSION__ >= 201112L |
| 291 | #define zig_noreturn _Noreturn void | |
| 291 | #define zig_noreturn _Noreturn | |
| 292 | 292 | #elif zig_has_attribute(noreturn) || defined(zig_gnuc) |
| 293 | #define zig_noreturn __attribute__((noreturn)) void | |
| 293 | #define zig_noreturn __attribute__((noreturn)) | |
| 294 | 294 | #elif _MSC_VER |
| 295 | #define zig_noreturn __declspec(noreturn) void | |
| 295 | #define zig_noreturn __declspec(noreturn) | |
| 296 | 296 | #else |
| 297 | #define zig_noreturn void | |
| 297 | #define zig_noreturn | |
| 298 | 298 | #endif |
| 299 | 299 | |
| 300 | 300 | #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) |
src/codegen/c.zig+14-11| ... | ... | @@ -1476,6 +1476,7 @@ pub const DeclGen = struct { |
| 1476 | 1476 | } |
| 1477 | 1477 | if (dg.decl.?.val.castTag(.function)) |func_payload| |
| 1478 | 1478 | if (func_payload.data.is_cold) try w.writeAll("zig_cold "); |
| 1479 | if (fn_info.return_type.tag() == .noreturn) try w.writeAll("zig_noreturn "); | |
| 1479 | 1480 | |
| 1480 | 1481 | const trailing = try renderTypePrefix( |
| 1481 | 1482 | dg.decl_index, |
| ... | ... | @@ -2289,7 +2290,7 @@ fn renderTypeSuffix( |
| 2289 | 2290 | w, |
| 2290 | 2291 | param_type, |
| 2291 | 2292 | .suffix, |
| 2292 | CQualifiers.init(.{}), | |
| 2293 | CQualifiers.init(.{ .@"const" = true }), | |
| 2293 | 2294 | ); |
| 2294 | 2295 | try w.print("{}a{d}", .{ trailing, param_i }); |
| 2295 | 2296 | try renderTypeSuffix(decl, store, mod, w, param_type, .suffix); |
| ... | ... | @@ -5737,26 +5738,28 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5737 | 5738 | const inst_ty = f.air.typeOfIndex(inst); |
| 5738 | 5739 | const writer = f.object.writer(); |
| 5739 | 5740 | 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(); | |
| 5742 | 5742 | |
| 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 | |
| 5744 | 5747 | if (operand == .undef) { |
| 5745 | // Unfortunately, C does not support any equivalent to | |
| 5746 | // &(*(void *)p)[0], although LLVM does via GetElementPtr | |
| 5747 | 5748 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 5748 | 5749 | try f.writeCValue(writer, CValue{ .undef = inst_ty.slicePtrFieldType(&buf) }, .Initializer); |
| 5749 | } else { | |
| 5750 | } else if (array_ty.hasRuntimeBitsIgnoreComptime()) { | |
| 5750 | 5751 | try writer.writeAll("&("); |
| 5751 | 5752 | try f.writeCValueDeref(writer, operand); |
| 5752 | 5753 | try writer.print(")[{}]", .{try f.fmtIntLiteral(Type.usize, Value.zero)}); |
| 5753 | } | |
| 5754 | } else try f.writeCValue(writer, operand, .Initializer); | |
| 5755 | try writer.writeAll("; "); | |
| 5754 | 5756 | |
| 5757 | const array_len = array_ty.arrayLen(); | |
| 5755 | 5758 | var len_pl: Value.Payload.U64 = .{ .base = .{ .tag = .int_u64 }, .data = array_len }; |
| 5756 | 5759 | 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 | ||
| 5760 | 5763 | return local; |
| 5761 | 5764 | } |
| 5762 | 5765 |
test/stage2/cbe.zig+6-6| ... | ... | @@ -959,7 +959,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 959 | 959 | \\ _ = a; |
| 960 | 960 | \\} |
| 961 | 961 | , |
| 962 | \\zig_extern void start(zig_u8 const a0); | |
| 962 | \\zig_extern void start(uint8_t const a0); | |
| 963 | 963 | \\ |
| 964 | 964 | ); |
| 965 | 965 | ctx.h("header with multiple param function", linux_x64, |
| ... | ... | @@ -967,19 +967,19 @@ pub fn addCases(ctx: *TestContext) !void { |
| 967 | 967 | \\ _ = a; _ = b; _ = c; |
| 968 | 968 | \\} |
| 969 | 969 | , |
| 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); | |
| 971 | 971 | \\ |
| 972 | 972 | ); |
| 973 | 973 | ctx.h("header with u32 param function", linux_x64, |
| 974 | 974 | \\export fn start(a: u32) void{ _ = a; } |
| 975 | 975 | , |
| 976 | \\zig_extern void start(zig_u32 const a0); | |
| 976 | \\zig_extern void start(uint32_t const a0); | |
| 977 | 977 | \\ |
| 978 | 978 | ); |
| 979 | 979 | ctx.h("header with usize param function", linux_x64, |
| 980 | 980 | \\export fn start(a: usize) void{ _ = a; } |
| 981 | 981 | , |
| 982 | \\zig_extern void start(zig_usize const a0); | |
| 982 | \\zig_extern void start(uintptr_t const a0); | |
| 983 | 983 | \\ |
| 984 | 984 | ); |
| 985 | 985 | ctx.h("header with bool param function", linux_x64, |
| ... | ... | @@ -993,7 +993,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 993 | 993 | \\ unreachable; |
| 994 | 994 | \\} |
| 995 | 995 | , |
| 996 | \\zig_extern zig_noreturn start(void); | |
| 996 | \\zig_extern zig_noreturn void start(void); | |
| 997 | 997 | \\ |
| 998 | 998 | ); |
| 999 | 999 | ctx.h("header with multiple functions", linux_x64, |
| ... | ... | @@ -1009,7 +1009,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1009 | 1009 | ctx.h("header with multiple includes", linux_x64, |
| 1010 | 1010 | \\export fn start(a: u32, b: usize) void{ _ = a; _ = b; } |
| 1011 | 1011 | , |
| 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); | |
| 1013 | 1013 | \\ |
| 1014 | 1014 | ); |
| 1015 | 1015 | } |