aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig18
-rw-r--r--src/codegen/llvm/bindings.zig6
2 files changed, 24 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index fe35620d38..714ac16c54 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -2424,6 +2424,24 @@ pub const DeclGen = struct {
}
fn lowerType(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type {
+ const llvm_ty = try lowerTypeInner(dg, t);
+ if (std.debug.runtime_safety) {
+ if (t.zigTypeTag() != .Opaque and t.hasRuntimeBits() and
+ !llvm_ty.isOpaqueStruct().toBool())
+ {
+ const zig_size = t.abiSize(dg.module.getTarget());
+ const llvm_size = dg.object.target_data.abiSizeOfType(llvm_ty);
+ if (llvm_size != zig_size) {
+ log.err("when lowering {}, Zig ABI size = {d} but LLVM ABI size = {d}", .{
+ t.fmt(dg.module), zig_size, llvm_size,
+ });
+ }
+ }
+ }
+ return llvm_ty;
+ }
+
+ fn lowerTypeInner(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type {
const gpa = dg.gpa;
const target = dg.module.getTarget();
switch (t.zigTypeTag()) {
diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig
index 89905e4a29..3279f052b2 100644
--- a/src/codegen/llvm/bindings.zig
+++ b/src/codegen/llvm/bindings.zig
@@ -301,6 +301,9 @@ pub const Type = opaque {
pub const countStructElementTypes = LLVMCountStructElementTypes;
extern fn LLVMCountStructElementTypes(StructTy: *const Type) c_uint;
+
+ pub const isOpaqueStruct = LLVMIsOpaqueStruct;
+ extern fn LLVMIsOpaqueStruct(StructTy: *const Type) Bool;
};
pub const Module = opaque {
@@ -1032,6 +1035,9 @@ pub const TargetData = opaque {
pub const abiAlignmentOfType = LLVMABIAlignmentOfType;
extern fn LLVMABIAlignmentOfType(TD: *const TargetData, Ty: *const Type) c_uint;
+
+ pub const abiSizeOfType = LLVMABISizeOfType;
+ extern fn LLVMABISizeOfType(TD: *const TargetData, Ty: *const Type) c_ulonglong;
};
pub const CodeModel = enum(c_int) {