authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-29 09:30:22-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-29 09:30:22-04:00
log8f682efbc5abf4d631f60310f95b998c6fe44669
treebbb70e115d7cb66f7a29e63128ca6fb19210f599
parent1116d82197b46010b80e0e4454abc8881a642947

pass all tests without triggering assertions

fixes tests when targeting darwin

2 files changed, 9 insertions(+), 12 deletions(-)

src/analyze.cpp+2
......@@ -4812,6 +4812,8 @@ uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) {
48124812 return type_entry->data.enumeration.abi_alignment;
48134813 } else if (type_entry->id == TypeTableEntryIdUnion) {
48144814 zig_panic("TODO");
4815 } else if (type_entry->id == TypeTableEntryIdOpaque) {
4816 return 1;
48154817 } else {
48164818 return LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);
48174819 }
src/codegen.cpp+7-12
......@@ -350,12 +350,6 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
350350 zig_unreachable();
351351}
352352
353static uint32_t get_pref_fn_align(CodeGen *g, LLVMTypeRef fn_type_ref) {
354 uint32_t pref_align = LLVMPreferredAlignmentOfType(g->target_data_ref, fn_type_ref);
355 uint32_t abi_align = LLVMABIAlignmentOfType(g->target_data_ref, fn_type_ref);
356 return (pref_align > abi_align) ? pref_align : abi_align;
357}
358
359353static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
360354 if (fn_table_entry->llvm_value)
361355 return fn_table_entry->llvm_value;
......@@ -450,12 +444,11 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
450444 }
451445 if (fn_table_entry->align_bytes > 0) {
452446 LLVMSetAlignment(fn_table_entry->llvm_value, (unsigned)fn_table_entry->align_bytes);
453 } else if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
454 LLVMSetAlignment(fn_table_entry->llvm_value,
455 get_pref_fn_align(g, fn_table_entry->type_entry->data.fn.raw_type_ref));
456447 } else {
457 LLVMSetAlignment(fn_table_entry->llvm_value,
458 LLVMABIAlignmentOfType(g->target_data_ref, fn_table_entry->type_entry->data.fn.raw_type_ref));
448 // We'd like to set the best alignment for the function here, but on Darwin LLVM gives
449 // "Cannot getTypeInfo() on a type that is unsized!" assertion failure when calling
450 // any of the functions for getting alignment. Not specifying the alignment should
451 // use the ABI alignment, which is fine.
459452 }
460453
461454 return fn_table_entry->llvm_value;
......@@ -814,7 +807,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
814807 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim", "true");
815808 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim-non-leaf", nullptr);
816809 }
817 LLVMSetAlignment(fn_val, get_pref_fn_align(g, fn_type_ref));
810 // Not setting alignment here. See the comment above about
811 // "Cannot getTypeInfo() on a type that is unsized!"
812 // assertion failure on Darwin.
818813
819814 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
820815 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);