aboutsummaryrefslogtreecommitdiff
path: root/src/target.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2022-08-27 12:55:28 +0200
committerRobin Voetter <robin@voetter.nl>2022-10-12 20:36:14 +0200
commit9f14681473140cd79e6d38cb2bb46a90c1be1259 (patch)
tree29a1774bb986ef24679911bfb7de662a34d66ec1 /src/target.zig
parent5d429b03e3d43e937e2b517d594275034a873959 (diff)
downloadzig-9f14681473140cd79e6d38cb2bb46a90c1be1259.tar.gz
zig-9f14681473140cd79e6d38cb2bb46a90c1be1259.zip
stage2: check address space cast validity
Diffstat (limited to 'src/target.zig')
-rw-r--r--src/target.zig21
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",