Skip to content

Commit b9a26bf

Browse files
committed
rollup merge of #20334: nagisa/ffi-llvm
Fixes #20313 r? @huonw
2 parents 656d5bb + f1b6401 commit b9a26bf

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/doc/reference.md

Lines changed: 3 additions & 0 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

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

@@ -327,6 +328,16 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
327328
"the `linkage` attribute is experimental \
328329
and not portable across platforms")
329330
}
331+
332+
let links_to_llvm = match attr::first_attr_value_str_by_name(i.attrs[], "link_name") {
333+
Some(val) => val.get().starts_with("llvm."),
334+
_ => false
335+
};
336+
if links_to_llvm {
337+
self.gate_feature("link_llvm_intrinsics", i.span,
338+
"linking to LLVM intrinsics is experimental");
339+
}
340+
330341
visit::walk_foreign_item(self, i)
331342
}
332343

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)