mirror of
https://github.com/ziglang/zig.git
synced 2024-11-22 20:30:17 +00:00
0fe3fd01dd
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
35 lines
988 B
Zig
35 lines
988 B
Zig
const expect = @import("std").testing.expect;
|
|
|
|
var foo: u8 align(4) = 100;
|
|
|
|
test "global variable alignment" {
|
|
try expect(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4);
|
|
try expect(@TypeOf(&foo) == *align(4) u8);
|
|
const as_pointer_to_array: *align(4) [1]u8 = &foo;
|
|
const as_slice: []align(4) u8 = as_pointer_to_array;
|
|
const as_unaligned_slice: []u8 = as_slice;
|
|
try expect(as_unaligned_slice[0] == 100);
|
|
}
|
|
|
|
fn derp() align(@sizeOf(usize) * 2) i32 {
|
|
return 1234;
|
|
}
|
|
fn noop1() align(1) void {}
|
|
fn noop4() align(4) void {}
|
|
|
|
test "function alignment" {
|
|
try expect(derp() == 1234);
|
|
try expect(@TypeOf(derp) == fn () i32);
|
|
try expect(@TypeOf(&derp) == *align(@sizeOf(usize) * 2) const fn () i32);
|
|
|
|
noop1();
|
|
try expect(@TypeOf(noop1) == fn () void);
|
|
try expect(@TypeOf(&noop1) == *align(1) const fn () void);
|
|
|
|
noop4();
|
|
try expect(@TypeOf(noop4) == fn () void);
|
|
try expect(@TypeOf(&noop4) == *align(4) const fn () void);
|
|
}
|
|
|
|
// test
|