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

String literals in asm!() and ABIs are not escaped #60493

Closed
petrochenkov opened this issue May 2, 2019 · 2 comments · Fixed by #66271
Closed

String literals in asm!() and ABIs are not escaped #60493

petrochenkov opened this issue May 2, 2019 · 2 comments · Fixed by #66271
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-grammar Area: The grammar of Rust A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@petrochenkov
Copy link
Contributor

petrochenkov commented May 2, 2019

String literals in asm!()'s outputs, inputs, clobbers and options are lexed like usual non-raw strings (asm!("something" : "outputs" : "inputs" : "clobbers" : "options")).
String literals in ABI specifications are also lexed like usual non-raw strings (extern "C" fn f();).
In particular, all escapes are checked for correctness and corresponding errors are reported.

However, during parsing strings from those literals are directly transplanted into AST.
Directly means all those sweet \r\ns are preserved, that's even raw-er than raw string literals!
That's not good.

Proposed solutions:

  • Alternative 1: Treat them as usual non-raw literals and escape properly.
    That would mean extern "\x43" fn f(); being legal code.
    This is slightly weird, but extern r#"C"# fn f() {} is already accepted, if we are talking about weird.
  • Alternative 2: Treat them as implicitly raw during parsing (share the same code path with raw literals), but not during lexing (cannot do that without an explicit lexical marker).
    This is slightly weird because lexing errors about escaping make no sense if the escaping is not even used.

I tend to prefer the first alternative for simplicity/consistency - "..." means non-raw, r"..." means raw, end of the story.

@petrochenkov petrochenkov added A-frontend Area: Compiler frontend (errors, parsing and HIR) A-grammar Area: The grammar of Rust labels May 2, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels May 3, 2019
@Centril Centril added the A-inline-assembly Area: Inline assembly (`asm!(…)`) label May 3, 2019
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Oct 25, 2019
@Centril
Copy link
Contributor

Centril commented Oct 30, 2019

The extern aspect of this ticket is fixed by #65884. The ASM part remains but is low priority (as inline assembly is).

@Centril Centril added P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 30, 2019
@petrochenkov
Copy link
Contributor Author

Fixed in #66271.

Centril added a commit to Centril/rust that referenced this issue Nov 17, 2019
syntax: Keep string literals in ABIs and `asm!` more precisely

As a result we don't lose spans when `extern` functions or blocks are passed to proc macros, and also escape all string literals consistently.
Continuation of rust-lang#60679, which did a similar thing with all literals besides those in ABIs and `asm!`.

TODO: Add tests.

Fixes rust-lang#60493
Fixes rust-lang#64561
r? @Centril
@bors bors closed this as completed in b83d50d Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-grammar Area: The grammar of Rust A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants