Commit dad62a7e27

Andrew Kelley <andrew@ziglang.org>
2020-02-26 03:23:35
Revert "ir: Fix sizeOf comparison with ptr to zst"
This reverts commit 89812217b4e5fee7e2851266c17c9d47204a1573. This caused #4560
1 parent e9bac8b
Changed files (2)
src
test
stage1
src/analyze.cpp
@@ -1132,9 +1132,10 @@ Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent
     if (type_val->special != ConstValSpecialLazy) {
         assert(type_val->special == ConstValSpecialStatic);
         if ((type_val->data.x_type->id == ZigTypeIdStruct &&
-             type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
+            type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
             (type_val->data.x_type->id == ZigTypeIdUnion &&
-             type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits))
+             type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits) ||
+            type_val->data.x_type->id == ZigTypeIdPointer)
         {
             // Does a struct/union which contains a pointer field to itself have bits? Yes.
             *is_zero_bits = false;
test/stage1/behavior/sizeof_and_typeof.zig
@@ -1,7 +1,5 @@
-const std = @import("std");
-const builtin = std.builtin;
-const expect = std.testing.expect;
-const expectEqual = std.testing.expectEqual;
+const builtin = @import("builtin");
+const expect = @import("std").testing.expect;
 
 test "@sizeOf and @TypeOf" {
     const y: @TypeOf(x) = 120;
@@ -137,31 +135,3 @@ test "@bitSizeOf" {
         a: u2
     }) == 2);
 }
-
-test "@sizeOf comparison against zero" {
-    const S0 = struct {
-        f: *@This(),
-    };
-    const U0 = union {
-        f: *@This(),
-    };
-    const S = struct {
-        fn doTheTest(comptime T: type, comptime result: bool) void {
-            expectEqual(result, @sizeOf(T) > 0);
-        }
-    };
-    // Zero-sized type
-    S.doTheTest(u0, false);
-    S.doTheTest(*u0, false);
-    // Non byte-sized type
-    S.doTheTest(u1, true);
-    S.doTheTest(*u1, true);
-    // Regular type
-    S.doTheTest(u8, true);
-    S.doTheTest(*u8, true);
-    S.doTheTest(f32, true);
-    S.doTheTest(*f32, true);
-    // Container with ptr pointing to themselves
-    S.doTheTest(S0, true);
-    S.doTheTest(U0, true);
-}