From 75d142c3c78ef786801dcf85f44d16a6530f02d2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 23 Dec 2018 18:22:30 -0500 Subject: [PATCH] llvm8: fix ZigLLVMCreateFunction --- src/codegen.cpp | 8 ++++++-- src/zig_llvm.cpp | 6 +++--- src/zig_llvm.h | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 983bc923d..83efc1971 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -643,14 +643,18 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) { unsigned line_number = (unsigned)(fn_table_entry->proto_node->line == 0) ? 0 : (fn_table_entry->proto_node->line + 1); unsigned scope_line = line_number; + bool is_definition = fn_table_entry->body_node != nullptr; + bool is_optimized = g->build_mode != BuildModeDebug; + bool is_internal_linkage = (fn_table_entry->body_node != nullptr && + fn_table_entry->export_list.length == 0); unsigned flags = 0; ZigLLVMDIScope *fn_di_scope = get_di_scope(g, scope->parent); assert(fn_di_scope != nullptr); ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder, fn_di_scope, buf_ptr(&fn_table_entry->symbol_name), "", import->di_file, line_number, - fn_table_entry->type_entry->di_type, - scope_line, flags, nullptr); + fn_table_entry->type_entry->di_type, is_internal_linkage, + is_definition, scope_line, flags, is_optimized, nullptr); scope->di_scope = ZigLLVMSubprogramToScope(subprogram); ZigLLVMFnSetSubprogram(fn_llvm_value(g, fn_table_entry), subprogram); diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 263dc82b1..7c486b183 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -594,8 +594,8 @@ ZigLLVMDIFile *ZigLLVMCreateFile(ZigLLVMDIBuilder *dibuilder, const char *filena ZigLLVMDISubprogram *ZigLLVMCreateFunction(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIScope *scope, const char *name, const char *linkage_name, ZigLLVMDIFile *file, unsigned lineno, - ZigLLVMDIType *fn_di_type, unsigned scope_line, - unsigned flags, ZigLLVMDISubprogram *decl_subprogram) + ZigLLVMDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line, + unsigned flags, bool is_optimized, ZigLLVMDISubprogram *decl_subprogram) { DISubroutineType *di_sub_type = static_cast(reinterpret_cast(fn_di_type)); assert(flags == 0); @@ -607,7 +607,7 @@ ZigLLVMDISubprogram *ZigLLVMCreateFunction(ZigLLVMDIBuilder *dibuilder, ZigLLVMD di_sub_type, scope_line, DINode::FlagZero, - DISubprogram::SPFlagZero, + DISubprogram::toSPFlags(is_local_to_unit, is_definition, is_optimized), nullptr, reinterpret_cast(decl_subprogram), nullptr); diff --git a/src/zig_llvm.h b/src/zig_llvm.h index 02078791c..9b70a919f 100644 --- a/src/zig_llvm.h +++ b/src/zig_llvm.h @@ -188,8 +188,9 @@ ZIG_EXTERN_C struct ZigLLVMDIFile *ZigLLVMCreateFile(struct ZigLLVMDIBuilder *di ZIG_EXTERN_C struct ZigLLVMDISubprogram *ZigLLVMCreateFunction(struct ZigLLVMDIBuilder *dibuilder, struct ZigLLVMDIScope *scope, const char *name, const char *linkage_name, struct ZigLLVMDIFile *file, - unsigned lineno, struct ZigLLVMDIType *fn_di_type, - unsigned scope_line, unsigned flags, struct ZigLLVMDISubprogram *decl_subprogram); + unsigned lineno, struct ZigLLVMDIType *fn_di_type, bool is_local_to_unit, bool is_definition, + unsigned scope_line, unsigned flags, bool is_optimized, struct ZigLLVMDISubprogram *decl_subprogram); + ZIG_EXTERN_C void ZigLLVMFnSetSubprogram(LLVMValueRef fn, struct ZigLLVMDISubprogram *subprogram);