diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index d964e89ab8e1c..5ad2a5ad69e8a 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1618,6 +1618,18 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext, } }; let uses_outptr = type_of::return_uses_outptr(ccx.tcx, substd_output_type); + + // The out pointer will never alias with any other pointers, as the object only exists at a + // language level after the call. It can also be tagged with SRet to indicate that it is + // guaranteed to point to a usable block of memory for the type. + if uses_outptr { + unsafe { + let outptr = llvm::LLVMGetParam(llfndecl, 0); + llvm::LLVMAddAttribute(outptr, lib::llvm::StructRetAttribute as c_uint); + llvm::LLVMAddAttribute(outptr, lib::llvm::NoAliasAttribute as c_uint); + } + } + let debug_context = debuginfo::create_function_debug_context(ccx, id, param_substs, llfndecl); let fcx = @mut FunctionContext {