Skip to content

Commit f1b6401

Browse files
committed
Feature gate FFI imports of LLVM intrinsics
Fixes #20313
1 parent d2368c3 commit f1b6401

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

src/doc/reference.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,9 @@ The currently implemented features of the reference compiler are:
25612561
if the system linker is not used then specifying custom flags
25622562
doesn't have much meaning.
25632563

2564+
* `link_llvm_intrinsics` – Allows linking to LLVM intrinsics via
2565+
`#[link_name="llvm.*"]`.
2566+
25642567
* `linkage` - Allows use of the `linkage` attribute, which is not portable.
25652568

25662569
* `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
41494152
stack. If a value with a destructor is freed during unwinding, the code for the
41504153
destructor is run, also on the thread's control stack. Running the destructor
41514154
code causes a temporary transition to a *running* state, and allows the
4152-
destructor code to cause any subsequent state transitions. The original thread
4155+
destructor code to cause any subsequent state transitions. The original thread
41534156
of unwinding and panicking thereby may suspend temporarily, and may involve
41544157
(recursive) unwinding of the stack of a failed destructor. Nonetheless, the
41554158
outermost unwinding activity will continue until the stack is unwound and the
4156-
thread transitions to the *dead* state. There is no way to "recover" from thread
4159+
thread transitions to the *dead* state. There is no way to "recover" from thread
41574160
panics. Once a thread has temporarily suspended its unwinding in the *panicking*
41584161
state, a panic occurring from within this destructor results in *hard* panic.
41594162
A hard panic currently results in the process aborting.

src/libsyntax/feature_gate.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5656
("simd", Active),
5757
("default_type_params", Active),
5858
("quote", Active),
59+
("link_llvm_intrinsics", Active),
5960
("linkage", Active),
6061
("struct_inherit", Removed),
6162

@@ -292,6 +293,16 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
292293
"the `linkage` attribute is experimental \
293294
and not portable across platforms")
294295
}
296+
297+
let links_to_llvm = match attr::first_attr_value_str_by_name(i.attrs[], "link_name") {
298+
Some(val) => val.get().starts_with("llvm."),
299+
_ => false
300+
};
301+
if links_to_llvm {
302+
self.gate_feature("link_llvm_intrinsics", i.span,
303+
"linking to LLVM intrinsics is experimental");
304+
}
305+
295306
visit::walk_foreign_item(self, i)
296307
}
297308

src/test/compile-fail/issue-20313.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern {
12+
#[link_name = "llvm.sqrt.f32"]
13+
fn sqrt(x: f32) -> f32; //~ ERROR linking to LLVM intrinsics is experimental
14+
}
15+
16+
fn main(){
17+
}

src/test/run-pass/issue-20313.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(link_llvm_intrinsics)]
11+
12+
extern {
13+
#[link_name = "llvm.sqrt.f32"]
14+
fn sqrt(x: f32) -> f32;
15+
}
16+
17+
fn main(){
18+
}

0 commit comments

Comments
 (0)