| author | |
| committer | |
| log | 7b8c5578c6c174893c5dd08e89cf3b3492ae065f |
| tree | a609d434b88129b347e016b407382a2456138ea7 |
| parent | 33cbb29def181ee758b1f8bb93d8d81a4e377ce1 |
| signature |
closes #20065 files changed, 36 insertions(+), 10 deletions(-)
src/all_types.hpp+11-3| ... | ... | @@ -1240,6 +1240,12 @@ enum ZigTypeId { |
| 1240 | 1240 | ZigTypeIdVector, |
| 1241 | 1241 | }; |
| 1242 | 1242 | |
| 1243 | enum OnePossibleValue { | |
| 1244 | OnePossibleValueInvalid, | |
| 1245 | OnePossibleValueNo, | |
| 1246 | OnePossibleValueYes, | |
| 1247 | }; | |
| 1248 | ||
| 1243 | 1249 | struct ZigType { |
| 1244 | 1250 | ZigTypeId id; |
| 1245 | 1251 | Buf name; |
| ... | ... | @@ -1247,9 +1253,6 @@ struct ZigType { |
| 1247 | 1253 | LLVMTypeRef type_ref; |
| 1248 | 1254 | ZigLLVMDIType *di_type; |
| 1249 | 1255 | |
| 1250 | bool zero_bits; // this is denormalized data | |
| 1251 | bool gen_h_loop_flag; | |
| 1252 | ||
| 1253 | 1256 | union { |
| 1254 | 1257 | ZigTypePointer pointer; |
| 1255 | 1258 | ZigTypeInt integral; |
| ... | ... | @@ -1275,6 +1278,11 @@ struct ZigType { |
| 1275 | 1278 | // If we generate a constant name value for this type, we memoize it here. |
| 1276 | 1279 | // The type of this is array |
| 1277 | 1280 | ConstExprValue *cached_const_name_val; |
| 1281 | ||
| 1282 | OnePossibleValue one_possible_value; | |
| 1283 | ||
| 1284 | bool zero_bits; // this is denormalized data | |
| 1285 | bool gen_h_loop_flag; | |
| 1278 | 1286 | }; |
| 1279 | 1287 | |
| 1280 | 1288 | struct PackageTableEntry { |
src/analyze.cpp+12-2| ... | ... | @@ -5129,6 +5129,10 @@ bool type_has_bits(ZigType *type_entry) { |
| 5129 | 5129 | // Whether you can infer the value based solely on the type. |
| 5130 | 5130 | OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { |
| 5131 | 5131 | assert(type_entry != nullptr); |
| 5132 | ||
| 5133 | if (type_entry->one_possible_value != OnePossibleValueInvalid) | |
| 5134 | return type_entry->one_possible_value; | |
| 5135 | ||
| 5132 | 5136 | Error err; |
| 5133 | 5137 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) |
| 5134 | 5138 | return OnePossibleValueInvalid; |
| ... | ... | @@ -5176,8 +5180,14 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { |
| 5176 | 5180 | case ZigTypeIdInt: |
| 5177 | 5181 | case ZigTypeIdVector: |
| 5178 | 5182 | return type_has_bits(type_entry) ? OnePossibleValueNo : OnePossibleValueYes; |
| 5179 | case ZigTypeIdPointer: | |
| 5180 | return type_has_one_possible_value(g, type_entry->data.pointer.child_type); | |
| 5183 | case ZigTypeIdPointer: { | |
| 5184 | ZigType *elem_type = type_entry->data.pointer.child_type; | |
| 5185 | // If the recursive function call asks, then we are not one possible value. | |
| 5186 | type_entry->one_possible_value = OnePossibleValueNo; | |
| 5187 | // Now update it to be the value of the recursive call. | |
| 5188 | type_entry->one_possible_value = type_has_one_possible_value(g, elem_type); | |
| 5189 | return type_entry->one_possible_value; | |
| 5190 | } | |
| 5181 | 5191 | case ZigTypeIdUnion: |
| 5182 | 5192 | if (type_entry->data.unionation.src_field_count > 1) |
| 5183 | 5193 | return OnePossibleValueNo; |
src/analyze.hpp-5| ... | ... | @@ -226,11 +226,6 @@ enum ReqCompTime { |
| 226 | 226 | }; |
| 227 | 227 | ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry); |
| 228 | 228 | |
| 229 | enum OnePossibleValue { | |
| 230 | OnePossibleValueInvalid, | |
| 231 | OnePossibleValueNo, | |
| 232 | OnePossibleValueYes, | |
| 233 | }; | |
| 234 | 229 | OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry); |
| 235 | 230 | |
| 236 | 231 | Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
test/stage1/behavior.zig+1| ... | ... | @@ -19,6 +19,7 @@ comptime { |
| 19 | 19 | _ = @import("behavior/bugs/1442.zig"); |
| 20 | 20 | _ = @import("behavior/bugs/1486.zig"); |
| 21 | 21 | _ = @import("behavior/bugs/1851.zig"); |
| 22 | _ = @import("behavior/bugs/2006.zig"); | |
| 22 | 23 | _ = @import("behavior/bugs/394.zig"); |
| 23 | 24 | _ = @import("behavior/bugs/421.zig"); |
| 24 | 25 | _ = @import("behavior/bugs/655.zig"); |
test/stage1/behavior/bugs/2006.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | ||
| 4 | const S = struct { | |
| 5 | p: *S, | |
| 6 | }; | |
| 7 | test "bug 2006" { | |
| 8 | var a: S = undefined; | |
| 9 | a = S{ .p = undefined }; | |
| 10 | expect(@sizeOf(S) != 0); | |
| 11 | expect(@sizeOf(*void) == 0); | |
| 12 | } |