Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gcc/rust/util/rust-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,13 @@ AttributeChecker::visit (AST::Function &fun)
"must be of the form: %<#[target_feature(enable = "
"\"name\")]%>");
}
else if (!fun.get_qualifiers ().is_unsafe ())
{
rust_error_at (
attribute.get_locus (),
"the %<#[target_feature]%> attribute can only be applied "
"to %<unsafe%> functions");
}
}
else if (result.name == "no_mangle")
{
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/issue-4234.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// { dg-options "-w" }
#[target_feature(sse)] // { dg-error "attribute can only be applied" }
fn foo() {}
5 changes: 3 additions & 2 deletions gcc/testsuite/rust/compile/unsafe11.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[target_feature(sse)]
fn foo() {
unsafe fn foo() {
let a: usize = 0;
}

fn main() {
foo() // { dg-error "requires unsafe function or block" }
foo(); // { dg-error "requires unsafe function or block" }
unsafe { foo(); }
}