Add more tests, fix span issue, improve diagnostics.

This commit is contained in:
Charles Lew 2019-09-20 01:48:30 +08:00
parent eb492455f2
commit dda10f2a2a
7 changed files with 96 additions and 4 deletions

View File

@ -2560,6 +2560,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
let whitelist = tcx.target_features_whitelist(LOCAL_CRATE);
let mut inline_span = None;
let mut link_ordinal_span = None;
for attr in attrs.iter() {
if attr.check_name(sym::cold) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
@ -2642,6 +2643,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
} else if attr.check_name(sym::link_name) {
codegen_fn_attrs.link_name = attr.value_str();
} else if attr.check_name(sym::link_ordinal) {
link_ordinal_span = Some(attr.span);
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
codegen_fn_attrs.link_ordinal = ordinal;
}
@ -2747,7 +2749,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
codegen_fn_attrs.export_name = Some(name);
codegen_fn_attrs.link_name = Some(name);
}
check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, inline_span);
check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, link_ordinal_span);
// Internal symbols to the standard library all have no_mangle semantics in
// that they have defined symbol names present in the function name. This
@ -2772,14 +2774,18 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
Some(*ordinal as usize)
} else {
let msg = format!(
"too large ordinal value in link_ordinal value: `{}`",
"ordinal value in `link_ordinal` is too large: `{}`",
&ordinal
);
tcx.sess.span_err(attr.span, &msg);
tcx.sess.struct_span_err(attr.span, &msg)
.note("the value may not exceed `std::usize::MAX`")
.emit();
None
}
} else {
tcx.sess.span_err(attr.span, "illegal ordinal format in link_ordinal");
tcx.sess.struct_span_err(attr.span, "illegal ordinal format in `link_ordinal`")
.note("an unsuffixed integer value, e.g., `1`, is expected")
.emit();
None
}
}

View File

@ -0,0 +1,12 @@
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
#[link(name="foo")]
extern {
#[link_name="foo"]
#[link_ordinal(42)]
//~^ ERROR cannot use `#[link_name]` with `#[link_ordinal]`
fn foo();
}
fn main() {}

View File

@ -0,0 +1,16 @@
warning: the feature `raw_dylib` is incomplete and may cause the compiler to crash
--> $DIR/link-ordinal-and-name.rs:1:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error: cannot use `#[link_name]` with `#[link_ordinal]`
--> $DIR/link-ordinal-and-name.rs:7:5
|
LL | #[link_ordinal(42)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View File

@ -0,0 +1,11 @@
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
#[link(name="foo")]
extern {
#[link_ordinal("JustMonika")]
//~^ ERROR illegal ordinal format in `link_ordinal`
fn foo();
}
fn main() {}

View File

@ -0,0 +1,18 @@
warning: the feature `raw_dylib` is incomplete and may cause the compiler to crash
--> $DIR/link-ordinal-invalid-format.rs:1:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error: illegal ordinal format in `link_ordinal`
--> $DIR/link-ordinal-invalid-format.rs:6:5
|
LL | #[link_ordinal("JustMonika")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: an unsuffixed integer value, e.g., `1`, is expected
error: aborting due to previous error

View File

@ -0,0 +1,11 @@
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
#[link(name="foo")]
extern {
#[link_ordinal(18446744073709551616)]
//~^ ERROR ordinal value in `link_ordinal` is too large: `18446744073709551616`
fn foo();
}
fn main() {}

View File

@ -0,0 +1,18 @@
warning: the feature `raw_dylib` is incomplete and may cause the compiler to crash
--> $DIR/link-ordinal-too-large.rs:1:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error: ordinal value in `link_ordinal` is too large: `18446744073709551616`
--> $DIR/link-ordinal-too-large.rs:6:5
|
LL | #[link_ordinal(18446744073709551616)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the value may not exceed `std::usize::MAX`
error: aborting due to previous error