aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2022-12-18 22:09:13 -0500
committerJacob Young <jacobly0@users.noreply.github.com>2022-12-18 22:11:26 -0500
commit0e3feebb042a538405153e4bc75a3bb73ee2e63c (patch)
treed597c19b71254dacb25c7744b03eb5c37d9ee516 /src/codegen/c.zig
parent52e5c6602550788cab96957d1a177bc7952d7a09 (diff)
downloadzig-0e3feebb042a538405153e4bc75a3bb73ee2e63c.tar.gz
zig-0e3feebb042a538405153e4bc75a3bb73ee2e63c.zip
codegen: fix taking the address of a zero-bit field in a zero-bit struct
Normally when we want a pointer to the end of a struct we just add 1 to the struct pointer. However, when it is a zero-bit struct, the pointer type being used during lowering is often a dummy pointer type that actually points to a non-zero-bit type, so we actually want to add 0 instead, since a zero-bit struct begins and ends at the same address.
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index a7a2b2cf2a..9488fa420b 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -5131,7 +5131,9 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc
.begin, .end => {
try writer.writeByte('(');
try f.writeCValue(writer, struct_ptr, .Other);
- try writer.print(")[{}]", .{@boolToInt(field_loc == .end)});
+ try writer.print(")[{}]", .{
+ @boolToInt(field_loc == .end and struct_ty.hasRuntimeBitsIgnoreComptime()),
+ });
},
.field => |field| if (extra_name != .none) {
try f.writeCValueDerefMember(writer, struct_ptr, extra_name);