From f1b64017d044018c649492b75708429749408ed0 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Tue, 30 Dec 2014 17:44:31 +0200 Subject: [PATCH] Feature gate FFI imports of LLVM intrinsics Fixes #20313 --- src/doc/reference.md | 7 +++++-- src/libsyntax/feature_gate.rs | 11 +++++++++++ src/test/compile-fail/issue-20313.rs | 17 +++++++++++++++++ src/test/run-pass/issue-20313.rs | 18 ++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-20313.rs create mode 100644 src/test/run-pass/issue-20313.rs diff --git a/src/doc/reference.md b/src/doc/reference.md index 94c76aaa69518..57a452b1a7b0c 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 @@ -4149,11 +4152,11 @@ Unwinding the stack of a thread is done by the thread itself, on its own control stack. If a value with a destructor is freed during unwinding, the code for the destructor is run, also on the thread's control stack. Running the destructor code causes a temporary transition to a *running* state, and allows the -destructor code to cause any subsequent state transitions. The original thread +destructor code to cause any subsequent state transitions. The original thread of unwinding and panicking thereby may suspend temporarily, and may involve (recursive) unwinding of the stack of a failed destructor. Nonetheless, the outermost unwinding activity will continue until the stack is unwound and the -thread transitions to the *dead* state. There is no way to "recover" from thread +thread transitions to the *dead* state. There is no way to "recover" from thread panics. Once a thread has temporarily suspended its unwinding in the *panicking* state, a panic occurring from within this destructor results in *hard* panic. A hard panic currently results in the process aborting. diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 4607520655ea1..8b4074abedcd3 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), @@ -292,6 +293,16 @@ impl<'a, 'v> Visitor<'v> for Context<'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 0000000000000..dfb23c0503689 --- /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 or the MIT license +// , 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 0000000000000..47791ceecb67d --- /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 or the MIT license +// , 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(){ +}