From 59de23dfa010c5556f79fbb8b4c637c8d150fd88 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 15 Dec 2019 19:25:41 +0100 Subject: [PATCH] Don't assume TLS storage has a fixed address Fixes #3433 --- src/ir.cpp | 2 +- test/stage1/behavior/misc.zig | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ir.cpp b/src/ir.cpp index 8e1cef8e43..52f3126428 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17395,7 +17395,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type, var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); - if (linkage_makes_it_runtime) + if (linkage_makes_it_runtime || var->is_thread_local) goto no_mem_slot; if (value_is_comptime(var->const_value)) { diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index dd3ad29878..0b29189cde 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -773,3 +773,11 @@ test "result location is optional inside error union" { const x = maybe(true) catch unreachable; expect(x.? == 42); } + +threadlocal var buffer: [11]u8 = undefined; + +test "pointer to thread local array" { + const s = "Hello world"; + std.mem.copy(u8, buffer[0..], s); + std.testing.expectEqualSlices(u8, buffer[0..], s); +}