-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inline assembly #12798
Fix inline assembly #12798
Conversation
Can you rebase out the changes from #12797? |
@alexcrichton it looks like the asm changes use the changes from #12797. |
Done. I don't have more ideas other than refactoring. I.e. the body of state = match (p.token, next_state(state), next_state(next_state(state))) {
(token::COLON, StateNone, _) |
(token::MOD_SEP, _, StateNone) => {
p.bump();
break 'statement;
}
(token::COLON, st, _) |
(token::MOD_SEP, _, st) => {
p.bump();
st
}
(token::EOF, _) => break 'statement,
_ => state
} |
While you're at it, do you think you could write some documentation for this feature? There's not really a great place that I know of for the documentation, but docs in Also, could you edit the title of the PR to not have "WIP" in the name, and also squash the commits together? |
There is a chunk of docs https://github.com/mozilla/rust/wiki/Doc-detailed-release-notes#wiki-inline-assembly but not in a very useful/obvious place... and no code examples are tested. Maybe we could have a That said, I'd personally be happy with this happening in a different PR. |
@@ -135,6 +142,10 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) | |||
let (s, _str_style) = p.parse_str(); | |||
let clob = format!("~\\{{}\\}", s); | |||
clobs.push(clob); | |||
|
|||
if s.equiv(&("volatile")) || s.equiv(&("alignstack")) || s.equiv(&("intel")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be "volatile" == s || "alignstack" == s || "intel" == s
, although maybe it would be even better (aka more extensible) as
static OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"];
// ...
if OPTIONS.iter().any(|opt| *opt == *s) { .. .}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@huonw Can I write "volatile" == option
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's an InternedString
error: mismatched types: expected `&str` but found `parse::token::InternedString`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my apologies, thought they were just ~str
s. In that case, .equiv
is good.
The problem is these examples can only be tested for x86 and x86_64. I will try to document this feature. GCC inline asm is extensively described here: http://locklessinc.com/articles/gcc_asm/ Should I squash all commits? |
I'm ok if you want to defer documentation for later, but yes, it would be nice to have the commits all squashed. |
Read+write modifier Some documentation in asm.rs rpass and cfail tests
Done |
## read+write modifier '+' This small sugar was left out in the original implementation (#5359). When an output operand with the '+' modifier is encountered, we store the index of that operand alongside the expression to create and append an input operand later. The following lines are equivalent: ``` asm!("" : "+m"(expr)); asm!("" : "=m"(expr) : "0"(expr)); ``` ## misplaced options and clobbers give a warning It's really annoying when a small typo might change behavior without any warning. ``` asm!("mov $1, $0" : "=r"(x) : "r"(8u) : "cc" , "volatile"); //~^ WARNING expected a clobber, but found an option ``` ## liveness Fixed incorrect order of propagation. Sometimes it caused spurious warnings in code: `warning: value assigned to `i` is never read, #[warn(dead_assignment)] on by default` ~~Note: Rebased on top of another PR. (uses other changes)~~ * [x] Implement read+write * [x] Warn about misplaced options * [x] Fix liveness (`dead_assignment` lint) * [x] Add all tests
… r=jonas-schievink internal: Remove outdated proc macro ABIs Drops support for 1.48 to 1.57. We still support 1.58+, which is 4 versions out of date, so that should be plenty.
…r=y21 Don't lint path statements in no_effect The rustc lint `path_statements` covers this case Fixes rust-lang#11547 changelog: none
read+write modifier '+'
This small sugar was left out in the original implementation (#5359).
When an output operand with the '+' modifier is encountered, we store the index of that operand alongside the expression to create and append an input operand later. The following lines are equivalent:
misplaced options and clobbers give a warning
It's really annoying when a small typo might change behavior without any warning.
liveness
Fixed incorrect order of propagation.
Sometimes it caused spurious warnings in code:
warning: value assigned to
iis never read, #[warn(dead_assignment)] on by default
Note: Rebased on top of another PR. (uses other changes)dead_assignment
lint)