Skip to content
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

Handle GCC's write-only inline asm constraint in liveness, borrowck and trans. #9850

Merged
merged 1 commit into from
Oct 18, 2013

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Oct 14, 2013

I've implemented analysis support for the GCC '=' write-only inline asm constraint modifier. I had more changes, for '+' (read+write) as well, but it turns out LLVM doesn't support '+' at all.

I've removed the need for wrapping each output in ExprAddrOf, as that would require unwrapping almost everywhere and it was harder to reason about in borrowck than ExprAssign's LHS.

With this change, rustc will treat (in respect to validity of accessing a local) code like this:

let x: int;
unsafe {
    asm!("mov $1, $0" : "=r"(x) : "r"(5u));
}

as if it were this:

let x : int;
x = 5;

Previously, the local was required to be both mutable and initialized, and the write effect wasn't recorded.

@alexcrichton
Copy link
Member

It looks to be that we have a section of constraints which are all dedicated to "output constraints", but it's possible to have an output constraint which isn't validated to be writable? It seems to me that we should merge all the constraints into one list (having = denote whether it's input or output), or we should leave the lists separate and not require = at all (because it's implied by where it's located). If we need to add the constraint for LLVM, then we can to that at trans time.

Or is there a purpose for having an output constraint without an =?

@eddyb
Copy link
Member Author

eddyb commented Oct 14, 2013

For the following C code:

int main() {
    short port = 0;
    int val = 0;
    asm("in %1, %0" : "a"(val) : "d"(port));
}

GCC gives me this error:

<stdin>: In function ‘main’:
<stdin>:4:5: error: output operand constraint lacks ‘=’
<stdin>:4:5: error: output operand constraint lacks ‘=’
<stdin>:4:5: error: invalid lvalue in asm output 0

while clang just fails validation, without a precise cause (but better location info than GCC):

<stdin>:4:23: error: invalid output constraint 'a' in asm
    asm("in %1, %0" : "a"(val) : "d"(port));}
                      ^
1 error generated.

We can follow the same rule, require '=' at the start of output constraints, and then remove all my .starts_with("=") conditions.

&mut cleanups,
callee::DontAutorefArg)
})
let out_datum = unpack_datum!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be one line, no need to manually wrap. The max line length is 100 characters.

bors added a commit that referenced this pull request Oct 18, 2013
I've implemented analysis support for the [GCC '=' write-only inline asm constraint modifier](http://gcc.gnu.org/onlinedocs/gcc/Modifiers.html). I had more changes, for '+' (read+write) as well, but it turns out LLVM doesn't support '+' at all.

I've removed the need for wrapping each output in ExprAddrOf, as that would require unwrapping almost everywhere and it was harder to reason about in borrowck than ExprAssign's LHS.

With this change, rustc will treat (in respect to validity of accessing a local) code like this:
```rust
let x: int;
unsafe {
    asm!("mov $1, $0" : "=r"(x) : "r"(5u));
}
```
as if it were this:
```rust
let x : int;
x = 5;
```

Previously, the local was required to be both mutable and initialized, and the write effect wasn't recorded.
@bors bors closed this Oct 18, 2013
@bors bors merged commit 7ab0b0c into rust-lang:master Oct 18, 2013
@eddyb eddyb deleted the inline-asm-constraints branch October 18, 2013 11:06
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2022
Preserve `ref` on `infallible_destructuring_match` suggestion

Fixes rust-lang/rust-clippy#7499

changelog: [`infallible_destructuring_match`]: Preserve `ref` on suggestion
lnicola pushed a commit to lnicola/rust that referenced this pull request Mar 3, 2025
Don't filter out private items when completing paths in the same crate. Instead respect the `privateEditable` setting.

Fixes rust-lang#9850
LorrensP-2158466 pushed a commit to LorrensP-2158466/rust that referenced this pull request Mar 5, 2025
Don't filter out private items when completing paths in the same crate. Instead respect the `privateEditable` setting.

Fixes rust-lang#9850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants