| author | |
| committer | |
| log | 070e3ea37dd51c2a2080941a056c455f70232148 |
| tree | 9c04d0ad2849ab14550603f19ab49118dbf3bc47 |
| parent | 4c7fe74b2c0e8279d0003f820a18d59e1237b74a |
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 | } |
| 2425 | 2425 | ||
| 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 { |
| 301 | 301 | ||
| 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 | }; |
| 305 | 308 | ||
| 306 | pub const Module = opaque { | 309 | pub const Module = opaque { |
| ... | @@ -1032,6 +1035,9 @@ pub const TargetData = opaque { | ... | @@ -1032,6 +1035,9 @@ pub const TargetData = opaque { |
| 1032 | 1035 | ||
| 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 | }; |
| 1036 | 1042 | ||
| 1037 | pub const CodeModel = enum(c_int) { | 1043 | pub const CodeModel = enum(c_int) { |