codegen: use gen_index for nonnull attribute

also put nonnull on sret params

closes #82
This commit is contained in:
Andrew Kelley 2016-02-05 14:48:23 -07:00
parent 54fbe7560e
commit 2ee80858b4
2 changed files with 3 additions and 6 deletions

View File

@ -2876,6 +2876,7 @@ static void do_code_gen(CodeGen *g) {
if (handle_is_ptr(fn_type->data.fn.fn_type_id.return_type)) {
LLVMValueRef first_arg = LLVMGetParam(fn_table_entry->fn_value, 0);
LLVMAddAttribute(first_arg, LLVMStructRetAttribute);
LLVMZigAddNonNullAttr(fn_table_entry->fn_value, 1);
}
// set parameter attributes
@ -2903,12 +2904,7 @@ static void do_code_gen(CodeGen *g) {
LLVMAddAttribute(argument_val, LLVMReadOnlyAttribute);
}
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);
LLVMZigAddNonNullAttr(fn_table_entry->fn_value, gen_index + 1);
}
if (is_byval) {
// TODO

View File

@ -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);
// 0 is return value, 1 is first arg
void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i);
LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type,