fix debug symbols regression after llvm 3.8.0

This commit is contained in:
Andrew Kelley 2016-04-09 14:21:00 -07:00
parent 7a05e18efb
commit 7026bed462
5 changed files with 23 additions and 9 deletions

View File

@ -1012,6 +1012,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t
BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context);
fn_table_entry->fn_def_node->data.fn_def.block_context = context;
context->di_scope = LLVMZigSubprogramToScope(subprogram);
ZigLLVMFnSetSubprogram(fn_table_entry->fn_value, subprogram);
}
}

View File

@ -744,6 +744,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
case CastOpBoolToInt:
assert(wanted_type->id == TypeTableEntryIdInt);
assert(actual_type->id == TypeTableEntryIdBool);
add_debug_source_node(g, node);
return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
}
@ -1965,6 +1966,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV
endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf");
}
add_debug_source_node(g, source_node);
LLVMBuildCondBr(g->builder, cond_value, then_block, else_block);
LLVMPositionBuilderAtEnd(g->builder, then_block);
@ -3836,6 +3838,8 @@ static void init(CodeGen *g, Buf *source_path) {
LLVMSetTarget(g->module, buf_ptr(&g->triple_str));
ZigLLVMAddModuleDebugInfoFlag(g->module);
LLVMTargetRef target_ref;
char *err_msg = nullptr;
if (LLVMGetTargetFromTriple(buf_ptr(&g->triple_str), &target_ref, &err_msg)) {

View File

@ -150,6 +150,12 @@ void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i)
unwrapped_function->addAttribute(i, Attribute::NonNull);
}
void ZigLLVMFnSetSubprogram(LLVMValueRef fn, LLVMZigDISubprogram *subprogram) {
assert( isa<Function>(unwrap(fn)) );
Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(fn));
unwrapped_function->setSubprogram(reinterpret_cast<DISubprogram*>(subprogram));
}
LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type,
uint64_t size_in_bits, uint64_t align_in_bits, const char *name)
@ -612,6 +618,10 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
abort();
}
void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) {
unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);
}
//------------------------------------
#include "buffer.hpp"
@ -627,7 +637,8 @@ void ZigLLVMGetTargetTriple(Buf *out_buf, ZigLLVM_ArchType arch_type, ZigLLVM_Su
triple.setVendor((Triple::VendorType)vendor_type);
triple.setOS((Triple::OSType)os_type);
triple.setEnvironment((Triple::EnvironmentType)environ_type);
triple.setObjectFormat((Triple::ObjectFormatType)oformat);
// I guess it's a "triple" because we don't set the object format?
//triple.setObjectFormat((Triple::ObjectFormatType)oformat);
const std::string &str = triple.str();
buf_init_from_mem(out_buf, str.c_str(), str.size());

View File

@ -100,6 +100,7 @@ unsigned LLVMZigTag_DW_variable(void);
unsigned LLVMZigTag_DW_structure_type(void);
LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved);
void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module);
void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope);
@ -132,6 +133,9 @@ LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigD
LLVMZigDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line,
unsigned flags, bool is_optimized, LLVMZigDISubprogram *decl_subprogram);
void ZigLLVMFnSetSubprogram(LLVMValueRef fn, LLVMZigDISubprogram *subprogram);
void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder);
LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder);

View File

@ -55,14 +55,8 @@ fn test_loc_vars(b: i32) {
#attribute("test")
fn bool_literals() {
should_be_true(true);
should_be_false(false);
}
fn should_be_true(b: bool) {
if (!b) unreachable{};
}
fn should_be_false(b: bool) {
if (b) unreachable{};
assert(true);
assert(!false);
}