authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-04 10:02:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:51:10-07:00
logdce80f67d4ab9a9387be595c0275853369ffb7e4
treeaa6188a6c237919903d7ce6ae2a791c33db48312
parent7702af5eb2d986d46b6978dafcf4b174313167e4

Sema: fix crashes accessing undefined values


1 files changed, 32 insertions(+), 22 deletions(-)

src/Sema.zig+32-22
......@@ -2770,8 +2770,8 @@ fn zirStructDecl(
27702770 // InternPool index.
27712771
27722772 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2773 .ty = Type.type,
2774 .val = undefined,
2773 .ty = Type.noreturn,
2774 .val = Value.@"unreachable",
27752775 }, small.name_strategy, "struct", inst);
27762776 const new_decl = mod.declPtr(new_decl_index);
27772777 new_decl.owns_tv = true;
......@@ -2804,6 +2804,7 @@ fn zirStructDecl(
28042804 // TODO: figure out InternPool removals for incremental compilation
28052805 //errdefer mod.intern_pool.remove(struct_ty);
28062806
2807 new_decl.ty = Type.type;
28072808 new_decl.val = struct_ty.toValue();
28082809 new_namespace.ty = struct_ty.toType();
28092810
......@@ -2973,8 +2974,8 @@ fn zirEnumDecl(
29732974
29742975 var done = false;
29752976 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2976 .ty = Type.type,
2977 .val = undefined,
2977 .ty = Type.noreturn,
2978 .val = Value.@"unreachable",
29782979 }, small.name_strategy, "enum", inst);
29792980 const new_decl = mod.declPtr(new_decl_index);
29802981 new_decl.owns_tv = true;
......@@ -3016,6 +3017,7 @@ fn zirEnumDecl(
30163017 // TODO: figure out InternPool removals for incremental compilation
30173018 //errdefer if (!done) mod.intern_pool.remove(incomplete_enum.index);
30183019
3020 new_decl.ty = Type.type;
30193021 new_decl.val = incomplete_enum.index.toValue();
30203022 new_namespace.ty = incomplete_enum.index.toType();
30213023
......@@ -3232,8 +3234,8 @@ fn zirUnionDecl(
32323234 // InternPool index.
32333235
32343236 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
3235 .ty = Type.type,
3236 .val = undefined,
3237 .ty = Type.noreturn,
3238 .val = Value.@"unreachable",
32373239 }, small.name_strategy, "union", inst);
32383240 const new_decl = mod.declPtr(new_decl_index);
32393241 new_decl.owns_tv = true;
......@@ -3272,6 +3274,7 @@ fn zirUnionDecl(
32723274 // TODO: figure out InternPool removals for incremental compilation
32733275 //errdefer mod.intern_pool.remove(union_ty);
32743276
3277 new_decl.ty = Type.type;
32753278 new_decl.val = union_ty.toValue();
32763279 new_namespace.ty = union_ty.toType();
32773280
......@@ -3312,8 +3315,8 @@ fn zirOpaqueDecl(
33123315 // type gains an InternPool index.
33133316
33143317 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
3315 .ty = Type.type,
3316 .val = undefined,
3318 .ty = Type.noreturn,
3319 .val = Value.@"unreachable",
33173320 }, small.name_strategy, "opaque", inst);
33183321 const new_decl = mod.declPtr(new_decl_index);
33193322 new_decl.owns_tv = true;
......@@ -3334,6 +3337,7 @@ fn zirOpaqueDecl(
33343337 // TODO: figure out InternPool removals for incremental compilation
33353338 //errdefer mod.intern_pool.remove(opaque_ty);
33363339
3340 new_decl.ty = Type.type;
33373341 new_decl.val = opaque_ty.toValue();
33383342 new_namespace.ty = opaque_ty.toType();
33393343
......@@ -19433,8 +19437,8 @@ fn zirReify(
1943319437 // an InternPool index.
1943419438
1943519439 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19436 .ty = Type.type,
19437 .val = undefined,
19440 .ty = Type.noreturn,
19441 .val = Value.@"unreachable",
1943819442 }, name_strategy, "enum", inst);
1943919443 const new_decl = mod.declPtr(new_decl_index);
1944019444 new_decl.owns_tv = true;
......@@ -19459,6 +19463,7 @@ fn zirReify(
1945919463 // TODO: figure out InternPool removals for incremental compilation
1946019464 //errdefer ip.remove(incomplete_enum.index);
1946119465
19466 new_decl.ty = Type.type;
1946219467 new_decl.val = incomplete_enum.index.toValue();
1946319468
1946419469 for (0..fields_len) |field_i| {
......@@ -19527,8 +19532,8 @@ fn zirReify(
1952719532 // after the opaque type gains an InternPool index.
1952819533
1952919534 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19530 .ty = Type.type,
19531 .val = undefined,
19535 .ty = Type.noreturn,
19536 .val = Value.@"unreachable",
1953219537 }, name_strategy, "opaque", inst);
1953319538 const new_decl = mod.declPtr(new_decl_index);
1953419539 new_decl.owns_tv = true;
......@@ -19552,6 +19557,7 @@ fn zirReify(
1955219557 // TODO: figure out InternPool removals for incremental compilation
1955319558 //errdefer ip.remove(opaque_ty);
1955419559
19560 new_decl.ty = Type.type;
1955519561 new_decl.val = opaque_ty.toValue();
1955619562 new_namespace.ty = opaque_ty.toType();
1955719563
......@@ -19585,8 +19591,8 @@ fn zirReify(
1958519591 // InternPool index.
1958619592
1958719593 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19588 .ty = Type.type,
19589 .val = undefined,
19594 .ty = Type.noreturn,
19595 .val = Value.@"unreachable",
1959019596 }, name_strategy, "union", inst);
1959119597 const new_decl = mod.declPtr(new_decl_index);
1959219598 new_decl.owns_tv = true;
......@@ -19629,6 +19635,7 @@ fn zirReify(
1962919635 // TODO: figure out InternPool removals for incremental compilation
1963019636 //errdefer ip.remove(union_ty);
1963119637
19638 new_decl.ty = Type.type;
1963219639 new_decl.val = union_ty.toValue();
1963319640 new_namespace.ty = union_ty.toType();
1963419641
......@@ -19886,8 +19893,8 @@ fn reifyStruct(
1988619893 // InternPool index.
1988719894
1988819895 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19889 .ty = Type.type,
19890 .val = undefined,
19896 .ty = Type.noreturn,
19897 .val = Value.@"unreachable",
1989119898 }, name_strategy, "struct", inst);
1989219899 const new_decl = mod.declPtr(new_decl_index);
1989319900 new_decl.owns_tv = true;
......@@ -19924,6 +19931,7 @@ fn reifyStruct(
1992419931 // TODO: figure out InternPool removals for incremental compilation
1992519932 //errdefer ip.remove(struct_ty);
1992619933
19934 new_decl.ty = Type.type;
1992719935 new_decl.val = struct_ty.toValue();
1992819936 new_namespace.ty = struct_ty.toType();
1992919937
......@@ -33441,8 +33449,8 @@ fn generateUnionTagTypeNumbered(
3344133449 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);
3344233450 };
3344333451 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
33444 .ty = Type.type,
33445 .val = undefined,
33452 .ty = Type.noreturn,
33453 .val = Value.@"unreachable",
3344633454 }, name);
3344733455 errdefer mod.abortAnonDecl(new_decl_index);
3344833456
......@@ -33463,6 +33471,7 @@ fn generateUnionTagTypeNumbered(
3346333471 .tag_mode = .explicit,
3346433472 } });
3346533473
33474 new_decl.ty = Type.type;
3346633475 new_decl.val = enum_ty.toValue();
3346733476
3346833477 try mod.finalizeAnonDecl(new_decl_index);
......@@ -33482,8 +33491,8 @@ fn generateUnionTagTypeSimple(
3348233491 const new_decl_index = new_decl_index: {
3348333492 const union_obj = maybe_union_obj orelse {
3348433493 break :new_decl_index try mod.createAnonymousDecl(block, .{
33485 .ty = Type.type,
33486 .val = undefined,
33494 .ty = Type.noreturn,
33495 .val = Value.@"unreachable",
3348733496 });
3348833497 };
3348933498 const src_decl = mod.declPtr(block.src_decl);
......@@ -33501,8 +33510,8 @@ fn generateUnionTagTypeSimple(
3350133510 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);
3350233511 };
3350333512 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
33504 .ty = Type.type,
33505 .val = undefined,
33513 .ty = Type.noreturn,
33514 .val = Value.@"unreachable",
3350633515 }, name);
3350733516 mod.declPtr(new_decl_index).name_fully_qualified = true;
3350833517 break :new_decl_index new_decl_index;
......@@ -33523,6 +33532,7 @@ fn generateUnionTagTypeSimple(
3352333532
3352433533 const new_decl = mod.declPtr(new_decl_index);
3352533534 new_decl.owns_tv = true;
33535 new_decl.ty = Type.type;
3352633536 new_decl.val = enum_ty.toValue();
3352733537
3352833538 try mod.finalizeAnonDecl(new_decl_index);