]> git.lizzy.rs Git - rust.git/commitdiff
Update to LLVM head and mark various ptrs as nonnull.
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Tue, 20 May 2014 21:42:20 +0000 (17:42 -0400)
committerLuqman Aden <laden@csclub.uwaterloo.ca>
Fri, 23 May 2014 01:06:24 +0000 (21:06 -0400)
src/librustc/lib/llvm.rs
src/librustc/middle/trans/base.rs
src/llvm
src/rustllvm/PassWrapper.cpp
src/rustllvm/RustWrapper.cpp
src/rustllvm/llvm-auto-clean-trigger

index 711081f46d6669703a276c2d8981881c4398b078..0e7a904c967826e959c77bdbaa9760ea5b7cca9b 100644 (file)
@@ -716,6 +716,9 @@ pub fn LLVMGetOrInsertFunction(M: ModuleRef,
 
         pub fn LLVMAddColdAttribute(Fn: ValueRef);
 
+        pub fn LLVMAddNonNullAttribute(Arg: ValueRef);
+        pub fn LLVMAddNonNullReturnAttribute(Fn: ValueRef);
+
         pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
                                       PA: c_ulonglong,
                                       HighPA: c_ulonglong);
index e208097e99b33a27cd8261bf66aad140039878ff..6413d798e0e2a909f3c1ffe8af5613ca7663d061 100644 (file)
@@ -259,12 +259,14 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
             ty::ty_uniq(..) => {
                 unsafe {
                     llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
+                    llvm::LLVMAddNonNullAttribute(llarg);
                 }
             }
             // `&mut` pointer parameters never alias other parameters, or mutable global data
             ty::ty_rptr(_, mt) if mt.mutbl == ast::MutMutable => {
                 unsafe {
                     llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
+                    llvm::LLVMAddNonNullAttribute(llarg);
                 }
             }
             // 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,
                 debug!("marking argument of {} as nocapture because of anonymous lifetime", name);
                 unsafe {
                     llvm::LLVMAddAttribute(llarg, lib::llvm::NoCaptureAttribute as c_uint);
+                    llvm::LLVMAddNonNullAttribute(llarg);
+                }
+            }
+            // `&` pointer parameters are never null
+            ty::ty_rptr(..) => {
+                unsafe {
+                    llvm::LLVMAddNonNullAttribute(llarg);
                 }
             }
             _ => {
@@ -290,12 +299,23 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
 
     // 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.
+    // guaranteed to point to a usable block of memory for the type. We also know that it's
+    // never null
     if uses_outptr {
         unsafe {
             let outptr = llvm::LLVMGetParam(llfn, 0);
             llvm::LLVMAddAttribute(outptr, lib::llvm::StructRetAttribute as c_uint);
             llvm::LLVMAddAttribute(outptr, lib::llvm::NoAliasAttribute as c_uint);
+            llvm::LLVMAddNonNullAttribute(outptr);
+        }
+    } else {
+        match ty::get(output).sty {
+            ty::ty_uniq(..) | ty::ty_rptr(..) => {
+                unsafe {
+                    llvm::LLVMAddNonNullReturnAttribute(llfn);
+                }
+            }
+            _ => {}
         }
     }
 
index 4b4d0533b4f76cc3fbba31bd9e7ac02e0c738b1d..0a894645cf120539876e9eb4eb0d7b572dfa9d14 160000 (submodule)
--- a/src/llvm
+++ b/src/llvm
@@ -1 +1 @@
-Subproject commit 4b4d0533b4f76cc3fbba31bd9e7ac02e0c738b1d
+Subproject commit 0a894645cf120539876e9eb4eb0d7b572dfa9d14
index 64776421fa1451c122839a93926844d4b8b52087..195b044ccdcef57ee72d6524b10bc65bc27c1add 100644 (file)
@@ -13,6 +13,7 @@
 #include "rustllvm.h"
 
 #include "llvm/Support/CBindingWrapping.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
 
index 717cd333a79ce800e41dee9ee23fb20871f5b2a1..3661d152d59995d9a64353d65a3d1026d3498d66 100644 (file)
@@ -119,8 +119,20 @@ extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {
   Function *A = unwrap<Function>(Fn);
   A->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold);
 }
+
+extern "C" void LLVMAddNonNullAttribute(LLVMValueRef Arg) {
+  Argument *A = unwrap<Argument>(Arg);
+  A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, Attribute::NonNull));
+}
+
+extern "C" void LLVMAddNonNullReturnAttribute(LLVMValueRef Fn) {
+  Function *A = unwrap<Function>(Fn);
+  A->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull);
+}
 #else
 extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {}
+extern "C" void LLVMAddNonNullAttribute(LLVMValueRef Arg) {}
+extern "C" void LLVMAddNonNullReturnAttribute(LLVMValueRef Fn) {}
 #endif
 
 extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
index 340a491527710eb8c574852cf8660823562854d4..4e599ad115db36dc9e66602a112073caae7ce50d 100644 (file)
@@ -1,4 +1,4 @@
 # If this file is modified, then llvm will be forcibly cleaned and then rebuilt.
 # The actual contents of this file do not matter, but to trigger a change on the
 # build bots then the contents should be changed so git updates the mtime.
-2014-04-14
+2014-05-20