diff options
| author | Robin Voetter <robin@voetter.nl> | 2022-08-27 12:55:28 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2022-10-12 20:36:14 +0200 |
| commit | 9f14681473140cd79e6d38cb2bb46a90c1be1259 (patch) | |
| tree | 29a1774bb986ef24679911bfb7de662a34d66ec1 /src/target.zig | |
| parent | 5d429b03e3d43e937e2b517d594275034a873959 (diff) | |
| download | zig-9f14681473140cd79e6d38cb2bb46a90c1be1259.tar.gz zig-9f14681473140cd79e6d38cb2bb46a90c1be1259.zip | |
stage2: check address space cast validity
Diffstat (limited to 'src/target.zig')
| -rw-r--r-- | src/target.zig | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/target.zig b/src/target.zig index b7da04e548..3fbaf6abc4 100644 --- a/src/target.zig +++ b/src/target.zig @@ -1,5 +1,6 @@ const std = @import("std"); const Type = @import("type.zig").Type; +const AddressSpace = std.builtin.AddressSpace; pub const ArchOsAbi = struct { arch: std.Target.Cpu.Arch, @@ -635,12 +636,30 @@ pub fn defaultAddressSpace( /// Query the default address space for functions themselves. function, }, -) std.builtin.AddressSpace { +) AddressSpace { _ = target; _ = context; return .generic; } +/// Returns true if pointers in `from` can be converted to a pointer in `to`. +pub fn addrSpaceCastIsValid( + target: std.Target, + from: AddressSpace, + to: AddressSpace, +) bool { + const arch = target.cpu.arch; + switch (arch) { + .x86_64, .i386 => return arch.supportsAddressSpace(from) and arch.supportsAddressSpace(to), + .amdgcn => { + const to_generic = arch.supportsAddressSpace(from) and to == .generic; + const from_generic = arch.supportsAddressSpace(to) and from == .generic; + return to_generic or from_generic; + }, + else => return from == .generic and to == .generic, + } +} + pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 { const have_float = switch (target.abi) { .gnuilp32 => return "ilp32", |
