authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-09 14:21:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-09 14:21:55-07:00
log7026bed4625b4fe9ac068b045a17e822791ceb93
tree652760a2b18c6f7b2f303074705e333ba4c7d500
parent7a05e18efb35330475e7ee6253f9fec6103c560f

fix debug symbols regression after llvm 3.8.0


5 files changed, 23 insertions(+), 9 deletions(-)

src/analyze.cpp+1
...@@ -1012,6 +1012,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t...@@ -1012,6 +1012,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t
1012 BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context);1012 BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context);
1013 fn_table_entry->fn_def_node->data.fn_def.block_context = context;1013 fn_table_entry->fn_def_node->data.fn_def.block_context = context;
1014 context->di_scope = LLVMZigSubprogramToScope(subprogram);1014 context->di_scope = LLVMZigSubprogramToScope(subprogram);
1015 ZigLLVMFnSetSubprogram(fn_table_entry->fn_value, subprogram);
1015 }1016 }
1016}1017}
10171018
src/codegen.cpp+4
...@@ -744,6 +744,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {...@@ -744,6 +744,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
744 case CastOpBoolToInt:744 case CastOpBoolToInt:
745 assert(wanted_type->id == TypeTableEntryIdInt);745 assert(wanted_type->id == TypeTableEntryIdInt);
746 assert(actual_type->id == TypeTableEntryIdBool);746 assert(actual_type->id == TypeTableEntryIdBool);
747 add_debug_source_node(g, node);
747 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");748 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
748749
749 }750 }
...@@ -1965,6 +1966,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV...@@ -1965,6 +1966,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV
1965 endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf");1966 endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf");
1966 }1967 }
19671968
1969 add_debug_source_node(g, source_node);
1968 LLVMBuildCondBr(g->builder, cond_value, then_block, else_block);1970 LLVMBuildCondBr(g->builder, cond_value, then_block, else_block);
19691971
1970 LLVMPositionBuilderAtEnd(g->builder, then_block);1972 LLVMPositionBuilderAtEnd(g->builder, then_block);
...@@ -3836,6 +3838,8 @@ static void init(CodeGen *g, Buf *source_path) {...@@ -3836,6 +3838,8 @@ static void init(CodeGen *g, Buf *source_path) {
38363838
3837 LLVMSetTarget(g->module, buf_ptr(&g->triple_str));3839 LLVMSetTarget(g->module, buf_ptr(&g->triple_str));
38383840
3841 ZigLLVMAddModuleDebugInfoFlag(g->module);
3842
3839 LLVMTargetRef target_ref;3843 LLVMTargetRef target_ref;
3840 char *err_msg = nullptr;3844 char *err_msg = nullptr;
3841 if (LLVMGetTargetFromTriple(buf_ptr(&g->triple_str), &target_ref, &err_msg)) {3845 if (LLVMGetTargetFromTriple(buf_ptr(&g->triple_str), &target_ref, &err_msg)) {
src/zig_llvm.cpp+12-1
...@@ -150,6 +150,12 @@ void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i)...@@ -150,6 +150,12 @@ void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i)
150 unwrapped_function->addAttribute(i, Attribute::NonNull);150 unwrapped_function->addAttribute(i, Attribute::NonNull);
151}151}
152152
153void ZigLLVMFnSetSubprogram(LLVMValueRef fn, LLVMZigDISubprogram *subprogram) {
154 assert( isa<Function>(unwrap(fn)) );
155 Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(fn));
156 unwrapped_function->setSubprogram(reinterpret_cast<DISubprogram*>(subprogram));
157}
158
153159
154LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type,160LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type,
155 uint64_t size_in_bits, uint64_t align_in_bits, const char *name)161 uint64_t size_in_bits, uint64_t align_in_bits, const char *name)
...@@ -612,6 +618,10 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {...@@ -612,6 +618,10 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
612 abort();618 abort();
613}619}
614620
621void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) {
622 unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);
623}
624
615//------------------------------------625//------------------------------------
616626
617#include "buffer.hpp"627#include "buffer.hpp"
...@@ -627,7 +637,8 @@ void ZigLLVMGetTargetTriple(Buf *out_buf, ZigLLVM_ArchType arch_type, ZigLLVM_Su...@@ -627,7 +637,8 @@ void ZigLLVMGetTargetTriple(Buf *out_buf, ZigLLVM_ArchType arch_type, ZigLLVM_Su
627 triple.setVendor((Triple::VendorType)vendor_type);637 triple.setVendor((Triple::VendorType)vendor_type);
628 triple.setOS((Triple::OSType)os_type);638 triple.setOS((Triple::OSType)os_type);
629 triple.setEnvironment((Triple::EnvironmentType)environ_type);639 triple.setEnvironment((Triple::EnvironmentType)environ_type);
630 triple.setObjectFormat((Triple::ObjectFormatType)oformat);640 // I guess it's a "triple" because we don't set the object format?
641 //triple.setObjectFormat((Triple::ObjectFormatType)oformat);
631642
632 const std::string &str = triple.str();643 const std::string &str = triple.str();
633 buf_init_from_mem(out_buf, str.c_str(), str.size());644 buf_init_from_mem(out_buf, str.c_str(), str.size());
src/zig_llvm.hpp+4
...@@ -100,6 +100,7 @@ unsigned LLVMZigTag_DW_variable(void);...@@ -100,6 +100,7 @@ unsigned LLVMZigTag_DW_variable(void);
100unsigned LLVMZigTag_DW_structure_type(void);100unsigned LLVMZigTag_DW_structure_type(void);
101101
102LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved);102LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved);
103void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module);
103104
104void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope);105void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope);
105106
...@@ -132,6 +133,9 @@ LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigD...@@ -132,6 +133,9 @@ LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigD
132 LLVMZigDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line,133 LLVMZigDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line,
133 unsigned flags, bool is_optimized, LLVMZigDISubprogram *decl_subprogram);134 unsigned flags, bool is_optimized, LLVMZigDISubprogram *decl_subprogram);
134135
136
137void ZigLLVMFnSetSubprogram(LLVMValueRef fn, LLVMZigDISubprogram *subprogram);
138
135void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder);139void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder);
136140
137LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder);141LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder);
test/self_hosted.zig+2-8
...@@ -55,14 +55,8 @@ fn test_loc_vars(b: i32) {...@@ -55,14 +55,8 @@ fn test_loc_vars(b: i32) {
5555
56#attribute("test")56#attribute("test")
57fn bool_literals() {57fn bool_literals() {
58 should_be_true(true);58 assert(true);
59 should_be_false(false);59 assert(!false);
60}
61fn should_be_true(b: bool) {
62 if (!b) unreachable{};
63}
64fn should_be_false(b: bool) {
65 if (b) unreachable{};
66}60}
6761
6862