From 08ad7afc1e90c68409e9dc869d9dc1dceb3e8564 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Thu, 31 Oct 2024 20:24:37 +0100 Subject: [PATCH] spirv: forbid pointer arithmetic --- src/Sema.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Sema.zig b/src/Sema.zig index 65805b6a67..771f4a0540 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -17605,6 +17605,24 @@ fn analyzePtrArithmetic( } else break :rs ptr_src; }; + const target = zcu.getTarget(); + if (target_util.arePointersLogical(target, ptr_info.flags.address_space)) { + return sema.failWithOwnedErrorMsg(block, msg: { + const msg = try sema.errMsg(op_src, "illegal pointer arithmetic on pointer of type '{}'", .{ptr_ty.fmt(pt)}); + errdefer msg.destroy(sema.gpa); + + const backend = target_util.zigBackend(target, zcu.comp.config.use_llvm); + try sema.errNote(op_src, msg, "arithmetic cannot be performed on pointers with address space '{s}' on target {s}-{s} by compiler backend {s}", .{ + @tagName(ptr_info.flags.address_space), + target.cpu.arch.genericName(), + @tagName(target.os.tag), + @tagName(backend), + }); + + break :msg msg; + }); + } + try sema.requireRuntimeBlock(block, op_src, runtime_src); return block.addInst(.{ .tag = air_tag,