zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 54fbe7560ec0f3a9d5016f2058b07463767bf6e1 (tree)
parent ff5673ae1b74b8ad59ee23921e0bb4e25349d10f
Author: realazthat <realazthat@gmail.com>
Date:   Fri,  5 Feb 2016 16:29:26 -0500

Added code for generating nonnull attributes

Diffstat:
Msrc/codegen.cpp | 4++++
Msrc/zig_llvm.cpp | 10++++++++++
Msrc/zig_llvm.hpp | 1+
3 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/codegen.cpp b/src/codegen.cpp @@ -2905,6 +2905,10 @@ static void do_code_gen(CodeGen *g) { if (param_type->id == TypeTableEntryIdPointer) { // when https://github.com/andrewrk/zig/issues/82 is fixed, add // non null attribute here + + ///`i` is arg index + 1 + ///I think that 0 is the return index, but it has a named LLVM constant variable + LLVMZigAddNonNullAttr(fn_table_entry->fn_value, param_decl_i + 1); } if (is_byval) { // TODO diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp @@ -140,6 +140,16 @@ LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A return wrap(unwrap(B)->Insert(call_inst)); } +void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i) +{ + assert( isa<Function>(unwrap(fn)) ); + + Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(fn)); + + unwrapped_function->addAttribute(i, Attribute::NonNull); +} + + LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type, uint64_t size_in_bits, uint64_t align_in_bits, const char *name) { diff --git a/src/zig_llvm.hpp b/src/zig_llvm.hpp @@ -39,6 +39,7 @@ void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, unsigned CC, const char *Name); +void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i); LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type, uint64_t size_in_bits, uint64_t align_in_bits, const char *name);