Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c4b46ace
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c4b46ace
编写于
2月 09, 2019
作者:
G
gnzlbg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement ffi_returns_twice attribute
上级
bcfb5e8a
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
79 addition
and
0 deletion
+79
-0
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+3
-0
src/librustc_codegen_llvm/attributes.rs
src/librustc_codegen_llvm/attributes.rs
+3
-0
src/librustc_codegen_llvm/llvm/ffi.rs
src/librustc_codegen_llvm/llvm/ffi.rs
+1
-0
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+12
-0
src/librustc_typeck/diagnostics.rs
src/librustc_typeck/diagnostics.rs
+1
-0
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+8
-0
src/rustllvm/RustWrapper.cpp
src/rustllvm/RustWrapper.cpp
+2
-0
src/rustllvm/rustllvm.h
src/rustllvm/rustllvm.h
+1
-0
src/test/codegen/ffi-returns-twice.rs
src/test/codegen/ffi-returns-twice.rs
+15
-0
src/test/ui/feature-gates/feature-gate-ffi_returns_twice.rs
src/test/ui/feature-gates/feature-gate-ffi_returns_twice.rs
+7
-0
src/test/ui/feature-gates/feature-gate-ffi_returns_twice.stderr
...st/ui/feature-gates/feature-gate-ffi_returns_twice.stderr
+11
-0
src/test/ui/ffi_returns_twice.rs
src/test/ui/ffi_returns_twice.rs
+6
-0
src/test/ui/ffi_returns_twice.stderr
src/test/ui/ffi_returns_twice.stderr
+9
-0
未找到文件。
src/librustc/hir/mod.rs
浏览文件 @
c4b46ace
...
...
@@ -2518,6 +2518,9 @@ pub struct CodegenFnAttrFlags: u32 {
/// `#[used]`: indicates that LLVM can't eliminate this function (but the
/// linker can!).
const
USED
=
1
<<
9
;
/// #[ffi_returns_twice], indicates that an extern function can return
/// multiple times
const
FFI_RETURNS_TWICE
=
1
<<
10
;
}
}
...
...
src/librustc_codegen_llvm/attributes.rs
浏览文件 @
c4b46ace
...
...
@@ -223,6 +223,9 @@ pub fn from_fn_attrs(
if
codegen_fn_attrs
.flags
.contains
(
CodegenFnAttrFlags
::
COLD
)
{
Attribute
::
Cold
.apply_llfn
(
Function
,
llfn
);
}
if
codegen_fn_attrs
.flags
.contains
(
CodegenFnAttrFlags
::
FFI_RETURNS_TWICE
)
{
Attribute
::
ReturnsTwice
.apply_llfn
(
Function
,
llfn
);
}
if
codegen_fn_attrs
.flags
.contains
(
CodegenFnAttrFlags
::
NAKED
)
{
naked
(
llfn
,
true
);
}
...
...
src/librustc_codegen_llvm/llvm/ffi.rs
浏览文件 @
c4b46ace
...
...
@@ -114,6 +114,7 @@ pub enum Attribute {
SanitizeMemory
=
22
,
NonLazyBind
=
23
,
OptimizeNone
=
24
,
ReturnsTwice
=
25
,
}
/// LLVMIntPredicate
...
...
src/librustc_typeck/collect.rs
浏览文件 @
c4b46ace
...
...
@@ -2388,6 +2388,18 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
codegen_fn_attrs
.flags
|
=
CodegenFnAttrFlags
::
ALLOCATOR
;
}
else
if
attr
.check_name
(
"unwind"
)
{
codegen_fn_attrs
.flags
|
=
CodegenFnAttrFlags
::
UNWIND
;
}
else
if
attr
.check_name
(
"ffi_returns_twice"
)
{
if
tcx
.is_foreign_item
(
id
)
{
codegen_fn_attrs
.flags
|
=
CodegenFnAttrFlags
::
FFI_RETURNS_TWICE
;
}
else
{
// `#[ffi_returns_twice]` is only allowed `extern fn`s
struct_span_err!
(
tcx
.sess
,
attr
.span
,
E0723
,
"`#[ffi_returns_twice]` may only be used on `extern fn`s"
)
.emit
();
}
}
else
if
attr
.check_name
(
"rustc_allocator_nounwind"
)
{
codegen_fn_attrs
.flags
|
=
CodegenFnAttrFlags
::
RUSTC_ALLOCATOR_NOUNWIND
;
}
else
if
attr
.check_name
(
"naked"
)
{
...
...
src/librustc_typeck/diagnostics.rs
浏览文件 @
c4b46ace
...
...
@@ -4738,4 +4738,5 @@ fn make_recursive_type() -> impl Sized {
E0698
,
// type inside generator must be known in this context
E0719
,
// duplicate values for associated type binding
E0722
,
// Malformed #[optimize] attribute
E0723
,
// `#[ffi_returns_twice]` is only allowed in `extern fn`
}
src/libsyntax/feature_gate.rs
浏览文件 @
c4b46ace
...
...
@@ -290,6 +290,9 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
// The `repr(i128)` annotation for enums.
(
active
,
repr128
,
"1.16.0"
,
Some
(
35118
),
None
),
// Allows the use of `#[ffi_returns_twice]` on extern functions.
(
active
,
ffi_returns_twice
,
"1.34.0"
,
Some
(
58314
),
None
),
// The `unadjusted` ABI; perma-unstable.
//
// rustc internal
...
...
@@ -1128,6 +1131,11 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
"the `#[naked]` attribute
\
is an experimental feature"
,
cfg_fn!
(
naked_functions
))),
(
"ffi_returns_twice"
,
Whitelisted
,
template!
(
Word
),
Gated
(
Stability
::
Unstable
,
"ffi_returns_twice"
,
"the `#[ffi_returns_twice]` attribute
\
is an experimental feature"
,
cfg_fn!
(
ffi_returns_twice
))),
(
"target_feature"
,
Whitelisted
,
template!
(
List
:
r#"enable = "name""#
),
Ungated
),
(
"export_name"
,
Whitelisted
,
template!
(
NameValueStr
:
"name"
),
Ungated
),
(
"inline"
,
Whitelisted
,
template!
(
Word
,
List
:
"always|never"
),
Ungated
),
...
...
src/rustllvm/RustWrapper.cpp
浏览文件 @
c4b46ace
...
...
@@ -190,6 +190,8 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
return
Attribute
::
NonLazyBind
;
case
OptimizeNone
:
return
Attribute
::
OptimizeNone
;
case
ReturnsTwice
:
return
Attribute
::
ReturnsTwice
;
}
report_fatal_error
(
"bad AttributeKind"
);
}
...
...
src/rustllvm/rustllvm.h
浏览文件 @
c4b46ace
...
...
@@ -85,6 +85,7 @@ enum LLVMRustAttribute {
SanitizeMemory
=
22
,
NonLazyBind
=
23
,
OptimizeNone
=
24
,
ReturnsTwice
=
25
,
};
typedef
struct
OpaqueRustString
*
RustStringRef
;
...
...
src/test/codegen/ffi-returns-twice.rs
0 → 100644
浏览文件 @
c4b46ace
// compile-flags: -C no-prepopulate-passes
#![crate_type
=
"lib"
]
#![feature(ffi_returns_twice)]
extern
{
// CHECK-LABEL: @foo()
// CHECK: attributes #1 = { {{.*}}returns_twice{{.*}} }
#[no_mangle]
#[ffi_returns_twice]
pub
fn
foo
();
}
pub
fn
bar
()
{
unsafe
{
foo
()
}
}
src/test/ui/feature-gates/feature-gate-ffi_returns_twice.rs
0 → 100644
浏览文件 @
c4b46ace
// ignore-tidy-linelength
#![crate_type
=
"lib"
]
extern
{
#[ffi_returns_twice]
//~ ERROR the `#[ffi_returns_twice]` attribute is an experimental feature (see issue #58314)
pub
fn
foo
();
}
src/test/ui/feature-gates/feature-gate-ffi_returns_twice.stderr
0 → 100644
浏览文件 @
c4b46ace
error[E0658]: the `#[ffi_returns_twice]` attribute is an experimental feature (see issue #58314)
--> $DIR/feature-gate-ffi_returns_twice.rs:5:5
|
LL | #[ffi_returns_twice] //~ ERROR the `#[ffi_returns_twice]` attribute is an experimental feature (see issue #58314)
| ^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(ffi_returns_twice)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.
src/test/ui/ffi_returns_twice.rs
0 → 100644
浏览文件 @
c4b46ace
// ignore-tidy-linelength
#![feature(ffi_returns_twice)]
#![crate_type
=
"lib"
]
#[ffi_returns_twice]
//~ ERROR `#[ffi_returns_twice]` may only be used on `extern fn`s
pub
fn
foo
()
{}
src/test/ui/ffi_returns_twice.stderr
0 → 100644
浏览文件 @
c4b46ace
error[E0723]: `#[ffi_returns_twice]` may only be used on `extern fn`s
--> $DIR/ffi_returns_twice.rs:5:1
|
LL | #[ffi_returns_twice] //~ ERROR `#[ffi_returns_twice]` may only be used on `extern fn`s
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0723`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录