authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-25 21:23:35-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-25 21:23:35-05:00
logdad62a7e27fb7e8ea1eb51d6619fd534106417f1
treee13adf5b92f39b686f96dfcf1f788405f1c261d1
parente9bac8be6b45434f107d2a0d8d4f8fd16de185c6
signaturelock-open Commit is signed but in an unrecognized format.

Revert "ir: Fix sizeOf comparison with ptr to zst"

This reverts commit 89812217b4e5fee7e2851266c17c9d47204a1573. This caused #4560

2 files changed, 5 insertions(+), 34 deletions(-)

src/analyze.cpp+3-2
...@@ -1132,9 +1132,10 @@ Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent...@@ -1132,9 +1132,10 @@ Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent
1132 if (type_val->special != ConstValSpecialLazy) {1132 if (type_val->special != ConstValSpecialLazy) {
1133 assert(type_val->special == ConstValSpecialStatic);1133 assert(type_val->special == ConstValSpecialStatic);
1134 if ((type_val->data.x_type->id == ZigTypeIdStruct &&1134 if ((type_val->data.x_type->id == ZigTypeIdStruct &&
1135 type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||1135 type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
1136 (type_val->data.x_type->id == ZigTypeIdUnion &&1136 (type_val->data.x_type->id == ZigTypeIdUnion &&
1137 type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits))1137 type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits) ||
1138 type_val->data.x_type->id == ZigTypeIdPointer)
1138 {1139 {
1139 // Does a struct/union which contains a pointer field to itself have bits? Yes.1140 // Does a struct/union which contains a pointer field to itself have bits? Yes.
1140 *is_zero_bits = false;1141 *is_zero_bits = false;
test/stage1/behavior/sizeof_and_typeof.zig+2-32
...@@ -1,7 +1,5 @@...@@ -1,7 +1,5 @@
1const std = @import("std");1const builtin = @import("builtin");
2const builtin = std.builtin;2const expect = @import("std").testing.expect;
3const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;
53
6test "@sizeOf and @TypeOf" {4test "@sizeOf and @TypeOf" {
7 const y: @TypeOf(x) = 120;5 const y: @TypeOf(x) = 120;
...@@ -137,31 +135,3 @@ test "@bitSizeOf" {...@@ -137,31 +135,3 @@ test "@bitSizeOf" {
137 a: u2135 a: u2
138 }) == 2);136 }) == 2);
139}137}
140
141test "@sizeOf comparison against zero" {
142 const S0 = struct {
143 f: *@This(),
144 };
145 const U0 = union {
146 f: *@This(),
147 };
148 const S = struct {
149 fn doTheTest(comptime T: type, comptime result: bool) void {
150 expectEqual(result, @sizeOf(T) > 0);
151 }
152 };
153 // Zero-sized type
154 S.doTheTest(u0, false);
155 S.doTheTest(*u0, false);
156 // Non byte-sized type
157 S.doTheTest(u1, true);
158 S.doTheTest(*u1, true);
159 // Regular type
160 S.doTheTest(u8, true);
161 S.doTheTest(*u8, true);
162 S.doTheTest(f32, true);
163 S.doTheTest(*f32, true);
164 // Container with ptr pointing to themselves
165 S.doTheTest(S0, true);
166 S.doTheTest(U0, true);
167}