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) {...@@ -4812,6 +4812,8 @@ uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) {
4812 return type_entry->data.enumeration.abi_alignment;4812 return type_entry->data.enumeration.abi_alignment;
4813 } else if (type_entry->id == TypeTableEntryIdUnion) {4813 } else if (type_entry->id == TypeTableEntryIdUnion) {
4814 zig_panic("TODO");4814 zig_panic("TODO");
4815 } else if (type_entry->id == TypeTableEntryIdOpaque) {
4816 return 1;
4815 } else {4817 } else {
4816 return LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);4818 return LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);
4817 }4819 }
src/codegen.cpp+7-12
...@@ -350,12 +350,6 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {...@@ -350,12 +350,6 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
350 zig_unreachable();350 zig_unreachable();
351}351}
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
359static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {353static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
360 if (fn_table_entry->llvm_value)354 if (fn_table_entry->llvm_value)
361 return fn_table_entry->llvm_value;355 return fn_table_entry->llvm_value;
...@@ -450,12 +444,11 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -450,12 +444,11 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
450 }444 }
451 if (fn_table_entry->align_bytes > 0) {445 if (fn_table_entry->align_bytes > 0) {
452 LLVMSetAlignment(fn_table_entry->llvm_value, (unsigned)fn_table_entry->align_bytes);446 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));
456 } else {447 } else {
457 LLVMSetAlignment(fn_table_entry->llvm_value,448 // We'd like to set the best alignment for the function here, but on Darwin LLVM gives
458 LLVMABIAlignmentOfType(g->target_data_ref, fn_table_entry->type_entry->data.fn.raw_type_ref));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.
459 }452 }
460453
461 return fn_table_entry->llvm_value;454 return fn_table_entry->llvm_value;
...@@ -814,7 +807,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {...@@ -814,7 +807,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
814 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim", "true");807 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim", "true");
815 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim-non-leaf", nullptr);808 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim-non-leaf", nullptr);
816 }809 }
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
819 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");814 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
820 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);815 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);