From f0dcdd7931f1eb4f3b6a0a87c914baf770f6df03 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 22 Oct 2021 15:53:59 -0700 Subject: [PATCH] stage2: fix Decl addrspace being undefined --- src/Module.zig | 11 ++++++++--- test/behavior/basic.zig | 13 +++++++++++++ test/behavior/misc.zig | 12 ------------ test/behavior/saturating_arithmetic.zig | 4 ++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Module.zig b/src/Module.zig index 8677be224f..3ac523bdc5 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4220,7 +4220,13 @@ fn markOutdatedDecl(mod: *Module, decl: *Decl) !void { decl.analysis = .outdated; } -pub fn allocateNewDecl(mod: *Module, name: [:0]const u8, namespace: *Namespace, src_node: Ast.Node.Index, src_scope: ?*CaptureScope) !*Decl { +pub fn allocateNewDecl( + mod: *Module, + name: [:0]const u8, + namespace: *Namespace, + src_node: Ast.Node.Index, + src_scope: ?*CaptureScope, +) !*Decl { // If we have emit-h then we must allocate a bigger structure to store the emit-h state. const new_decl: *Decl = if (mod.emit_h != null) blk: { const parent_struct = try mod.gpa.create(DeclPlusEmitH); @@ -4242,7 +4248,7 @@ pub fn allocateNewDecl(mod: *Module, name: [:0]const u8, namespace: *Namespace, .val = undefined, .align_val = undefined, .linksection_val = undefined, - .@"addrspace" = undefined, + .@"addrspace" = .generic, .analysis = .unreferenced, .deletion_flag = false, .zir_decl_index = 0, @@ -4346,7 +4352,6 @@ pub fn createAnonymousDeclFromDeclNamed( new_decl.val = typed_value.val; new_decl.align_val = Value.initTag(.null_value); new_decl.linksection_val = Value.initTag(.null_value); - new_decl.@"addrspace" = .generic; // default global addrspace new_decl.has_tv = true; new_decl.analysis = .complete; new_decl.generation = mod.generation; diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index ae4cb26354..f3d511916f 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -2,6 +2,7 @@ const std = @import("std"); const builtin = @import("builtin"); const mem = std.mem; const expect = std.testing.expect; +const expectEqualStrings = std.testing.expectEqualStrings; // normal comment @@ -446,3 +447,15 @@ test "self reference through fn ptr field" { a.f = S.foo; try expect(a.f(a) == 12); } + +test "global variable initialized to global variable array element" { + try expect(global_ptr == &gdt[0]); +} +const GDTEntry = struct { + field: i32, +}; +var gdt = [_]GDTEntry{ + GDTEntry{ .field = 1 }, + GDTEntry{ .field = 2 }, +}; +var global_ptr = &gdt[0]; diff --git a/test/behavior/misc.zig b/test/behavior/misc.zig index 83414f49b2..7a248ed320 100644 --- a/test/behavior/misc.zig +++ b/test/behavior/misc.zig @@ -100,18 +100,6 @@ test "string concatenation" { try expect(b[len] == 0); } -test "global variable initialized to global variable array element" { - try expect(global_ptr == &gdt[0]); -} -const GDTEntry = struct { - field: i32, -}; -var gdt = [_]GDTEntry{ - GDTEntry{ .field = 1 }, - GDTEntry{ .field = 2 }, -}; -var global_ptr = &gdt[0]; - // can't really run this test but we can make sure it has no compile error // and generates code const vram = @intToPtr([*]volatile u8, 0x20000000)[0..0x8000]; diff --git a/test/behavior/saturating_arithmetic.zig b/test/behavior/saturating_arithmetic.zig index 7749dc9559..c0f29892a1 100644 --- a/test/behavior/saturating_arithmetic.zig +++ b/test/behavior/saturating_arithmetic.zig @@ -62,7 +62,7 @@ test "saturating subtraction" { test "saturating multiplication" { // TODO: once #9660 has been solved, remove this line - if (builtin.stage2_arch == .wasm32) return error.SkipZigTest; + if (builtin.cpu.arch == .wasm32) return error.SkipZigTest; const S = struct { fn doTheTest() !void { @@ -99,7 +99,7 @@ test "saturating shift-left" { try testSatShl(i8, 127, 1, 127); try testSatShl(i8, -128, 1, -128); // TODO: remove this check once #9668 is completed - if (builtin.stage2_arch != .wasm32) { + if (builtin.cpu.arch != .wasm32) { // skip testing ints > 64 bits on wasm due to miscompilation / wasmtime ci error try testSatShl(i128, maxInt(i128), 64, maxInt(i128)); try testSatShl(u128, maxInt(u128), 64, maxInt(u128));