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

Add a "raw" option for asm! which ignores format string specifiers #86599

Merged
merged 1 commit into from
Jun 25, 2021

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Jun 24, 2021

This is useful when including raw assembly snippets using include_str!.

@rust-highfive
Copy link
Collaborator

r? @LeSeulArtichaut

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 24, 2021
@rust-log-analyzer

This comment has been minimized.

@LeSeulArtichaut
Copy link
Contributor

I don't think I should be reviewing this. r? @nagisa maybe?

@nagisa
Copy link
Member

nagisa commented Jun 25, 2021

Huh, this is an interesting artifact of the fact that we do not require the assembly fragments to be a literal string. I do wonder, however, if it would perhaps make more sense to automatically consider assembly to be "raw" if the assembly doesn't come from string literals?

I think the ability to interpolate {}s within a separate file is all that straightforward to understand. Is there a design space exploration for this anywhere?

@Amanieu
Copy link
Member Author

Amanieu commented Jun 25, 2021

We do require that asm fragments are string literals: include_str! expands to a string literal.

@nagisa
Copy link
Member

nagisa commented Jun 25, 2021

We do require that asm fragments are string literals: include_str! expands to a string literal.

Hm, confusing, because

fn main() {
    println!(include_str("format"), 42); // where `format` contains `{}`
}

does not work and compiler demands a literal string literal:

error: format argument must be a string literal
 --> test.rs:2:14
  |
2 |     println!(include_str("format"), 42);
  |              ^^^^^^^^^^^^^^^^^^^^^
  |
help: you might be missing a string literal to format with
  |
2 |     println!("{} {}", include_str("format"), 42);
  |              ^^^^^^^^

I wonder why the discrepancy. I bet it'll have something to do with macro expansion order perhaps?

@Amanieu
Copy link
Member Author

Amanieu commented Jun 25, 2021

There's a typo in your code, you forgot the ! after include_str.

@nagisa
Copy link
Member

nagisa commented Jun 25, 2021

Ah, silly me.

@bors r+

@bors
Copy link
Contributor

bors commented Jun 25, 2021

📌 Commit d0443bb has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2021
@bors
Copy link
Contributor

bors commented Jun 25, 2021

⌛ Testing commit d0443bb with merge e6b4c25...

@bors
Copy link
Contributor

bors commented Jun 25, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing e6b4c25 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 25, 2021
@bors bors merged commit e6b4c25 into rust-lang:master Jun 25, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jun 25, 2021
retrage added a commit to retrage/rust-hypervisor-firmware that referenced this pull request Jul 30, 2021
As reported in issue cloud-hypervisor#143, recent nightly rustc fails to compile the
assembly file because it uses AT&T syntax. It is also suggested that use
raw option when using `include_str!` macro.

https://rust-lang.github.io/rfcs/2873-inline-asm.html#options-1
rust-lang/rust#86599

Signed-off-by: Akira Moroo <retrage01@gmail.com>
retrage added a commit to cloud-hypervisor/rust-hypervisor-firmware that referenced this pull request Jul 30, 2021
As reported in issue #143, recent nightly rustc fails to compile the
assembly file because it uses AT&T syntax. It is also suggested that use
raw option when using `include_str!` macro.

https://rust-lang.github.io/rfcs/2873-inline-asm.html#options-1
rust-lang/rust#86599

Signed-off-by: Akira Moroo <retrage01@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants