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
10121012 BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context);
10131013 fn_table_entry->fn_def_node->data.fn_def.block_context = context;
10141014 context->di_scope = LLVMZigSubprogramToScope(subprogram);
1015 ZigLLVMFnSetSubprogram(fn_table_entry->fn_value, subprogram);
10151016 }
10161017}
10171018
src/codegen.cpp+4
......@@ -744,6 +744,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
744744 case CastOpBoolToInt:
745745 assert(wanted_type->id == TypeTableEntryIdInt);
746746 assert(actual_type->id == TypeTableEntryIdBool);
747 add_debug_source_node(g, node);
747748 return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
748749
749750 }
......@@ -1965,6 +1966,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV
19651966 endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf");
19661967 }
19671968
1969 add_debug_source_node(g, source_node);
19681970 LLVMBuildCondBr(g->builder, cond_value, then_block, else_block);
19691971
19701972 LLVMPositionBuilderAtEnd(g->builder, then_block);
......@@ -3836,6 +3838,8 @@ static void init(CodeGen *g, Buf *source_path) {
38363838
38373839 LLVMSetTarget(g->module, buf_ptr(&g->triple_str));
38383840
3841 ZigLLVMAddModuleDebugInfoFlag(g->module);
3842
38393843 LLVMTargetRef target_ref;
38403844 char *err_msg = nullptr;
38413845 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)
150150 unwrapped_function->addAttribute(i, Attribute::NonNull);
151151}
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
154160LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type,
155161 uint64_t size_in_bits, uint64_t align_in_bits, const char *name)
......@@ -612,6 +618,10 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
612618 abort();
613619}
614620
621void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) {
622 unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);
623}
624
615625//------------------------------------
616626
617627#include "buffer.hpp"
......@@ -627,7 +637,8 @@ void ZigLLVMGetTargetTriple(Buf *out_buf, ZigLLVM_ArchType arch_type, ZigLLVM_Su
627637 triple.setVendor((Triple::VendorType)vendor_type);
628638 triple.setOS((Triple::OSType)os_type);
629639 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
632643 const std::string &str = triple.str();
633644 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);
100100unsigned LLVMZigTag_DW_structure_type(void);
101101
102102LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved);
103void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module);
103104
104105void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope);
105106
......@@ -132,6 +133,9 @@ LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigD
132133 LLVMZigDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line,
133134 unsigned flags, bool is_optimized, LLVMZigDISubprogram *decl_subprogram);
134135
136
137void ZigLLVMFnSetSubprogram(LLVMValueRef fn, LLVMZigDISubprogram *subprogram);
138
135139void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder);
136140
137141LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder);
test/self_hosted.zig+2-8
......@@ -55,14 +55,8 @@ fn test_loc_vars(b: i32) {
5555
5656#attribute("test")
5757fn bool_literals() {
58 should_be_true(true);
59 should_be_false(false);
60}
61fn should_be_true(b: bool) {
62 if (!b) unreachable{};
63}
64fn should_be_false(b: bool) {
65 if (b) unreachable{};
58 assert(true);
59 assert(!false);
6660}
6761
6862