rust/compiler
Dylan DPC 3f606ceaec
Rollup merge of #95864 - luqmana:inline-asm-unwind-store-miscompile, r=Amanieu
Fix miscompilation of inline assembly with outputs in cases where we emit an invoke instead of call instruction.

We ran into this bug where rustc would segfault while trying to compile certain uses of inline assembly.

Here is a simple repro that demonstrates the issue:
```rust
#![feature(asm_unwind)]

fn main() {
    let _x = String::from("string here just cause we need something with a non-trivial drop");
    let foo: u64;
    unsafe {
        std::arch::asm!(
            "mov {}, 1",
            out(reg) foo,
            options(may_unwind)
        );
    }
    println!("{}", foo);
}
```
([playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=7d6641e83370d2536a07234aca2498ff))

But crucially `feature(asm_unwind)` is not actually needed and this can be triggered on stable as a result of the way async functions/generators are handled in the compiler. e.g.:

```rust
extern crate futures; // 0.3.21

async fn bar() {
    let foo: u64;
    unsafe {
        std::arch::asm!(
            "mov {}, 1",
            out(reg) foo,
        );
    }
    println!("{}", foo);
}

fn main() {
    futures::executor::block_on(bar());
}
```
([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1c7781c34dd4a3e80ae4bd936a0c82fc))

An example of the incorrect LLVM generated:
```llvm
bb1:                                              ; preds = %start
  %1 = invoke i64 asm sideeffect alignstack inteldialect unwind "mov ${0:q}, 1", "=&r,~{dirflag},~{fpsr},~{flags},~{memory}"()
          to label %bb2 unwind label %cleanup, !srcloc !9
  store i64 %1, i64* %foo, align 8

bb2:
[...snip...]
```

The store should not be placed after the asm invoke but rather should be in the normal control flow basic block (`bb2` in this case).

[Here](https://gist.github.com/luqmana/be1af5b64d2cda5a533e3e23a7830b44) is a writeup of the investigation that lead to finding this.
2022-04-11 20:00:42 +02:00
..
rustc Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
rustc_apfloat Addressed comments by @compiler-errors and @bjorn3 2022-03-30 17:04:46 -04:00
rustc_arena mark FIXMES for all the places found that are probably offset_from 2022-03-29 20:18:28 -04:00
rustc_ast better error for binder on associated type bound 2022-04-10 16:41:15 -07:00
rustc_ast_lowering diagnostics: use correct span for const generics 2022-04-04 12:16:20 -07:00
rustc_ast_passes [let_chains] Forbid let inside parentheses 2022-03-31 18:33:05 -03:00
rustc_ast_pretty Remove Nonterminal::NtTT. 2022-03-28 10:03:02 +11:00
rustc_attr
rustc_borrowck Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
rustc_builtin_macros Auto merge of #95697 - klensy:no-strings, r=petrochenkov 2022-04-09 13:15:26 +00:00
rustc_codegen_cranelift Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
rustc_codegen_gcc Use WrappingRange::full instead of hand-rolling it 2022-04-05 13:18:22 +00:00
rustc_codegen_llvm Switch to the 'normal' basic block for writing asm outputs if needed. 2022-04-09 15:25:46 -04:00
rustc_codegen_ssa Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
rustc_const_eval Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
rustc_data_structures Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote 2022-04-09 02:31:24 +00:00
rustc_driver session: opt for enabling directionality markers 2022-04-05 07:01:03 +01:00
rustc_error_codes rework error messages for incorrect inherent impls 2022-03-30 11:23:58 +02:00
rustc_error_messages Suggest replacing typeof(...) with an actual type 2022-04-07 23:40:32 +04:00
rustc_errors session: opt for enabling directionality markers 2022-04-05 07:01:03 +01:00
rustc_expand Rollup merge of #95808 - petrochenkov:fragspec, r=nnethercote 2022-04-09 18:26:28 +02:00
rustc_feature Split fuzzy_provenance_casts into lossy and fuzzy, feature gate and test it 2022-04-08 17:41:28 +02:00
rustc_fs_util
rustc_graphviz
rustc_hir Avoid accessing HIR from MIR queries. 2022-04-10 13:08:36 +02:00
rustc_hir_pretty
rustc_incremental check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
rustc_index Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
rustc_infer Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote 2022-04-09 02:31:24 +00:00
rustc_interface expand: Remove ParseSess::missing_fragment_specifiers 2022-04-09 15:44:19 +03:00
rustc_lexer Reduce max hash in raw strings from u16 to u8 2022-03-23 22:13:55 +01:00
rustc_lint Auto merge of #94527 - oli-obk:undef_scalars, r=nagisa,erikdesjardin 2022-04-05 16:46:13 +00:00
rustc_lint_defs Split fuzzy_provenance_casts into lossy and fuzzy, feature gate and test it 2022-04-08 17:41:28 +02:00
rustc_llvm trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
rustc_log
rustc_macros macros: support translatable suggestions 2022-04-05 07:01:03 +01:00
rustc_metadata rustdoc: Early doc link resolution fixes and refactorings 2022-04-07 00:19:48 +03:00
rustc_middle Auto merge of #95125 - JakobDegen:uninit-variant-rvalue, r=oli-obk 2022-04-11 14:49:30 +00:00
rustc_mir_build interpret: err instead of ICE on size mismatches in to_bits_or_ptr_internal 2022-04-07 16:24:48 -04:00
rustc_mir_dataflow Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
rustc_mir_transform Remove inlining cost of Deinit statements 2022-04-11 10:23:33 -04:00
rustc_monomorphize Use def_key in tcx.item_name when possible. 2022-04-09 10:54:43 +02:00
rustc_parse better error for binder on associated type bound 2022-04-10 16:41:15 -07:00
rustc_parse_format Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
rustc_passes check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
rustc_plugin_impl
rustc_privacy Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errors 2022-03-31 04:57:28 +02:00
rustc_query_impl rework implementation for inherent impls for builtin types 2022-03-30 11:23:58 +02:00
rustc_query_system Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote 2022-04-09 02:31:24 +00:00
rustc_resolve Rollup merge of #95907 - compiler-errors:diag, r=Dylan-DPC 2022-04-11 12:06:57 +02:00
rustc_save_analysis Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errors 2022-03-31 04:57:28 +02:00
rustc_serialize errors: implement fallback diagnostic translation 2022-04-05 07:01:02 +01:00
rustc_session expand: Remove ParseSess::missing_fragment_specifiers 2022-04-09 15:44:19 +03:00
rustc_span Split fuzzy_provenance_casts into lossy and fuzzy, feature gate and test it 2022-04-08 17:41:28 +02:00
rustc_symbol_mangling Do not access HIR to compute symbol_name. 2022-04-10 13:42:47 +02:00
rustc_target trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
rustc_trait_selection Auto merge of #95931 - matthiaskrgr:rollup-1c5zhit, r=matthiaskrgr 2022-04-11 11:12:26 +00:00
rustc_traits Remove opaque type obligation and just register opaque types as they are encountered. 2022-03-28 16:57:45 +00:00
rustc_ty_utils Avoid accessing HIR from MIR queries. 2022-04-10 13:08:36 +02:00
rustc_type_ir Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk" 2022-03-28 16:27:14 +00:00
rustc_typeck Auto merge of #95758 - compiler-errors:issue-54771, r=estebank 2022-04-11 08:31:37 +00:00