about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-02 09:22:18 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-02 09:22:18 -0800
commitb9a26bf4b1b98beeaaf4dae16c4b590aec87b54b (patch)
treeb01e699db5029ad17f0b18dd42095bc33bc90369
parent656d5bbb92a7f811c0ab172b2bda484b1c890924 (diff)
parentf1b64017d044018c649492b75708429749408ed0 (diff)
downloadrust-b9a26bf4b1b98beeaaf4dae16c4b590aec87b54b.tar.gz
rust-b9a26bf4b1b98beeaaf4dae16c4b590aec87b54b.zip
rollup merge of #20334: nagisa/ffi-llvm
Fixes #20313

r? @huonw
-rw-r--r--src/doc/reference.md3
-rw-r--r--src/libsyntax/feature_gate.rs11
-rw-r--r--src/test/compile-fail/issue-20313.rs17
-rw-r--r--src/test/run-pass/issue-20313.rs18
4 files changed, 49 insertions, 0 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md
index 38ca90aeecc..ec44dc20386 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -2561,6 +2561,9 @@ The currently implemented features of the reference compiler are:
                 if the system linker is not used then specifying custom flags
                 doesn't have much meaning.
 
+* `link_llvm_intrinsics` – Allows linking to LLVM intrinsics via
+                           `#[link_name="llvm.*"]`.
+
 * `linkage` - Allows use of the `linkage` attribute, which is not portable.
 
 * `log_syntax` - Allows use of the `log_syntax` macro attribute, which is a
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index b2c2d7eb626..035b748a7db 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -56,6 +56,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
     ("simd", Active),
     ("default_type_params", Active),
     ("quote", Active),
+    ("link_llvm_intrinsics", Active),
     ("linkage", Active),
     ("struct_inherit", Removed),
 
@@ -327,6 +328,16 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
                               "the `linkage` attribute is experimental \
                                and not portable across platforms")
         }
+
+        let links_to_llvm = match attr::first_attr_value_str_by_name(i.attrs[], "link_name") {
+            Some(val) => val.get().starts_with("llvm."),
+            _ => false
+        };
+        if links_to_llvm {
+            self.gate_feature("link_llvm_intrinsics", i.span,
+                              "linking to LLVM intrinsics is experimental");
+        }
+
         visit::walk_foreign_item(self, i)
     }
 
diff --git a/src/test/compile-fail/issue-20313.rs b/src/test/compile-fail/issue-20313.rs
new file mode 100644
index 00000000000..dfb23c05036
--- /dev/null
+++ b/src/test/compile-fail/issue-20313.rs
@@ -0,0 +1,17 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern {
+    #[link_name = "llvm.sqrt.f32"]
+    fn sqrt(x: f32) -> f32; //~ ERROR linking to LLVM intrinsics is experimental
+}
+
+fn main(){
+}
diff --git a/src/test/run-pass/issue-20313.rs b/src/test/run-pass/issue-20313.rs
new file mode 100644
index 00000000000..47791ceecb6
--- /dev/null
+++ b/src/test/run-pass/issue-20313.rs
@@ -0,0 +1,18 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+#![feature(link_llvm_intrinsics)]
+
+extern {
+    #[link_name = "llvm.sqrt.f32"]
+    fn sqrt(x: f32) -> f32;
+}
+
+fn main(){
+}