rust/tests/ui/proc-macro
Matthias Krüger 7d78885a8e
Rollup merge of #111891 - rustbox:feat/riscv-isr-cconv, r=jackh726
feat: `riscv-interrupt-{m,s}` calling conventions

Similar to prior support added for the mips430, avr, and x86 targets this change implements the rough equivalent of clang's [`__attribute__((interrupt))`][clang-attr] for riscv targets, enabling e.g.

```rust
static mut CNT: usize = 0;

pub extern "riscv-interrupt-m" fn isr_m() {
    unsafe {
        CNT += 1;
    }
}
```

to produce highly effective assembly like:

```asm
pub extern "riscv-interrupt-m" fn isr_m() {
420003a0:       1141                    addi    sp,sp,-16
    unsafe {
        CNT += 1;
420003a2:       c62a                    sw      a0,12(sp)
420003a4:       c42e                    sw      a1,8(sp)
420003a6:       3fc80537                lui     a0,0x3fc80
420003aa:       63c52583                lw      a1,1596(a0) # 3fc8063c <_ZN12esp_riscv_rt3CNT17hcec3e3a214887d53E.0>
420003ae:       0585                    addi    a1,a1,1
420003b0:       62b52e23                sw      a1,1596(a0)
    }
}
420003b4:       4532                    lw      a0,12(sp)
420003b6:       45a2                    lw      a1,8(sp)
420003b8:       0141                    addi    sp,sp,16
420003ba:       30200073                mret
```

(disassembly via `riscv64-unknown-elf-objdump -C -S --disassemble ./esp32c3-hal/target/riscv32imc-unknown-none-elf/release/examples/gpio_interrupt`)

This outcome is superior to hand-coded interrupt routines which, lacking visibility into any non-assembly body of the interrupt handler, have to be very conservative and save the [entire CPU state to the stack frame][full-frame-save]. By instead asking LLVM to only save the registers that it uses, we defer the decision to the tool with the best context: it can more accurately account for the cost of spills if it knows that every additional register used is already at the cost of an implicit spill.

At the LLVM level, this is apparently [implemented by] marking every register as "[callee-save]," matching the semantics of an interrupt handler nicely (it has to leave the CPU state just as it found it after its `{m|s}ret`).

This approach is not suitable for every interrupt handler, as it makes no attempt to e.g. save the state in a user-accessible stack frame. For a full discussion of those challenges and tradeoffs, please refer to [the interrupt calling conventions RFC][rfc].

Inside rustc, this implementation differs from prior art because LLVM does not expose the "all-saved" function flavor as a calling convention directly, instead preferring to use an attribute that allows for differentiating between "machine-mode" and "superivsor-mode" interrupts.

Finally, some effort has been made to guide those who may not yet be aware of the differences between machine-mode and supervisor-mode interrupts as to why no `riscv-interrupt` calling convention is exposed through rustc, and similarly for why `riscv-interrupt-u` makes no appearance (as it would complicate future LLVM upgrades).

[clang-attr]: https://clang.llvm.org/docs/AttributeReference.html#interrupt-risc-v
[full-frame-save]: 9281af2ecf/src/lib.rs (L440-L469)
[implemented by]: b7fb2a3fec/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp (L61-L67)
[callee-save]: 973f1fe7a8/llvm/lib/Target/RISCV/RISCVCallingConv.td (L30-L37)
[rfc]: https://github.com/rust-lang/rfcs/pull/3246
2023-08-09 22:59:58 +02:00
..
auxiliary fix proc-macro test added here to solely be exercised as a build product for the host. 2023-08-08 11:40:35 -04:00
debug
outer
pretty-print-hack
add-impl.rs
allowed-attr-stmt-expr.rs
allowed-attr-stmt-expr.stdout
allowed-signatures.rs
ambiguous-builtin-attrs-test.rs
ambiguous-builtin-attrs-test.stderr
ambiguous-builtin-attrs.rs
ambiguous-builtin-attrs.stderr
amputate-span.fixed
amputate-span.rs
amputate-span.stderr
append-impl.rs
attr-args.rs
attr-cfg.rs
attr-complex-fn.rs
attr-complex-fn.stdout
attr-invalid-exprs.rs
attr-invalid-exprs.stderr
attr-on-trait.rs
attr-stmt-expr-rpass.rs
attr-stmt-expr.rs
attr-stmt-expr.stderr
attr-stmt-expr.stdout
attribute-after-derive.rs
attribute-after-derive.stdout
attribute-spans-preserved.rs
attribute-spans-preserved.stderr
attribute-spans-preserved.stdout
attribute-with-error.rs
attribute-with-error.stderr
attribute.rs
attribute.stderr
attributes-included.rs
attributes-included.stderr
attributes-on-definitions.rs
attributes-on-definitions.stderr
attributes-on-modules-fail.rs
attributes-on-modules-fail.stderr
attributes-on-modules.rs
bad-projection.rs
bad-projection.stderr
bang-macro.rs
break-token-spans.rs
break-token-spans.stderr
call-deprecated.rs
call-deprecated.stderr
call-site.rs
capture-macro-rules-invoke.rs
capture-macro-rules-invoke.stdout
capture-unglued-token.rs
capture-unglued-token.stdout
cfg-eval-fail.rs
cfg-eval-fail.stderr
cfg-eval-inner.rs
cfg-eval-inner.stdout
cfg-eval.rs
cfg-eval.stdout
count_compound_ops.rs
crate-attrs-multiple.rs
crate-var.rs
crt-static.rs
custom-attr-only-one-derive.rs
define-two.rs
define-two.stderr
derive-attr-cfg.rs
derive-b.rs
derive-bad.rs
derive-bad.stderr
derive-expand-order.rs
derive-expand-order.stdout
derive-helper-configured.rs
derive-helper-legacy-limits.rs
derive-helper-legacy-limits.stderr
derive-helper-legacy-spurious.rs
derive-helper-legacy-spurious.stderr
derive-helper-shadowed.rs
derive-helper-shadowing-2.rs
derive-helper-shadowing.rs
derive-helper-shadowing.stderr
derive-helper-vs-legacy.rs
derive-in-mod.rs
derive-multiple-with-packed.rs
derive-same-struct.rs
derive-same-struct.stdout
derive-still-gated.rs
derive-still-gated.stderr
derive-test.rs
derive-two-attrs.rs
derive-union.rs
disappearing-resolution.rs
disappearing-resolution.stderr
doc-comment-preserved.rs
doc-comment-preserved.stdout
dollar-crate-issue-57089.rs
dollar-crate-issue-57089.stdout
dollar-crate-issue-62325.rs
dollar-crate-issue-62325.stdout
dollar-crate-issue-101211.rs
dollar-crate.rs
dollar-crate.stdout
edition-imports-2018.rs
empty-crate.rs
empty-where-clause.rs
empty-where-clause.stderr
expand-expr.rs
expand-expr.stderr
expand-to-derive.rs
expand-to-derive.stdout
expand-to-unstable.rs
expand-to-unstable.stderr
expand-with-a-macro.rs
export-macro.rs
export-macro.stderr
exports.rs
exports.stderr
expr-stmt-nonterminal-tokens.rs
expr-stmt-nonterminal-tokens.stdout
extern-prelude-extern-crate-proc-macro.rs
gen-lifetime-token.rs
gen-macro-rules-hygiene.rs
gen-macro-rules-hygiene.stderr
gen-macro-rules.rs
generate-dollar-ident.rs
generate-mod.rs
generate-mod.stderr
helper-attr-blocked-by-import-ambig.rs
helper-attr-blocked-by-import-ambig.stderr
helper-attr-blocked-by-import.rs
hygiene_example.rs
illegal-proc-macro-derive-use.rs
illegal-proc-macro-derive-use.stderr
import.rs
import.stderr
inert-attribute-order.rs
inert-attribute-order.stdout
inner-attr-non-inline-mod.rs
inner-attr-non-inline-mod.stderr
inner-attr-non-inline-mod.stdout
inner-attrs.rs
inner-attrs.stderr
inner-attrs.stdout
input-interpolated.rs
input-interpolated.stdout
invalid-attributes.rs
invalid-attributes.stderr
invalid-punct-ident-1.rs
invalid-punct-ident-1.stderr
invalid-punct-ident-2.rs
invalid-punct-ident-2.stderr
invalid-punct-ident-3.rs
invalid-punct-ident-3.stderr
invalid-punct-ident-4.rs
invalid-punct-ident-4.stderr
is-available.rs
issue-36935.rs
issue-36935.stderr
issue-37788.rs
issue-37788.stderr
issue-38586.rs
issue-38586.stderr
issue-39889.rs
issue-42708.rs
issue-50061.rs
issue-50493.rs
issue-50493.stderr
issue-53481.rs
issue-59191-replace-root-with-fn.rs
issue-59191-replace-root-with-fn.stderr
issue-66286.rs
issue-66286.stderr
issue-73933-procedural-masquerade.rs
issue-73933-procedural-masquerade.stdout
issue-75734-pp-paren.rs
issue-75734-pp-paren.stdout
issue-75801.rs
issue-75801.stderr
issue-75930-derive-cfg.rs
issue-75930-derive-cfg.stderr
issue-75930-derive-cfg.stdout
issue-76182-leading-vert-pat.rs
issue-76182-leading-vert-pat.stdout
issue-76270-panic-in-libproc-macro.rs
issue-76270-panic-in-libproc-macro.stderr
issue-78675-captured-inner-attrs.rs
issue-78675-captured-inner-attrs.stdout
issue-79148.rs
issue-79148.stderr
issue-79242-slow-retokenize-check.rs
issue-79825.rs
issue-80760-empty-stmt.rs
issue-80760-empty-stmt.stdout
issue-81007-item-attrs.rs
issue-81007-item-attrs.stdout
issue-81543-item-parse-err.rs
issue-81543-item-parse-err.stderr
issue-81555.rs
issue-83469-global-alloc-invalid-stmt.rs
issue-83469-global-alloc-invalid-stmt.stderr
issue-83510.rs
issue-83510.stderr
issue-86781-bad-inner-doc.fixed
issue-86781-bad-inner-doc.rs
issue-86781-bad-inner-doc.stderr
issue-91800.rs
issue-91800.stderr
issue-104884-trait-impl-sugg-err.rs
issue-104884-trait-impl-sugg-err.stderr
issue-107113-wrap.rs Fix #107113, avoid suggest for macro attributes 2023-08-02 14:54:37 +08:00
issue-107113-wrap.stderr Fix #107113, avoid suggest for macro attributes 2023-08-02 14:54:37 +08:00
item-error.rs
item-error.stderr
keep-expr-tokens.rs
keep-expr-tokens.stderr
keep-expr-tokens.stdout
lifetimes-rpass.rs
lifetimes.rs
lifetimes.stderr
lints_in_proc_macros.rs
lints_in_proc_macros.stderr
load-panic-backtrace.rs
load-panic-backtrace.stderr Change default panic handler message format. 2023-07-29 11:42:50 +02:00
load-panic.rs
load-panic.stderr
load-two.rs
macro-brackets.rs
macro-brackets.stderr
macro-crate-multi-decorator.rs
macro-namespace-reserved-2.rs
macro-namespace-reserved-2.stderr
macro-namespace-reserved.rs
macro-namespace-reserved.stderr
macro-quote-cond.rs
macro-rules-derive-cfg.rs
macro-rules-derive-cfg.stdout
macro-rules-derive.rs
macro-rules-derive.stderr
macro-use-attr.rs
macro-use-bang.rs
macros-in-extern-derive.rs
macros-in-extern-derive.stderr
macros-in-extern.rs
macros-in-type.rs
meta-delim.rs
meta-macro-hygiene.rs fix(test): improve sensitivity of hygene tests 2023-08-08 18:09:56 -07:00
meta-macro-hygiene.stdout fix(test): improve sensitivity of hygene tests 2023-08-08 18:09:56 -07:00
meta-macro.rs
meta-macro.stdout
mixed-site-span.rs
mixed-site-span.stderr
modify-ast.rs
module_with_attrs.rs
module.rs
multispan.rs
multispan.stderr
negative-token.rs
nested-derive-cfg.rs
nested-derive-cfg.stdout
nested-item-spans.rs
nested-item-spans.stderr
nested-macro-rules.rs
nested-macro-rules.stdout
nested-nonterminal-tokens.rs
nested-nonterminal-tokens.stdout
no-macro-use-attr.rs
no-macro-use-attr.stderr
no-mangle-in-proc-macro-issue-111888.rs fix proc-macro test added here to solely be exercised as a build product for the host. 2023-08-08 11:40:35 -04:00
no-missing-docs.rs
nodelim-groups.rs
nodelim-groups.stdout
non-root.rs
non-root.stderr
nonterminal-expansion.rs
nonterminal-expansion.stdout
nonterminal-recollect-attr.rs
nonterminal-recollect-attr.stdout
nonterminal-token-hygiene.rs fix(test): improve sensitivity of hygene tests 2023-08-08 18:09:56 -07:00
nonterminal-token-hygiene.stdout fix(test): improve sensitivity of hygene tests 2023-08-08 18:09:56 -07:00
not-joint.rs
out-of-line-mod.rs
panic-abort.rs
panic-abort.stderr
parent-source-spans.rs
parent-source-spans.stderr
pretty-print-hack-hide.rs
pretty-print-hack-hide.stdout
pretty-print-hack-show.local.stderr
pretty-print-hack-show.local.stdout
pretty-print-hack-show.remapped.stderr
pretty-print-hack-show.remapped.stdout
pretty-print-hack-show.rs
pretty-print-tts.rs
pretty-print-tts.stdout
proc-macro-abi.rs
proc-macro-abi.stderr
proc-macro-attributes.rs
proc-macro-attributes.stderr
proc-macro-deprecated-attr.rs
proc-macro-gates2.rs
proc-macro-gates2.stderr
proc-macro-gates.rs
proc-macro-gates.stderr
pub-at-crate-root.rs
pub-at-crate-root.stderr
quote-debug.rs
quote-debug.stdout
raw-ident.rs
raw-ident.stderr
reserved-macro-names.rs
reserved-macro-names.stderr
resolve-error.rs
resolve-error.stderr
resolved-located-at.rs
resolved-located-at.stderr
shadow.rs
shadow.stderr
signature-proc-macro-attribute.rs
signature-proc-macro-attribute.stderr
signature-proc-macro-derive.rs
signature-proc-macro-derive.stderr
signature-proc-macro.rs
signature-proc-macro.stderr
signature.rs
signature.stderr
smoke.rs
span-absolute-posititions.rs
span-absolute-posititions.stderr
span-api-tests.rs
span-from-proc-macro.rs
span-from-proc-macro.stderr
span-preservation.rs
span-preservation.stderr
struct-field-macro.rs
subspan.rs
subspan.stderr
test-same-crate.rs
test-same-crate.stderr
test.rs
three-equals.rs
three-equals.stderr
trailing-plus.rs
trailing-plus.stdout
trait-fn-args-2015.rs
two-crate-types-1.rs
two-crate-types-1.stderr
two-crate-types-2.rs
two-crate-types-2.stderr
unsafe-foreign-mod.rs
unsafe-mod.rs
visibility-path.rs
visibility-path.stderr
weird-braces.rs
weird-braces.stdout
weird-hygiene.rs
weird-hygiene.stderr