Validate export_name attribute
This commit is contained in:
@@ -1692,9 +1692,9 @@ pub fn build_return_block<'blk, 'tcx>(fcx: &FunctionContext<'blk, 'tcx>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// trans_closure: Builds an LLVM function out of a source function.
|
/// Builds an LLVM function out of a source function.
|
||||||
// If the function closes over its environment a closure will be
|
///
|
||||||
// returned.
|
/// If the function closes over its environment a closure will be returned.
|
||||||
pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||||
decl: &ast::FnDecl,
|
decl: &ast::FnDecl,
|
||||||
body: &ast::Block,
|
body: &ast::Block,
|
||||||
@@ -1827,8 +1827,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||||||
finish_fn(&fcx, bcx, output_type, ret_debug_loc);
|
finish_fn(&fcx, bcx, output_type, ret_debug_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// trans_fn: creates an LLVM function corresponding to a source language
|
/// Creates an LLVM function corresponding to a source language function.
|
||||||
// function.
|
|
||||||
pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||||
decl: &ast::FnDecl,
|
decl: &ast::FnDecl,
|
||||||
body: &ast::Block,
|
body: &ast::Block,
|
||||||
@@ -2645,10 +2644,9 @@ fn exported_name<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, id: ast::NodeId,
|
|||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
match attr::first_attr_value_str_by_name(attrs, "export_name") {
|
match attr::find_export_name_attr(ccx.sess().diagnostic(), attrs) {
|
||||||
// Use provided name
|
// Use provided name
|
||||||
Some(name) => name.to_string(),
|
Some(name) => name.to_string(),
|
||||||
|
|
||||||
_ => ccx.tcx().map.with_path(id, |path| {
|
_ => ccx.tcx().map.with_path(id, |path| {
|
||||||
if attr::contains_name(attrs, "no_mangle") {
|
if attr::contains_name(attrs, "no_mangle") {
|
||||||
// Don't mangle
|
// Don't mangle
|
||||||
|
|||||||
@@ -282,6 +282,23 @@ pub fn find_crate_name(attrs: &[Attribute]) -> Option<InternedString> {
|
|||||||
first_attr_value_str_by_name(attrs, "crate_name")
|
first_attr_value_str_by_name(attrs, "crate_name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Find the value of #[export_name=*] attribute and check its validity.
|
||||||
|
pub fn find_export_name_attr(diag: &SpanHandler, attrs: &[Attribute]) -> Option<InternedString> {
|
||||||
|
attrs.iter().fold(None, |ia,attr| {
|
||||||
|
if attr.check_name("export_name") {
|
||||||
|
if let s@Some(_) = attr.value_str() {
|
||||||
|
s
|
||||||
|
} else {
|
||||||
|
diag.span_err(attr.span, "export_name attribute has invalid format");
|
||||||
|
diag.handler.help("use #[export_name=\"*\"]");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ia
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
pub enum InlineAttr {
|
pub enum InlineAttr {
|
||||||
None,
|
None,
|
||||||
|
|||||||
Reference in New Issue
Block a user