From 6be5946ed8026f2a7ae990aced9572f229acecf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eckhart=20K=C3=B6ppen?= Date: Wed, 1 Mar 2023 16:49:12 +0200 Subject: [PATCH] sema: Place functions on AVR in flash addrspace - Use .flash as the default address space for functions on AVR - Return .flash as the address space for function pointers on AVR without explicit address space --- src/Sema.zig | 4 ++-- src/target.zig | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 46b47cd23d..f9a6f39867 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -17328,11 +17328,11 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air break :blk abi_align; } else 0; - const address_space = if (inst_data.flags.has_addrspace) blk: { + const address_space: std.builtin.AddressSpace = if (inst_data.flags.has_addrspace) blk: { const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); extra_i += 1; break :blk try sema.analyzeAddressSpace(block, addrspace_src, ref, .pointer); - } else .generic; + } else if (elem_ty.zigTypeTag() == .Fn and target.cpu.arch == .avr) .flash else .generic; const bit_offset = if (inst_data.flags.has_bit_range) blk: { const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); diff --git a/src/target.zig b/src/target.zig index 6d6933e9e7..f1c9a4056f 100644 --- a/src/target.zig +++ b/src/target.zig @@ -644,8 +644,9 @@ pub fn defaultAddressSpace( function, }, ) AddressSpace { - _ = target; - _ = context; + // The default address space for functions on AVR is .flash to produce + // correct fixups into progmem. + if (context == .function and target.cpu.arch == .avr) return .flash; return .generic; }