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.
This commit is contained in:
Andrew Kelley
2021-10-22 17:12:12 -07:00
parent b24e9b6347
commit 01c1f41520
11 changed files with 370 additions and 337 deletions

View File

@@ -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.