diff --git a/src/codegen.cpp b/src/codegen.cpp index f4defb840..2965c8e59 100644 --- 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 index b0e32e8b6..5749a996d 100644 --- 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(unwrap(fn)) ); + + Function *unwrapped_function = reinterpret_cast(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 index 74b249927..d4e3548b7 100644 --- 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);