| author | |
| committer | |
| log | dad62a7e27fb7e8ea1eb51d6619fd534106417f1 |
| tree | e13adf5b92f39b686f96dfcf1f788405f1c261d1 |
| parent | e9bac8be6b45434f107d2a0d8d4f8fd16de185c6 |
| signature |
This reverts commit 89812217b4e5fee7e2851266c17c9d47204a1573.
This caused #45602 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 @@ |
| 1 | const std = @import("std"); | 1 | const builtin = @import("builtin"); |
| 2 | const builtin = std.builtin; | 2 | const expect = @import("std").testing.expect; |
| 3 | const expect = std.testing.expect; | ||
| 4 | const expectEqual = std.testing.expectEqual; | ||
| 5 | 3 | ||
| 6 | test "@sizeOf and @TypeOf" { | 4 | test "@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: u2 | 135 | a: u2 |
| 138 | }) == 2); | 136 | }) == 2); |
| 139 | } | 137 | } |
| 140 | |||
| 141 | test "@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 | } |