1export fn intFromPtr() void {
2 var value: u8 = 0;
3 _ = @intFromPtr(&value);
4}
5
6export fn ptrFromInt() void {
7 var v: u32 = 0x1234;
8 var ptr: *u8 = @ptrFromInt(v);
9 _ = &v;
10 _ = &ptr;
11}
12
13export fn ptrPtrArithmetic() void {
14 var value0: u8 = 0;
15 var value1: u8 = 0;
16 _ = &value0 - &value1;
17}
18
19export fn ptrIntArithmetic() void {
20 var ptr0: [*]u8 = undefined;
21 _ = &ptr0;
22 _ = ptr0 - 10;
23}
24
25const slice: []const u8 = "abc";
26
27export fn sliceElemVal() void {
28 var i: u32 = 0;
29 _ = &i;
30 _ = slice[i];
31}
32
33export fn sliceElemPtr() void {
34 var i: u32 = 0;
35 _ = &i;
36 _ = &slice[i];
37}
38
39export fn manyElemVal() void {
40 var ptr: [*]const u8 = "abc";
41 var i: u32 = 0;
42 _ = .{ &ptr, &i };
43 _ = ptr[i];
44}
45
46export fn manyElemPtr() void {
47 var ptr: [*]const u8 = "abc";
48 var i: u32 = 0;
49 _ = .{ &ptr, &i };
50 _ = &ptr[i];
51}
52
53// error
54// target=spirv64-vulkan
55//
56// :3:21: error: illegal operation on logical pointer of type '*u8'
57// :3:21: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan
58// :8:20: error: illegal operation on logical pointer of type '*u8'
59// :8:20: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan
60// :16:17: error: illegal operation on logical pointer of type '*u8'
61// :16:17: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan
62// :22:14: error: illegal operation on logical pointer of type '[*]u8'
63// :22:14: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan
64// :30:14: error: illegal operation on logical pointer of type '[]const u8'
65// :30:14: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan
66// :36:15: error: illegal operation on logical pointer of type '[]const u8'
67// :36:15: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan
68// :43:12: error: illegal operation on logical pointer of type '[*]const u8'
69// :43:12: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan
70// :50:13: error: illegal operation on logical pointer of type '[*]const u8'
71// :50:13: note: pointers with address space 'generic' do not support arithmetic or indexing on target spirv-vulkan