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(...@@ -2770,8 +2770,8 @@ fn zirStructDecl(
2770 // InternPool index.2770 // InternPool index.
27712771
2772 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{2772 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2773 .ty = Type.type,2773 .ty = Type.noreturn,
2774 .val = undefined,2774 .val = Value.@"unreachable",
2775 }, small.name_strategy, "struct", inst);2775 }, small.name_strategy, "struct", inst);
2776 const new_decl = mod.declPtr(new_decl_index);2776 const new_decl = mod.declPtr(new_decl_index);
2777 new_decl.owns_tv = true;2777 new_decl.owns_tv = true;
...@@ -2804,6 +2804,7 @@ fn zirStructDecl(...@@ -2804,6 +2804,7 @@ fn zirStructDecl(
2804 // TODO: figure out InternPool removals for incremental compilation2804 // TODO: figure out InternPool removals for incremental compilation
2805 //errdefer mod.intern_pool.remove(struct_ty);2805 //errdefer mod.intern_pool.remove(struct_ty);
28062806
2807 new_decl.ty = Type.type;
2807 new_decl.val = struct_ty.toValue();2808 new_decl.val = struct_ty.toValue();
2808 new_namespace.ty = struct_ty.toType();2809 new_namespace.ty = struct_ty.toType();
28092810
...@@ -2973,8 +2974,8 @@ fn zirEnumDecl(...@@ -2973,8 +2974,8 @@ fn zirEnumDecl(
29732974
2974 var done = false;2975 var done = false;
2975 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{2976 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2976 .ty = Type.type,2977 .ty = Type.noreturn,
2977 .val = undefined,2978 .val = Value.@"unreachable",
2978 }, small.name_strategy, "enum", inst);2979 }, small.name_strategy, "enum", inst);
2979 const new_decl = mod.declPtr(new_decl_index);2980 const new_decl = mod.declPtr(new_decl_index);
2980 new_decl.owns_tv = true;2981 new_decl.owns_tv = true;
...@@ -3016,6 +3017,7 @@ fn zirEnumDecl(...@@ -3016,6 +3017,7 @@ fn zirEnumDecl(
3016 // TODO: figure out InternPool removals for incremental compilation3017 // TODO: figure out InternPool removals for incremental compilation
3017 //errdefer if (!done) mod.intern_pool.remove(incomplete_enum.index);3018 //errdefer if (!done) mod.intern_pool.remove(incomplete_enum.index);
30183019
3020 new_decl.ty = Type.type;
3019 new_decl.val = incomplete_enum.index.toValue();3021 new_decl.val = incomplete_enum.index.toValue();
3020 new_namespace.ty = incomplete_enum.index.toType();3022 new_namespace.ty = incomplete_enum.index.toType();
30213023
...@@ -3232,8 +3234,8 @@ fn zirUnionDecl(...@@ -3232,8 +3234,8 @@ fn zirUnionDecl(
3232 // InternPool index.3234 // InternPool index.
32333235
3234 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{3236 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
3235 .ty = Type.type,3237 .ty = Type.noreturn,
3236 .val = undefined,3238 .val = Value.@"unreachable",
3237 }, small.name_strategy, "union", inst);3239 }, small.name_strategy, "union", inst);
3238 const new_decl = mod.declPtr(new_decl_index);3240 const new_decl = mod.declPtr(new_decl_index);
3239 new_decl.owns_tv = true;3241 new_decl.owns_tv = true;
...@@ -3272,6 +3274,7 @@ fn zirUnionDecl(...@@ -3272,6 +3274,7 @@ fn zirUnionDecl(
3272 // TODO: figure out InternPool removals for incremental compilation3274 // TODO: figure out InternPool removals for incremental compilation
3273 //errdefer mod.intern_pool.remove(union_ty);3275 //errdefer mod.intern_pool.remove(union_ty);
32743276
3277 new_decl.ty = Type.type;
3275 new_decl.val = union_ty.toValue();3278 new_decl.val = union_ty.toValue();
3276 new_namespace.ty = union_ty.toType();3279 new_namespace.ty = union_ty.toType();
32773280
...@@ -3312,8 +3315,8 @@ fn zirOpaqueDecl(...@@ -3312,8 +3315,8 @@ fn zirOpaqueDecl(
3312 // type gains an InternPool index.3315 // type gains an InternPool index.
33133316
3314 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{3317 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
3315 .ty = Type.type,3318 .ty = Type.noreturn,
3316 .val = undefined,3319 .val = Value.@"unreachable",
3317 }, small.name_strategy, "opaque", inst);3320 }, small.name_strategy, "opaque", inst);
3318 const new_decl = mod.declPtr(new_decl_index);3321 const new_decl = mod.declPtr(new_decl_index);
3319 new_decl.owns_tv = true;3322 new_decl.owns_tv = true;
...@@ -3334,6 +3337,7 @@ fn zirOpaqueDecl(...@@ -3334,6 +3337,7 @@ fn zirOpaqueDecl(
3334 // TODO: figure out InternPool removals for incremental compilation3337 // TODO: figure out InternPool removals for incremental compilation
3335 //errdefer mod.intern_pool.remove(opaque_ty);3338 //errdefer mod.intern_pool.remove(opaque_ty);
33363339
3340 new_decl.ty = Type.type;
3337 new_decl.val = opaque_ty.toValue();3341 new_decl.val = opaque_ty.toValue();
3338 new_namespace.ty = opaque_ty.toType();3342 new_namespace.ty = opaque_ty.toType();
33393343
...@@ -19433,8 +19437,8 @@ fn zirReify(...@@ -19433,8 +19437,8 @@ fn zirReify(
19433 // an InternPool index.19437 // an InternPool index.
1943419438
19435 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{19439 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19436 .ty = Type.type,19440 .ty = Type.noreturn,
19437 .val = undefined,19441 .val = Value.@"unreachable",
19438 }, name_strategy, "enum", inst);19442 }, name_strategy, "enum", inst);
19439 const new_decl = mod.declPtr(new_decl_index);19443 const new_decl = mod.declPtr(new_decl_index);
19440 new_decl.owns_tv = true;19444 new_decl.owns_tv = true;
...@@ -19459,6 +19463,7 @@ fn zirReify(...@@ -19459,6 +19463,7 @@ fn zirReify(
19459 // TODO: figure out InternPool removals for incremental compilation19463 // TODO: figure out InternPool removals for incremental compilation
19460 //errdefer ip.remove(incomplete_enum.index);19464 //errdefer ip.remove(incomplete_enum.index);
1946119465
19466 new_decl.ty = Type.type;
19462 new_decl.val = incomplete_enum.index.toValue();19467 new_decl.val = incomplete_enum.index.toValue();
1946319468
19464 for (0..fields_len) |field_i| {19469 for (0..fields_len) |field_i| {
...@@ -19527,8 +19532,8 @@ fn zirReify(...@@ -19527,8 +19532,8 @@ fn zirReify(
19527 // after the opaque type gains an InternPool index.19532 // after the opaque type gains an InternPool index.
1952819533
19529 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{19534 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19530 .ty = Type.type,19535 .ty = Type.noreturn,
19531 .val = undefined,19536 .val = Value.@"unreachable",
19532 }, name_strategy, "opaque", inst);19537 }, name_strategy, "opaque", inst);
19533 const new_decl = mod.declPtr(new_decl_index);19538 const new_decl = mod.declPtr(new_decl_index);
19534 new_decl.owns_tv = true;19539 new_decl.owns_tv = true;
...@@ -19552,6 +19557,7 @@ fn zirReify(...@@ -19552,6 +19557,7 @@ fn zirReify(
19552 // TODO: figure out InternPool removals for incremental compilation19557 // TODO: figure out InternPool removals for incremental compilation
19553 //errdefer ip.remove(opaque_ty);19558 //errdefer ip.remove(opaque_ty);
1955419559
19560 new_decl.ty = Type.type;
19555 new_decl.val = opaque_ty.toValue();19561 new_decl.val = opaque_ty.toValue();
19556 new_namespace.ty = opaque_ty.toType();19562 new_namespace.ty = opaque_ty.toType();
1955719563
...@@ -19585,8 +19591,8 @@ fn zirReify(...@@ -19585,8 +19591,8 @@ fn zirReify(
19585 // InternPool index.19591 // InternPool index.
1958619592
19587 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{19593 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19588 .ty = Type.type,19594 .ty = Type.noreturn,
19589 .val = undefined,19595 .val = Value.@"unreachable",
19590 }, name_strategy, "union", inst);19596 }, name_strategy, "union", inst);
19591 const new_decl = mod.declPtr(new_decl_index);19597 const new_decl = mod.declPtr(new_decl_index);
19592 new_decl.owns_tv = true;19598 new_decl.owns_tv = true;
...@@ -19629,6 +19635,7 @@ fn zirReify(...@@ -19629,6 +19635,7 @@ fn zirReify(
19629 // TODO: figure out InternPool removals for incremental compilation19635 // TODO: figure out InternPool removals for incremental compilation
19630 //errdefer ip.remove(union_ty);19636 //errdefer ip.remove(union_ty);
1963119637
19638 new_decl.ty = Type.type;
19632 new_decl.val = union_ty.toValue();19639 new_decl.val = union_ty.toValue();
19633 new_namespace.ty = union_ty.toType();19640 new_namespace.ty = union_ty.toType();
1963419641
...@@ -19886,8 +19893,8 @@ fn reifyStruct(...@@ -19886,8 +19893,8 @@ fn reifyStruct(
19886 // InternPool index.19893 // InternPool index.
1988719894
19888 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{19895 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
19889 .ty = Type.type,19896 .ty = Type.noreturn,
19890 .val = undefined,19897 .val = Value.@"unreachable",
19891 }, name_strategy, "struct", inst);19898 }, name_strategy, "struct", inst);
19892 const new_decl = mod.declPtr(new_decl_index);19899 const new_decl = mod.declPtr(new_decl_index);
19893 new_decl.owns_tv = true;19900 new_decl.owns_tv = true;
...@@ -19924,6 +19931,7 @@ fn reifyStruct(...@@ -19924,6 +19931,7 @@ fn reifyStruct(
19924 // TODO: figure out InternPool removals for incremental compilation19931 // TODO: figure out InternPool removals for incremental compilation
19925 //errdefer ip.remove(struct_ty);19932 //errdefer ip.remove(struct_ty);
1992619933
19934 new_decl.ty = Type.type;
19927 new_decl.val = struct_ty.toValue();19935 new_decl.val = struct_ty.toValue();
19928 new_namespace.ty = struct_ty.toType();19936 new_namespace.ty = struct_ty.toType();
1992919937
...@@ -33441,8 +33449,8 @@ fn generateUnionTagTypeNumbered(...@@ -33441,8 +33449,8 @@ fn generateUnionTagTypeNumbered(
33441 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);33449 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);
33442 };33450 };
33443 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{33451 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
33444 .ty = Type.type,33452 .ty = Type.noreturn,
33445 .val = undefined,33453 .val = Value.@"unreachable",
33446 }, name);33454 }, name);
33447 errdefer mod.abortAnonDecl(new_decl_index);33455 errdefer mod.abortAnonDecl(new_decl_index);
3344833456
...@@ -33463,6 +33471,7 @@ fn generateUnionTagTypeNumbered(...@@ -33463,6 +33471,7 @@ fn generateUnionTagTypeNumbered(
33463 .tag_mode = .explicit,33471 .tag_mode = .explicit,
33464 } });33472 } });
3346533473
33474 new_decl.ty = Type.type;
33466 new_decl.val = enum_ty.toValue();33475 new_decl.val = enum_ty.toValue();
3346733476
33468 try mod.finalizeAnonDecl(new_decl_index);33477 try mod.finalizeAnonDecl(new_decl_index);
...@@ -33482,8 +33491,8 @@ fn generateUnionTagTypeSimple(...@@ -33482,8 +33491,8 @@ fn generateUnionTagTypeSimple(
33482 const new_decl_index = new_decl_index: {33491 const new_decl_index = new_decl_index: {
33483 const union_obj = maybe_union_obj orelse {33492 const union_obj = maybe_union_obj orelse {
33484 break :new_decl_index try mod.createAnonymousDecl(block, .{33493 break :new_decl_index try mod.createAnonymousDecl(block, .{
33485 .ty = Type.type,33494 .ty = Type.noreturn,
33486 .val = undefined,33495 .val = Value.@"unreachable",
33487 });33496 });
33488 };33497 };
33489 const src_decl = mod.declPtr(block.src_decl);33498 const src_decl = mod.declPtr(block.src_decl);
...@@ -33501,8 +33510,8 @@ fn generateUnionTagTypeSimple(...@@ -33501,8 +33510,8 @@ fn generateUnionTagTypeSimple(
33501 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);33510 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);
33502 };33511 };
33503 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{33512 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
33504 .ty = Type.type,33513 .ty = Type.noreturn,
33505 .val = undefined,33514 .val = Value.@"unreachable",
33506 }, name);33515 }, name);
33507 mod.declPtr(new_decl_index).name_fully_qualified = true;33516 mod.declPtr(new_decl_index).name_fully_qualified = true;
33508 break :new_decl_index new_decl_index;33517 break :new_decl_index new_decl_index;
...@@ -33523,6 +33532,7 @@ fn generateUnionTagTypeSimple(...@@ -33523,6 +33532,7 @@ fn generateUnionTagTypeSimple(
3352333532
33524 const new_decl = mod.declPtr(new_decl_index);33533 const new_decl = mod.declPtr(new_decl_index);
33525 new_decl.owns_tv = true;33534 new_decl.owns_tv = true;
33535 new_decl.ty = Type.type;
33526 new_decl.val = enum_ty.toValue();33536 new_decl.val = enum_ty.toValue();
3352733537
33528 try mod.finalizeAnonDecl(new_decl_index);33538 try mod.finalizeAnonDecl(new_decl_index);