Commit 25a3c933b9

Jacob Young <jacobly0@users.noreply.github.com>
2023-02-21 08:21:39
CBE: fix test failures
1 parent 828ac63
Changed files (3)
lib
src
codegen
test
stage2
lib/zig.h
@@ -288,13 +288,13 @@ typedef char bool;
 #endif
 
 #if __STDC_VERSION__ >= 201112L
-#define zig_noreturn _Noreturn void
+#define zig_noreturn _Noreturn
 #elif zig_has_attribute(noreturn) || defined(zig_gnuc)
-#define zig_noreturn __attribute__((noreturn)) void
+#define zig_noreturn __attribute__((noreturn))
 #elif _MSC_VER
-#define zig_noreturn __declspec(noreturn) void
+#define zig_noreturn __declspec(noreturn)
 #else
-#define zig_noreturn void
+#define zig_noreturn
 #endif
 
 #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T))
src/codegen/c.zig
@@ -1476,6 +1476,7 @@ pub const DeclGen = struct {
         }
         if (dg.decl.?.val.castTag(.function)) |func_payload|
             if (func_payload.data.is_cold) try w.writeAll("zig_cold ");
+        if (fn_info.return_type.tag() == .noreturn) try w.writeAll("zig_noreturn ");
 
         const trailing = try renderTypePrefix(
             dg.decl_index,
@@ -2289,7 +2290,7 @@ fn renderTypeSuffix(
                     w,
                     param_type,
                     .suffix,
-                    CQualifiers.init(.{}),
+                    CQualifiers.init(.{ .@"const" = true }),
                 );
                 try w.print("{}a{d}", .{ trailing, param_i });
                 try renderTypeSuffix(decl, store, mod, w, param_type, .suffix);
@@ -5737,26 +5738,28 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
     const inst_ty = f.air.typeOfIndex(inst);
     const writer = f.object.writer();
     const local = try f.allocLocal(inst, inst_ty);
-    try f.writeCValue(writer, local, .Other);
-    const array_len = f.air.typeOf(ty_op.operand).elemType().arrayLen();
+    const array_ty = f.air.typeOf(ty_op.operand).childType();
 
-    try writer.writeAll(".ptr = ");
+    try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });
+    try writer.writeAll(" = ");
+    // Unfortunately, C does not support any equivalent to
+    // &(*(void *)p)[0], although LLVM does via GetElementPtr
     if (operand == .undef) {
-        // Unfortunately, C does not support any equivalent to
-        // &(*(void *)p)[0], although LLVM does via GetElementPtr
         var buf: Type.SlicePtrFieldTypeBuffer = undefined;
         try f.writeCValue(writer, CValue{ .undef = inst_ty.slicePtrFieldType(&buf) }, .Initializer);
-    } else {
+    } else if (array_ty.hasRuntimeBitsIgnoreComptime()) {
         try writer.writeAll("&(");
         try f.writeCValueDeref(writer, operand);
         try writer.print(")[{}]", .{try f.fmtIntLiteral(Type.usize, Value.zero)});
-    }
+    } else try f.writeCValue(writer, operand, .Initializer);
+    try writer.writeAll("; ");
 
+    const array_len = array_ty.arrayLen();
     var len_pl: Value.Payload.U64 = .{ .base = .{ .tag = .int_u64 }, .data = array_len };
     const len_val = Value.initPayload(&len_pl.base);
-    try writer.writeAll("; ");
-    try f.writeCValue(writer, local, .Other);
-    try writer.print(".len = {};\n", .{try f.fmtIntLiteral(Type.usize, len_val)});
+    try f.writeCValueMember(writer, local, .{ .identifier = "len" });
+    try writer.print(" = {};\n", .{try f.fmtIntLiteral(Type.usize, len_val)});
+
     return local;
 }
 
test/stage2/cbe.zig
@@ -959,7 +959,7 @@ pub fn addCases(ctx: *TestContext) !void {
         \\    _ = a;
         \\}
     ,
-        \\zig_extern void start(zig_u8 const a0);
+        \\zig_extern void start(uint8_t const a0);
         \\
     );
     ctx.h("header with multiple param function", linux_x64,
@@ -967,19 +967,19 @@ pub fn addCases(ctx: *TestContext) !void {
         \\  _ = a; _ = b; _ = c;
         \\}
     ,
-        \\zig_extern void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2);
+        \\zig_extern void start(uint8_t const a0, uint8_t const a1, uint8_t const a2);
         \\
     );
     ctx.h("header with u32 param function", linux_x64,
         \\export fn start(a: u32) void{ _ = a; }
     ,
-        \\zig_extern void start(zig_u32 const a0);
+        \\zig_extern void start(uint32_t const a0);
         \\
     );
     ctx.h("header with usize param function", linux_x64,
         \\export fn start(a: usize) void{ _ = a; }
     ,
-        \\zig_extern void start(zig_usize const a0);
+        \\zig_extern void start(uintptr_t const a0);
         \\
     );
     ctx.h("header with bool param function", linux_x64,
@@ -993,7 +993,7 @@ pub fn addCases(ctx: *TestContext) !void {
         \\    unreachable;
         \\}
     ,
-        \\zig_extern zig_noreturn start(void);
+        \\zig_extern zig_noreturn void start(void);
         \\
     );
     ctx.h("header with multiple functions", linux_x64,
@@ -1009,7 +1009,7 @@ pub fn addCases(ctx: *TestContext) !void {
     ctx.h("header with multiple includes", linux_x64,
         \\export fn start(a: u32, b: usize) void{ _ = a; _ = b; }
     ,
-        \\zig_extern void start(zig_u32 const a0, zig_usize const a1);
+        \\zig_extern void start(uint32_t const a0, uintptr_t const a1);
         \\
     );
 }