authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-14 19:30:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-14 22:26:11-07:00
log070e3ea37dd51c2a2080941a056c455f70232148
tree9c04d0ad2849ab14550603f19ab49118dbf3bc47
parent4c7fe74b2c0e8279d0003f820a18d59e1237b74a

LLVM: insert debug logging when LLVM ABI size is wrong


2 files changed, 24 insertions(+), 0 deletions(-)

src/codegen/llvm.zig+18
...@@ -2424,6 +2424,24 @@ pub const DeclGen = struct {...@@ -2424,6 +2424,24 @@ pub const DeclGen = struct {
2424 }2424 }
24252425
2426 fn lowerType(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type {2426 fn lowerType(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type {
2427 const llvm_ty = try lowerTypeInner(dg, t);
2428 if (std.debug.runtime_safety) {
2429 if (t.zigTypeTag() != .Opaque and t.hasRuntimeBits() and
2430 !llvm_ty.isOpaqueStruct().toBool())
2431 {
2432 const zig_size = t.abiSize(dg.module.getTarget());
2433 const llvm_size = dg.object.target_data.abiSizeOfType(llvm_ty);
2434 if (llvm_size != zig_size) {
2435 log.err("when lowering {}, Zig ABI size = {d} but LLVM ABI size = {d}", .{
2436 t.fmt(dg.module), zig_size, llvm_size,
2437 });
2438 }
2439 }
2440 }
2441 return llvm_ty;
2442 }
2443
2444 fn lowerTypeInner(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type {
2427 const gpa = dg.gpa;2445 const gpa = dg.gpa;
2428 const target = dg.module.getTarget();2446 const target = dg.module.getTarget();
2429 switch (t.zigTypeTag()) {2447 switch (t.zigTypeTag()) {
src/codegen/llvm/bindings.zig+6
...@@ -301,6 +301,9 @@ pub const Type = opaque {...@@ -301,6 +301,9 @@ pub const Type = opaque {
301301
302 pub const countStructElementTypes = LLVMCountStructElementTypes;302 pub const countStructElementTypes = LLVMCountStructElementTypes;
303 extern fn LLVMCountStructElementTypes(StructTy: *const Type) c_uint;303 extern fn LLVMCountStructElementTypes(StructTy: *const Type) c_uint;
304
305 pub const isOpaqueStruct = LLVMIsOpaqueStruct;
306 extern fn LLVMIsOpaqueStruct(StructTy: *const Type) Bool;
304};307};
305308
306pub const Module = opaque {309pub const Module = opaque {
...@@ -1032,6 +1035,9 @@ pub const TargetData = opaque {...@@ -1032,6 +1035,9 @@ pub const TargetData = opaque {
10321035
1033 pub const abiAlignmentOfType = LLVMABIAlignmentOfType;1036 pub const abiAlignmentOfType = LLVMABIAlignmentOfType;
1034 extern fn LLVMABIAlignmentOfType(TD: *const TargetData, Ty: *const Type) c_uint;1037 extern fn LLVMABIAlignmentOfType(TD: *const TargetData, Ty: *const Type) c_uint;
1038
1039 pub const abiSizeOfType = LLVMABISizeOfType;
1040 extern fn LLVMABISizeOfType(TD: *const TargetData, Ty: *const Type) c_ulonglong;
1035};1041};
10361042
1037pub const CodeModel = enum(c_int) {1043pub const CodeModel = enum(c_int) {