Skip to content

Commit 90eeb92

Browse files
committed
Update to LLVM head and mark various ptrs as nonnull.
1 parent 87ad19e commit 90eeb92

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

src/librustc/lib/llvm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@ pub mod llvm {
716716

717717
pub fn LLVMAddColdAttribute(Fn: ValueRef);
718718

719+
pub fn LLVMAddNonNullAttribute(Arg: ValueRef);
720+
pub fn LLVMAddNonNullReturnAttribute(Fn: ValueRef);
721+
719722
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
720723
PA: c_ulonglong,
721724
HighPA: c_ulonglong);

src/librustc/middle/trans/base.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,14 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
259259
ty::ty_uniq(..) => {
260260
unsafe {
261261
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
262+
llvm::LLVMAddNonNullAttribute(llarg);
262263
}
263264
}
264265
// `&mut` pointer parameters never alias other parameters, or mutable global data
265266
ty::ty_rptr(_, mt) if mt.mutbl == ast::MutMutable => {
266267
unsafe {
267268
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
269+
llvm::LLVMAddNonNullAttribute(llarg);
268270
}
269271
}
270272
// When a reference in an argument has no named lifetime, it's impossible for that
@@ -273,6 +275,13 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
273275
debug!("marking argument of {} as nocapture because of anonymous lifetime", name);
274276
unsafe {
275277
llvm::LLVMAddAttribute(llarg, lib::llvm::NoCaptureAttribute as c_uint);
278+
llvm::LLVMAddNonNullAttribute(llarg);
279+
}
280+
}
281+
// `&` pointer parameters are never null
282+
ty::ty_rptr(..) => {
283+
unsafe {
284+
llvm::LLVMAddNonNullAttribute(llarg);
276285
}
277286
}
278287
_ => {
@@ -290,12 +299,23 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
290299

291300
// The out pointer will never alias with any other pointers, as the object only exists at a
292301
// language level after the call. It can also be tagged with SRet to indicate that it is
293-
// guaranteed to point to a usable block of memory for the type.
302+
// guaranteed to point to a usable block of memory for the type. We also know that it's
303+
// never null
294304
if uses_outptr {
295305
unsafe {
296306
let outptr = llvm::LLVMGetParam(llfn, 0);
297307
llvm::LLVMAddAttribute(outptr, lib::llvm::StructRetAttribute as c_uint);
298308
llvm::LLVMAddAttribute(outptr, lib::llvm::NoAliasAttribute as c_uint);
309+
llvm::LLVMAddNonNullAttribute(outptr);
310+
}
311+
} else {
312+
match ty::get(output).sty {
313+
ty::ty_uniq(..) | ty::ty_rptr(..) => {
314+
unsafe {
315+
llvm::LLVMAddNonNullReturnAttribute(llfn);
316+
}
317+
}
318+
_ => {}
299319
}
300320
}
301321

src/llvm

Submodule llvm updated 2770 files

src/rustllvm/PassWrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "rustllvm.h"
1414

1515
#include "llvm/Support/CBindingWrapping.h"
16+
#include "llvm/Support/FileSystem.h"
1617
#include "llvm/Target/TargetLibraryInfo.h"
1718
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
1819

src/rustllvm/RustWrapper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,20 @@ extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {
119119
Function *A = unwrap<Function>(Fn);
120120
A->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold);
121121
}
122+
123+
extern "C" void LLVMAddNonNullAttribute(LLVMValueRef Arg) {
124+
Argument *A = unwrap<Argument>(Arg);
125+
A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, Attribute::NonNull));
126+
}
127+
128+
extern "C" void LLVMAddNonNullReturnAttribute(LLVMValueRef Fn) {
129+
Function *A = unwrap<Function>(Fn);
130+
A->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull);
131+
}
122132
#else
123133
extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {}
134+
extern "C" void LLVMAddNonNullAttribute(LLVMValueRef Arg) {}
135+
extern "C" void LLVMAddNonNullReturnAttribute(LLVMValueRef Fn) {}
124136
#endif
125137

126138
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,

src/rustllvm/llvm-auto-clean-trigger

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# If this file is modified, then llvm will be forcibly cleaned and then rebuilt.
22
# The actual contents of this file do not matter, but to trigger a change on the
33
# build bots then the contents should be changed so git updates the mtime.
4-
2014-04-14
4+
2014-05-20

0 commit comments

Comments
 (0)