diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-22 17:12:12 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-22 17:12:12 -0700 |
| commit | 01c1f415209f5085e09430cc6df182d7eb2245ee (patch) | |
| tree | 9f93de2769afd58bf1a88db0b9b266aa24bb4b66 /src/Module.zig | |
| parent | b24e9b6347afc66aa94f61b3ed4c2d02cdb0d0ee (diff) | |
| download | zig-01c1f415209f5085e09430cc6df182d7eb2245ee.tar.gz zig-01c1f415209f5085e09430cc6df182d7eb2245ee.zip | |
stage2: slice and alignment fixes
* Fix backend using wrong union field of the slice instruction.
* LLVM backend properly sets alignment on global variables.
* Sema: add coercion for *T to *[1]T
* Sema: pointers to Decls with explicit alignment now have alignment
metadata in them.
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig index 3ac523bdc5..de6770d3d7 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -772,6 +772,17 @@ pub const Decl = struct { else => false, }; } + + pub fn getAlignment(decl: Decl, target: Target) u32 { + assert(decl.has_tv); + if (decl.align_val.tag() != .null_value) { + // Explicit alignment. + return @intCast(u32, decl.align_val.toUnsignedInt()); + } else { + // Natural alignment. + return decl.ty.abiAlignment(target); + } + } }; /// This state is attached to every Decl when Module emit_h is non-null. |
