From 67aca498c6b17b8888f17c5035e2c6f257e32c5c Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Mon, 23 May 2022 09:20:57 -0500 Subject: [PATCH 1/6] Put a bound on collection misbehavior As currently written, when a logic error occurs in a collection's trait parameters, this allows *completely arbitrary* misbehavior, so long as it does not cause undefined behavior in std. However, because the extent of misbehavior is not specified, it is allowed for *any* code in std to start misbehaving in arbitrary ways which are not formally UB; consider the theoretical example of a global which gets set on an observed logic error. Because the misbehavior is only bound by not resulting in UB from safe APIs and the crate-level encapsulation boundary of all of std, this makes writing user unsafe code that utilizes std theoretically impossible, as it now relies on undocumented QOI that unrelated parts of std cannot be caused to misbehave by a misuse of std::collections APIs. In practice, this is a nonconcern, because std has reasonable QOI and an implementation that takes advantage of this freedom is essentially a malicious implementation and only compliant by the most langauage-lawyer reading of the documentation. To close this hole, we just add a small clause to the existing logic error paragraph that ensures that any misbehavior is limited to the collection which observed the logic error, making it more plausible to prove the soundness of user unsafe code. This is not meant to be formal; a formal refinement would likely need to mention that values derived from the collection can also misbehave after a logic error is observed, as well as define what it means to "observe" a logic error in the first place. This fix errs on the side of informality in order to close the hole without complicating a normal reading which can assume a reasonable nonmalicious QOI. See also [discussion on IRLO][1]. [1]: https://internals.rust-lang.org/t/using-std-collections-and-unsafe-anything-can-happen/16640 --- library/alloc/src/collections/binary_heap.rs | 7 ++++--- library/alloc/src/collections/btree/map.rs | 6 +++--- library/alloc/src/collections/btree/set.rs | 6 +++--- library/std/src/collections/hash/map.rs | 3 ++- library/std/src/collections/hash/set.rs | 15 ++++++++------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index c3c1d0c92a86b..839088eac21ea 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -166,9 +166,10 @@ mod tests; /// item's ordering relative to any other item, as determined by the [`Ord`] /// trait, changes while it is in the heap. This is normally only possible /// through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. The -/// behavior resulting from such a logic error is not specified (it -/// could include panics, incorrect results, aborts, memory leaks, or -/// non-termination) but will not be undefined behavior. +/// behavior resulting from such a logic error is not specified, but will +/// be encapsulated to the `BinaryHeap` that observed the logic error and not +/// result in undefined behavior. This could include panics, incorrect results, +/// aborts, memory leaks, and non-termination. /// /// # Examples /// diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 264c217c9ef23..28b44e3acb9da 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -64,9 +64,9 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; /// It is a logic error for a key to be modified in such a way that the key's ordering relative to /// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is /// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified (it could include panics, -/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined -/// behavior. +/// The behavior resulting from such a logic error is not specified, but will be encapsulated to the +/// `BTreeSet` that observed the logic error and not result in undefined behavior. This could +/// include panics, incorrect results, aborts, memory leaks, and non-termination. /// /// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::values`], or /// [`BTreeMap::keys`] produce their items in order by key, and take worst-case logarithmic and diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index d6733425288d4..20ef834eaeef3 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -23,9 +23,9 @@ use super::Recover; /// It is a logic error for an item to be modified in such a way that the item's ordering relative /// to any other item, as determined by the [`Ord`] trait, changes while it is in the set. This is /// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified (it could include panics, -/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined -/// behavior. +/// The behavior resulting from such a logic error is not specified, but will be encapsulated to the +/// `BTreeSet` that observed the logic error and not result in undefined behavior. This could +/// include panics, incorrect results, aborts, memory leaks, and non-termination. /// /// Iterators returned by [`BTreeSet::iter`] produce their items in order, and take worst-case /// logarithmic and amortized constant time per item returned. diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 969f5dde4f05d..4ec423eb27f31 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -54,7 +54,8 @@ use crate::sys; /// the [`Eq`] trait, changes while it is in the map. This is normally only /// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. /// The behavior resulting from such a logic error is not specified, but will -/// not result in undefined behavior. This could include panics, incorrect results, +/// be encapsulated to the `HashMap` that observed the logic error and not +/// result in undefined behavior. This could include panics, incorrect results, /// aborts, memory leaks, and non-termination. /// /// The hash table implementation is a Rust port of Google's [SwissTable]. diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 4ac0e081c2e2d..da0572047eca8 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -33,13 +33,14 @@ use super::map::{map_try_reserve_error, RandomState}; /// In other words, if two keys are equal, their hashes must be equal. /// /// -/// It is a logic error for an item to be modified in such a way that the -/// item's hash, as determined by the [`Hash`] trait, or its equality, as -/// determined by the [`Eq`] trait, changes while it is in the set. This is -/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or -/// unsafe code. The behavior resulting from such a logic error is not -/// specified (it could include panics, incorrect results, aborts, memory -/// leaks, or non-termination) but will not be undefined behavior. +/// It is a logic error for a key to be modified in such a way that the key's +/// hash, as determined by the [`Hash`] trait, or its equality, as determined by +/// the [`Eq`] trait, changes while it is in the map. This is normally only +/// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. +/// The behavior resulting from such a logic error is not specified, but will +/// be encapsulated to the `HashSet` that observed the logic error and not +/// result in undefined behavior. This could include panics, incorrect results, +/// aborts, memory leaks, and non-termination. /// /// # Examples /// From 0462cc3d96506adc1dd5b43551f05aadbec034f1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 8 Apr 2022 18:20:57 +0300 Subject: [PATCH 2/6] Stabilize the `bundle` native library modifier --- compiler/rustc_codegen_ssa/src/back/link.rs | 4 +-- .../src/error_codes/E0060.md | 4 +-- compiler/rustc_feature/src/accepted.rs | 2 ++ compiler/rustc_feature/src/active.rs | 4 --- compiler/rustc_feature/src/removed.rs | 3 +++ compiler/rustc_metadata/src/native_libs.rs | 19 -------------- compiler/rustc_session/src/config.rs | 20 +------------- library/unwind/src/lib.rs | 2 +- src/doc/rustc/src/command-line-arguments.md | 20 ++++++++++++++ .../native-link-modifiers-bundle.md | 19 -------------- .../static-nobundle/Makefile | 23 ---------------- .../run-make-fulldeps/static-nobundle/bbb.rs | 13 ---------- .../run-make-fulldeps/static-nobundle/ccc.rs | 13 ---------- .../run-make-fulldeps/static-nobundle/ddd.rs | 7 ----- src/test/run-make-fulldeps/tools.mk | 2 +- .../native-link-modifier-bundle/Makefile | 26 +++++++++++++++++++ .../native-link-modifier-bundle/bundled.rs | 11 ++++++++ .../cdylib-bundled.rs | 1 + .../cdylib-non-bundled.rs | 1 + .../native-staticlib.c} | 0 .../non-bundled.rs | 11 ++++++++ .../Makefile | 4 +-- .../native_lib_in_src.rs | 2 -- ...ure-gate-native_link_modifiers_bundle-2.rs | 9 ------- ...ure-gate-native_link_modifiers_bundle-3.rs | 3 --- ...gate-native_link_modifiers_bundle-3.stderr | 2 -- ...ature-gate-native_link_modifiers_bundle.rs | 5 ---- ...e-gate-native_link_modifiers_bundle.stderr | 12 --------- .../feature-gate-static-nobundle-2.rs | 4 --- .../feature-gate-static-nobundle-2.stderr | 2 -- .../feature-gate-static-nobundle.rs | 6 ----- .../feature-gate-static-nobundle.stderr | 18 ------------- .../mix-bundle-and-whole-archive-link-attr.rs | 2 -- .../modifiers-override.rs | 2 -- .../modifiers-override.stderr | 8 +++--- 35 files changed, 88 insertions(+), 196 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/native-link-modifiers-bundle.md delete mode 100644 src/test/run-make-fulldeps/static-nobundle/Makefile delete mode 100644 src/test/run-make-fulldeps/static-nobundle/bbb.rs delete mode 100644 src/test/run-make-fulldeps/static-nobundle/ccc.rs delete mode 100644 src/test/run-make-fulldeps/static-nobundle/ddd.rs create mode 100644 src/test/run-make/native-link-modifier-bundle/Makefile create mode 100644 src/test/run-make/native-link-modifier-bundle/bundled.rs create mode 100644 src/test/run-make/native-link-modifier-bundle/cdylib-bundled.rs create mode 100644 src/test/run-make/native-link-modifier-bundle/cdylib-non-bundled.rs rename src/test/{run-make-fulldeps/static-nobundle/aaa.c => run-make/native-link-modifier-bundle/native-staticlib.c} (100%) create mode 100644 src/test/run-make/native-link-modifier-bundle/non-bundled.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-2.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.stderr delete mode 100644 src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.stderr delete mode 100644 src/test/ui/feature-gates/feature-gate-static-nobundle-2.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-static-nobundle-2.stderr delete mode 100644 src/test/ui/feature-gates/feature-gate-static-nobundle.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-static-nobundle.stderr diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index fc30679be03cb..1f5e2b76bf0dc 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1952,7 +1952,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( add_local_native_libraries(cmd, sess, codegen_results); } - // Upstream rust libraries and their nobundle static libraries + // Upstream rust libraries and their non-bundled static libraries add_upstream_rust_crates::(cmd, sess, codegen_results, crate_type, tmpdir); // Upstream dynamic native libraries linked with `#[link]` attributes at and `-l` @@ -2237,7 +2237,7 @@ fn add_local_native_libraries( } } -/// # Linking Rust crates and their nobundle static libraries +/// # Linking Rust crates and their non-bundled static libraries /// /// Rust crates are not considered at all when creating an rlib output. All dependencies will be /// linked when producing the final output (instead of the intermediate rlib version). diff --git a/compiler/rustc_error_codes/src/error_codes/E0060.md b/compiler/rustc_error_codes/src/error_codes/E0060.md index e6906d72367d8..54b10c886ccce 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0060.md +++ b/compiler/rustc_error_codes/src/error_codes/E0060.md @@ -16,10 +16,10 @@ Using this declaration, it must be called with at least one argument, so simply calling `printf()` is invalid. But the following uses are allowed: ``` -# #![feature(static_nobundle)] # use std::os::raw::{c_char, c_int}; # #[cfg_attr(all(windows, target_env = "msvc"), -# link(name = "legacy_stdio_definitions", kind = "static-nobundle"))] +# link(name = "legacy_stdio_definitions", +# kind = "static", modifiers = "-bundle"))] # extern "C" { fn printf(_: *const c_char, ...) -> c_int; } # fn main() { unsafe { diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 048039343a7a2..b0398ef684997 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -219,6 +219,8 @@ declare_features! ( (accepted, move_ref_pattern, "1.49.0", Some(68354), None), /// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]` (accepted, native_link_modifiers, "1.61.0", Some(81490), None), + /// Allows specifying the bundle link modifier + (accepted, native_link_modifiers_bundle, "1.63.0", Some(81490), None), /// Allows specifying the whole-archive link modifier (accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490), None), /// Allows using `#![no_std]`. diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 5a02661513ca7..1c4dc29fe36d5 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -449,8 +449,6 @@ declare_features! ( (active, naked_functions, "1.9.0", Some(32408), None), /// Allows specifying the as-needed link modifier (active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None), - /// Allows specifying the bundle link modifier - (active, native_link_modifiers_bundle, "1.53.0", Some(81490), None), /// Allows specifying the verbatim link modifier (active, native_link_modifiers_verbatim, "1.53.0", Some(81490), None), /// Allow negative trait implementations. @@ -500,8 +498,6 @@ declare_features! ( (active, simd_ffi, "1.0.0", Some(27731), None), /// Allows specialization of implementations (RFC 1210). (incomplete, specialization, "1.7.0", Some(31844), None), - /// Allows `#[link(kind="static-nobundle"...)]`. - (active, static_nobundle, "1.16.0", Some(37403), None), /// Allows attributes on expressions and non-item statements. (active, stmt_expr_attributes, "1.6.0", Some(15701), None), /// Allows lints part of the strict provenance effort. diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index b546662dc1496..7194416cd1d60 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -169,6 +169,9 @@ declare_features! ( (removed, sanitizer_runtime, "1.17.0", None, None, None), (removed, simd, "1.0.0", Some(27731), None, Some("removed in favor of `#[repr(simd)]`")), + /// Allows `#[link(kind = "static-nobundle", ...)]`. + (removed, static_nobundle, "1.16.0", Some(37403), None, + Some(r#"subsumed by `#[link(kind = "static", modifiers = "-bundle", ...)]`"#)), (removed, struct_inherit, "1.0.0", None, None, None), (removed, test_removed_feature, "1.0.0", None, None, None), /// Allows using items which are missing stability attributes diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 95892d8341479..c33219e470050 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -97,24 +97,6 @@ impl<'tcx> Collector<'tcx> { let span = item.name_value_literal_span().unwrap(); let link_kind = match link_kind.as_str() { "static" => NativeLibKind::Static { bundle: None, whole_archive: None }, - "static-nobundle" => { - sess.struct_span_warn( - span, - "link kind `static-nobundle` has been superseded by specifying \ - modifier `-bundle` with link kind `static`", - ) - .emit(); - if !features.static_nobundle { - feature_err( - &sess.parse_sess, - sym::static_nobundle, - span, - "link kind `static-nobundle` is unstable", - ) - .emit(); - } - NativeLibKind::Static { bundle: Some(false), whole_archive: None } - } "dylib" => NativeLibKind::Dylib { as_needed: None }, "framework" => { if !sess.target.is_like_osx { @@ -264,7 +246,6 @@ impl<'tcx> Collector<'tcx> { }; match (modifier, &mut kind) { ("bundle", Some(NativeLibKind::Static { bundle, .. })) => { - report_unstable_modifier!(native_link_modifiers_bundle); assign_modifier(bundle) } ("bundle", _) => { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 997f361737b34..b4cb47dd61c8d 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1938,21 +1938,6 @@ fn parse_native_lib_kind( let kind = match kind { "static" => NativeLibKind::Static { bundle: None, whole_archive: None }, - "static-nobundle" => { - early_warn( - error_format, - "library kind `static-nobundle` has been superseded by specifying \ - modifier `-bundle` with library kind `static`. Try `static:-bundle`", - ); - if !nightly_options::match_is_nightly_build(matches) { - early_error( - error_format, - "library kind `static-nobundle` is unstable \ - and only accepted on the nightly compiler", - ); - } - NativeLibKind::Static { bundle: Some(false), whole_archive: None } - } "dylib" => NativeLibKind::Dylib { as_needed: None }, "framework" => NativeLibKind::Framework { as_needed: None }, _ => early_error( @@ -2005,10 +1990,7 @@ fn parse_native_lib_modifiers( } }; match (modifier, &mut kind) { - ("bundle", NativeLibKind::Static { bundle, .. }) => { - report_unstable_modifier(); - assign_modifier(bundle) - } + ("bundle", NativeLibKind::Static { bundle, .. }) => assign_modifier(bundle), ("bundle", _) => early_error( error_format, "linking modifier `bundle` is only compatible with `static` linking kind", diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index c92a7d310f309..d4a520b86bb14 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] #![unstable(feature = "panic_unwind", issue = "32837")] #![feature(link_cfg)] -#![feature(native_link_modifiers_bundle)] +#![cfg_attr(bootstrap, feature(native_link_modifiers_bundle))] #![feature(nll)] #![feature(staged_api)] #![feature(c_unwind)] diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index 73e7764a11d37..bc04dfd4433f6 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -84,6 +84,26 @@ The default for this modifier is `-whole-archive`. \ NOTE: The default may currently be different in some cases for backward compatibility, but it is not guaranteed. If you need whole archive semantics use `+whole-archive` explicitly. +### Linking modifiers: `bundle` + +This modifier is only compatible with the `static` linking kind. +Using any other kind will result in a compiler error. + +When building a rlib or staticlib `+bundle` means that all object files from the native static +library will be added to the rlib or staticlib archive, and then used from it during linking of +the final binary. + +When building a rlib `-bundle` means that the native static library is registered as a dependency +of that rlib "by name", and object files from it are included only during linking of the final +binary, the file search by that name is also performed during final linking. \ +When building a staticlib `-bundle` means that the native static library is simply not included +into the archive and some higher level build system will need to add it later during linking of +the final binary. + +This modifier has no effect when building other targets like executables or dynamic libraries. + +The default for this modifier is `+bundle`. + ## `--crate-type`: a list of types of crates for the compiler to emit diff --git a/src/doc/unstable-book/src/language-features/native-link-modifiers-bundle.md b/src/doc/unstable-book/src/language-features/native-link-modifiers-bundle.md deleted file mode 100644 index ac192cff13a3d..0000000000000 --- a/src/doc/unstable-book/src/language-features/native-link-modifiers-bundle.md +++ /dev/null @@ -1,19 +0,0 @@ -# `native_link_modifiers_bundle` - -The tracking issue for this feature is: [#81490] - -[#81490]: https://github.com/rust-lang/rust/issues/81490 - ------------------------- - -The `native_link_modifiers_bundle` feature allows you to use the `bundle` modifier. - -Only compatible with the `static` linking kind. Using any other kind will result in a compiler error. - -`+bundle` means objects from the static library are bundled into the produced crate (a rlib, for example) and are used from this crate later during linking of the final binary. - -`-bundle` means the static library is included into the produced rlib "by name" and object files from it are included only during linking of the final binary, the file search by that name is also performed during final linking. - -This modifier is supposed to supersede the `static-nobundle` linking kind defined by [RFC 1717](https://github.com/rust-lang/rfcs/pull/1717). - -The default for this modifier is currently `+bundle`, but it could be changed later on some future edition boundary. diff --git a/src/test/run-make-fulldeps/static-nobundle/Makefile b/src/test/run-make-fulldeps/static-nobundle/Makefile deleted file mode 100644 index 001081798a6e4..0000000000000 --- a/src/test/run-make-fulldeps/static-nobundle/Makefile +++ /dev/null @@ -1,23 +0,0 @@ --include ../tools.mk - -# aaa is a native static library -# bbb is a rlib -# ccc is a dylib -# ddd is an executable - -all: $(call NATIVE_STATICLIB,aaa) - $(RUSTC) bbb.rs --crate-type=rlib - - # Check that bbb does NOT contain the definition of `native_func` - # We're using the llvm-nm instead of the system nm to ensure it - # is compatible with the LLVM bitcode generated by rustc. - "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbbb.rlib | $(CGREP) -ve "T _*native_func" - "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbbb.rlib | $(CGREP) -e "U _*native_func" - - # Check that aaa gets linked (either as `-l aaa` or `aaa.lib`) when building ccc. - $(RUSTC) ccc.rs -C prefer-dynamic --crate-type=dylib --print link-args | $(CGREP) -e '-l[" ]*aaa|aaa\.lib' - - # Check that aaa does NOT get linked when building ddd. - $(RUSTC) ddd.rs --print link-args | $(CGREP) -ve '-l[" ]*aaa|aaa\.lib' - - $(call RUN,ddd) diff --git a/src/test/run-make-fulldeps/static-nobundle/bbb.rs b/src/test/run-make-fulldeps/static-nobundle/bbb.rs deleted file mode 100644 index 69d1668d4f643..0000000000000 --- a/src/test/run-make-fulldeps/static-nobundle/bbb.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![crate_type = "rlib"] -#![feature(static_nobundle)] - -#[link(name = "aaa", kind = "static-nobundle")] -extern "C" { - pub fn native_func(); -} - -pub fn wrapped_func() { - unsafe { - native_func(); - } -} diff --git a/src/test/run-make-fulldeps/static-nobundle/ccc.rs b/src/test/run-make-fulldeps/static-nobundle/ccc.rs deleted file mode 100644 index a1f875a52d514..0000000000000 --- a/src/test/run-make-fulldeps/static-nobundle/ccc.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![crate_type = "dylib"] - -extern crate bbb; - -pub fn do_work() { - unsafe { bbb::native_func(); } - bbb::wrapped_func(); -} - -pub fn do_work_generic() { - unsafe { bbb::native_func(); } - bbb::wrapped_func(); -} diff --git a/src/test/run-make-fulldeps/static-nobundle/ddd.rs b/src/test/run-make-fulldeps/static-nobundle/ddd.rs deleted file mode 100644 index 50b41211ff02b..0000000000000 --- a/src/test/run-make-fulldeps/static-nobundle/ddd.rs +++ /dev/null @@ -1,7 +0,0 @@ -extern crate ccc; - -fn main() { - ccc::do_work(); - ccc::do_work_generic::(); - ccc::do_work_generic::(); -} diff --git a/src/test/run-make-fulldeps/tools.mk b/src/test/run-make-fulldeps/tools.mk index 9655d09df0f2a..a14f6e3ab95a5 100644 --- a/src/test/run-make-fulldeps/tools.mk +++ b/src/test/run-make-fulldeps/tools.mk @@ -120,7 +120,7 @@ else # So we end up with the following hack: we link use static:-bundle to only # link the parts of libstdc++ that we actually use, which doesn't include # the dependency on the pthreads DLL. - EXTRARSCXXFLAGS := -l static:-bundle=stdc++ -Z unstable-options + EXTRARSCXXFLAGS := -l static:-bundle=stdc++ endif else ifeq ($(UNAME),Darwin) diff --git a/src/test/run-make/native-link-modifier-bundle/Makefile b/src/test/run-make/native-link-modifier-bundle/Makefile new file mode 100644 index 0000000000000..c26c034949ddd --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle/Makefile @@ -0,0 +1,26 @@ +-include ../../run-make-fulldeps/tools.mk + +all: $(call NATIVE_STATICLIB,native-staticlib) + # Build a staticlib and a rlib, the `native_func` symbol will be bundled into them + $(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbundled.a | $(CGREP) -e "T _*native_func" + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbundled.a | $(CGREP) -e "U _*native_func" + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbundled.rlib | $(CGREP) -e "T _*native_func" + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbundled.rlib | $(CGREP) -e "U _*native_func" + + # Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it + $(RUSTC) non-bundled.rs --crate-type=staticlib --crate-type=rlib + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libnon_bundled.a | $(CGREP) -ve "T _*native_func" + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libnon_bundled.a | $(CGREP) -e "U _*native_func" + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -ve "T _*native_func" + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -e "U _*native_func" + + # Build a cdylib, `native-staticlib` will not appear on the linker line because it was bundled previously + # The cdylib will contain the `native_func` symbol in the end + $(RUSTC) cdylib-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -ve '-l[" ]*native-staticlib|native-staticlib\.lib' + "$(LLVM_BIN_DIR)/llvm-nm" $(call DYLIB,cdylib_bundled) | $(CGREP) -e "[Tt] _*native_func" + + # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously + # The cdylib will contain the `native_func` symbol in the end + $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib|native-staticlib\.lib' + "$(LLVM_BIN_DIR)/llvm-nm" $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func" diff --git a/src/test/run-make/native-link-modifier-bundle/bundled.rs b/src/test/run-make/native-link-modifier-bundle/bundled.rs new file mode 100644 index 0000000000000..0bbae8752d7b3 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle/bundled.rs @@ -0,0 +1,11 @@ +#[link(name = "native-staticlib", kind = "static", modifiers = "+bundle")] +extern "C" { + pub fn native_func(); +} + +#[no_mangle] +pub extern "C" fn wrapped_func() { + unsafe { + native_func(); + } +} diff --git a/src/test/run-make/native-link-modifier-bundle/cdylib-bundled.rs b/src/test/run-make/native-link-modifier-bundle/cdylib-bundled.rs new file mode 100644 index 0000000000000..7291309168a48 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle/cdylib-bundled.rs @@ -0,0 +1 @@ +extern crate bundled; diff --git a/src/test/run-make/native-link-modifier-bundle/cdylib-non-bundled.rs b/src/test/run-make/native-link-modifier-bundle/cdylib-non-bundled.rs new file mode 100644 index 0000000000000..1df81fd101f75 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle/cdylib-non-bundled.rs @@ -0,0 +1 @@ +extern crate non_bundled; diff --git a/src/test/run-make-fulldeps/static-nobundle/aaa.c b/src/test/run-make/native-link-modifier-bundle/native-staticlib.c similarity index 100% rename from src/test/run-make-fulldeps/static-nobundle/aaa.c rename to src/test/run-make/native-link-modifier-bundle/native-staticlib.c diff --git a/src/test/run-make/native-link-modifier-bundle/non-bundled.rs b/src/test/run-make/native-link-modifier-bundle/non-bundled.rs new file mode 100644 index 0000000000000..8181e6387c5c7 --- /dev/null +++ b/src/test/run-make/native-link-modifier-bundle/non-bundled.rs @@ -0,0 +1,11 @@ +#[link(name = "native-staticlib", kind = "static", modifiers = "-bundle")] +extern "C" { + pub fn native_func(); +} + +#[no_mangle] +pub extern "C" fn wrapped_func() { + unsafe { + native_func(); + } +} diff --git a/src/test/run-make/native-link-modifier-whole-archive/Makefile b/src/test/run-make/native-link-modifier-whole-archive/Makefile index 799b5f6f5fc6f..3b49d1188ae6b 100644 --- a/src/test/run-make/native-link-modifier-whole-archive/Makefile +++ b/src/test/run-make/native-link-modifier-whole-archive/Makefile @@ -17,7 +17,7 @@ all: $(TMPDIR)/$(call BIN,directly_linked) $(TMPDIR)/$(call BIN,indirectly_linke # Native lib linked directly into executable $(TMPDIR)/$(call BIN,directly_linked): $(call NATIVE_STATICLIB,c_static_lib_with_constructor) - $(RUSTC) directly_linked.rs -Z unstable-options -l static:+whole-archive=c_static_lib_with_constructor + $(RUSTC) directly_linked.rs -l static:+whole-archive=c_static_lib_with_constructor # Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable $(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib @@ -29,7 +29,7 @@ $(TMPDIR)/$(call BIN,indirectly_linked_via_attr): $(TMPDIR)/libnative_lib_in_src # Native lib linked into rlib with via commandline $(TMPDIR)/librlib_with_cmdline_native_lib.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor) - $(RUSTC) rlib_with_cmdline_native_lib.rs -Z unstable-options --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor + $(RUSTC) rlib_with_cmdline_native_lib.rs --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor # Native lib linked into rlib via `#[link()]` attribute on extern block. $(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor) diff --git a/src/test/run-make/native-link-modifier-whole-archive/native_lib_in_src.rs b/src/test/run-make/native-link-modifier-whole-archive/native_lib_in_src.rs index 2436c36e6ebfb..971f3be7a61e9 100644 --- a/src/test/run-make/native-link-modifier-whole-archive/native_lib_in_src.rs +++ b/src/test/run-make/native-link-modifier-whole-archive/native_lib_in_src.rs @@ -1,5 +1,3 @@ -#![feature(native_link_modifiers_bundle)] - use std::io::Write; #[link(name = "c_static_lib_with_constructor", diff --git a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-2.rs b/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-2.rs deleted file mode 100644 index e229564950fcf..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-2.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Test native_link_modifiers_bundle don't need static-nobundle -// check-pass - -#![feature(native_link_modifiers_bundle)] - -#[link(name = "foo", kind = "static", modifiers = "-bundle")] -extern "C" {} - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.rs b/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.rs deleted file mode 100644 index 3da943ee4a963..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.rs +++ /dev/null @@ -1,3 +0,0 @@ -// compile-flags: -l static:-bundle=nonexistent - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.stderr b/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.stderr deleted file mode 100644 index 743bcc9a1b381..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: linking modifier `bundle` is unstable and only accepted on the nightly compiler - diff --git a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.rs b/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.rs deleted file mode 100644 index c1d5a31aaa4df..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[link(name = "foo", kind = "static", modifiers = "+bundle")] -//~^ ERROR: linking modifier `bundle` is unstable -extern "C" {} - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.stderr b/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.stderr deleted file mode 100644 index dcaa7fcc64f02..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: linking modifier `bundle` is unstable - --> $DIR/feature-gate-native_link_modifiers_bundle.rs:1:51 - | -LL | #[link(name = "foo", kind = "static", modifiers = "+bundle")] - | ^^^^^^^^^ - | - = note: see issue #81490 for more information - = help: add `#![feature(native_link_modifiers_bundle)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gates/feature-gate-static-nobundle-2.rs b/src/test/ui/feature-gates/feature-gate-static-nobundle-2.rs deleted file mode 100644 index ad0662b6892d2..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-static-nobundle-2.rs +++ /dev/null @@ -1,4 +0,0 @@ -// check-pass -// compile-flags: -l static-nobundle=nonexistent - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-static-nobundle-2.stderr b/src/test/ui/feature-gates/feature-gate-static-nobundle-2.stderr deleted file mode 100644 index 782d9e3945615..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-static-nobundle-2.stderr +++ /dev/null @@ -1,2 +0,0 @@ -warning: library kind `static-nobundle` has been superseded by specifying modifier `-bundle` with library kind `static`. Try `static:-bundle` - diff --git a/src/test/ui/feature-gates/feature-gate-static-nobundle.rs b/src/test/ui/feature-gates/feature-gate-static-nobundle.rs deleted file mode 100644 index 50f1b7ff3fc48..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-static-nobundle.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[link(name = "foo", kind = "static-nobundle")] -//~^ WARNING: link kind `static-nobundle` has been superseded by specifying modifier `-bundle` with link kind `static` -//~^^ ERROR: link kind `static-nobundle` is unstable -extern "C" {} - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-static-nobundle.stderr b/src/test/ui/feature-gates/feature-gate-static-nobundle.stderr deleted file mode 100644 index 094661aeb57af..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-static-nobundle.stderr +++ /dev/null @@ -1,18 +0,0 @@ -warning: link kind `static-nobundle` has been superseded by specifying modifier `-bundle` with link kind `static` - --> $DIR/feature-gate-static-nobundle.rs:1:29 - | -LL | #[link(name = "foo", kind = "static-nobundle")] - | ^^^^^^^^^^^^^^^^^ - -error[E0658]: link kind `static-nobundle` is unstable - --> $DIR/feature-gate-static-nobundle.rs:1:29 - | -LL | #[link(name = "foo", kind = "static-nobundle")] - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #37403 for more information - = help: add `#![feature(static_nobundle)]` to the crate attributes to enable - -error: aborting due to previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive-link-attr.rs b/src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive-link-attr.rs index b153ef94626a3..066048795c8a2 100644 --- a/src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive-link-attr.rs +++ b/src/test/ui/native-library-link-flags/mix-bundle-and-whole-archive-link-attr.rs @@ -2,8 +2,6 @@ // build-fail // error-pattern: the linking modifiers `+bundle` and `+whole-archive` are not compatible with each other when generating rlibs -#![feature(native_link_modifiers_bundle)] - #[link(name = "mylib", kind = "static", modifiers = "+bundle,+whole-archive")] extern "C" { } diff --git a/src/test/ui/native-library-link-flags/modifiers-override.rs b/src/test/ui/native-library-link-flags/modifiers-override.rs index 3912ac9f13d6c..42cdb5004adcb 100644 --- a/src/test/ui/native-library-link-flags/modifiers-override.rs +++ b/src/test/ui/native-library-link-flags/modifiers-override.rs @@ -1,7 +1,5 @@ // compile-flags:-ldylib:+as-needed=foo -lstatic=bar -Zunstable-options -#![feature(native_link_modifiers_bundle)] - #[link(name = "foo")] #[link( name = "bar", diff --git a/src/test/ui/native-library-link-flags/modifiers-override.stderr b/src/test/ui/native-library-link-flags/modifiers-override.stderr index 55362910e71c6..eb3ab55c31044 100644 --- a/src/test/ui/native-library-link-flags/modifiers-override.stderr +++ b/src/test/ui/native-library-link-flags/modifiers-override.stderr @@ -1,23 +1,23 @@ error: multiple `modifiers` arguments in a single `#[link]` attribute - --> $DIR/modifiers-override.rs:11:5 + --> $DIR/modifiers-override.rs:9:5 | LL | modifiers = "+bundle" | ^^^^^^^^^^^^^^^^^^^^^ error: multiple `whole-archive` modifiers in a single `modifiers` argument - --> $DIR/modifiers-override.rs:9:17 + --> $DIR/modifiers-override.rs:7:17 | LL | modifiers = "+whole-archive,-whole-archive", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: overriding linking modifiers from command line is not supported - --> $DIR/modifiers-override.rs:14:1 + --> $DIR/modifiers-override.rs:12:1 | LL | extern "C" {} | ^^^^^^^^^^^^^ error: overriding linking modifiers from command line is not supported - --> $DIR/modifiers-override.rs:14:1 + --> $DIR/modifiers-override.rs:12:1 | LL | extern "C" {} | ^^^^^^^^^^^^^ From e60d8b631a5d917d5ce7db9c3c096920df8d4c4c Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Mon, 30 May 2022 16:26:02 -0700 Subject: [PATCH 3/6] Fix TLS access mir opt test and remove stale files --- ...st_combine_deref.deep_opt.InstCombine.diff | 92 ------------------- ...e_deref.do_not_miscompile.InstCombine.diff | 85 ----------------- ...st_combine_deref.dont_opt.InstCombine.diff | 53 ----------- ..._combine_deref.opt_struct.InstCombine.diff | 44 --------- ..._combine_deref.simple_opt.InstCombine.diff | 34 ------- src/test/mir-opt/tls-access.rs | 6 +- ...r => tls_access.main.PreCodegen.after.mir} | 33 ++++--- 7 files changed, 21 insertions(+), 326 deletions(-) delete mode 100644 src/test/mir-opt/inst_combine_deref.deep_opt.InstCombine.diff delete mode 100644 src/test/mir-opt/inst_combine_deref.do_not_miscompile.InstCombine.diff delete mode 100644 src/test/mir-opt/inst_combine_deref.dont_opt.InstCombine.diff delete mode 100644 src/test/mir-opt/inst_combine_deref.opt_struct.InstCombine.diff delete mode 100644 src/test/mir-opt/inst_combine_deref.simple_opt.InstCombine.diff rename src/test/mir-opt/{tls_access.main.SimplifyCfg-final.after.mir => tls_access.main.PreCodegen.after.mir} (60%) diff --git a/src/test/mir-opt/inst_combine_deref.deep_opt.InstCombine.diff b/src/test/mir-opt/inst_combine_deref.deep_opt.InstCombine.diff deleted file mode 100644 index 1d20e17a8499b..0000000000000 --- a/src/test/mir-opt/inst_combine_deref.deep_opt.InstCombine.diff +++ /dev/null @@ -1,92 +0,0 @@ -- // MIR for `deep_opt` before InstCombine -+ // MIR for `deep_opt` after InstCombine - - fn deep_opt() -> (u64, u64, u64) { - let mut _0: (u64, u64, u64); // return place in scope 0 at $DIR/inst_combine_deref.rs:11:18: 11:33 - let _1: u64; // in scope 0 at $DIR/inst_combine_deref.rs:12:9: 12:11 - let mut _10: u64; // in scope 0 at $DIR/inst_combine_deref.rs:21:6: 21:8 - let mut _11: u64; // in scope 0 at $DIR/inst_combine_deref.rs:21:10: 21:12 - let mut _12: u64; // in scope 0 at $DIR/inst_combine_deref.rs:21:14: 21:16 - scope 1 { - debug x1 => _1; // in scope 1 at $DIR/inst_combine_deref.rs:12:9: 12:11 - let _2: u64; // in scope 1 at $DIR/inst_combine_deref.rs:13:9: 13:11 - scope 2 { - debug x2 => _2; // in scope 2 at $DIR/inst_combine_deref.rs:13:9: 13:11 - let _3: u64; // in scope 2 at $DIR/inst_combine_deref.rs:14:9: 14:11 - scope 3 { - debug x3 => _3; // in scope 3 at $DIR/inst_combine_deref.rs:14:9: 14:11 - let _4: &u64; // in scope 3 at $DIR/inst_combine_deref.rs:15:9: 15:11 - scope 4 { - debug y1 => _4; // in scope 4 at $DIR/inst_combine_deref.rs:15:9: 15:11 - let _5: &u64; // in scope 4 at $DIR/inst_combine_deref.rs:16:9: 16:11 - scope 5 { - debug y2 => _5; // in scope 5 at $DIR/inst_combine_deref.rs:16:9: 16:11 - let _6: &u64; // in scope 5 at $DIR/inst_combine_deref.rs:17:9: 17:11 - scope 6 { - debug y3 => _6; // in scope 6 at $DIR/inst_combine_deref.rs:17:9: 17:11 - let _7: u64; // in scope 6 at $DIR/inst_combine_deref.rs:18:9: 18:11 - scope 7 { - debug z1 => _7; // in scope 7 at $DIR/inst_combine_deref.rs:18:9: 18:11 - let _8: u64; // in scope 7 at $DIR/inst_combine_deref.rs:19:9: 19:11 - scope 8 { - debug z2 => _8; // in scope 8 at $DIR/inst_combine_deref.rs:19:9: 19:11 - let _9: u64; // in scope 8 at $DIR/inst_combine_deref.rs:20:9: 20:11 - scope 9 { - debug z3 => _9; // in scope 9 at $DIR/inst_combine_deref.rs:20:9: 20:11 - } - } - } - } - } - } - } - } - } - - bb0: { - StorageLive(_1); // scope 0 at $DIR/inst_combine_deref.rs:12:9: 12:11 - _1 = const 1_u64; // scope 0 at $DIR/inst_combine_deref.rs:12:14: 12:15 - StorageLive(_2); // scope 1 at $DIR/inst_combine_deref.rs:13:9: 13:11 - _2 = const 2_u64; // scope 1 at $DIR/inst_combine_deref.rs:13:14: 13:15 - StorageLive(_3); // scope 2 at $DIR/inst_combine_deref.rs:14:9: 14:11 - _3 = const 3_u64; // scope 2 at $DIR/inst_combine_deref.rs:14:14: 14:15 - StorageLive(_4); // scope 3 at $DIR/inst_combine_deref.rs:15:9: 15:11 - _4 = &_1; // scope 3 at $DIR/inst_combine_deref.rs:15:14: 15:17 - StorageLive(_5); // scope 4 at $DIR/inst_combine_deref.rs:16:9: 16:11 - _5 = &_2; // scope 4 at $DIR/inst_combine_deref.rs:16:14: 16:17 - StorageLive(_6); // scope 5 at $DIR/inst_combine_deref.rs:17:9: 17:11 - _6 = &_3; // scope 5 at $DIR/inst_combine_deref.rs:17:14: 17:17 - StorageLive(_7); // scope 6 at $DIR/inst_combine_deref.rs:18:9: 18:11 -- _7 = (*_4); // scope 6 at $DIR/inst_combine_deref.rs:18:14: 18:17 -+ _7 = _1; // scope 6 at $DIR/inst_combine_deref.rs:18:14: 18:17 - StorageLive(_8); // scope 7 at $DIR/inst_combine_deref.rs:19:9: 19:11 -- _8 = (*_5); // scope 7 at $DIR/inst_combine_deref.rs:19:14: 19:17 -+ _8 = _2; // scope 7 at $DIR/inst_combine_deref.rs:19:14: 19:17 - StorageLive(_9); // scope 8 at $DIR/inst_combine_deref.rs:20:9: 20:11 -- _9 = (*_6); // scope 8 at $DIR/inst_combine_deref.rs:20:14: 20:17 -+ _9 = _3; // scope 8 at $DIR/inst_combine_deref.rs:20:14: 20:17 - StorageLive(_10); // scope 9 at $DIR/inst_combine_deref.rs:21:6: 21:8 - _10 = _7; // scope 9 at $DIR/inst_combine_deref.rs:21:6: 21:8 - StorageLive(_11); // scope 9 at $DIR/inst_combine_deref.rs:21:10: 21:12 - _11 = _8; // scope 9 at $DIR/inst_combine_deref.rs:21:10: 21:12 - StorageLive(_12); // scope 9 at $DIR/inst_combine_deref.rs:21:14: 21:16 - _12 = _9; // scope 9 at $DIR/inst_combine_deref.rs:21:14: 21:16 - (_0.0: u64) = move _10; // scope 9 at $DIR/inst_combine_deref.rs:21:5: 21:17 - (_0.1: u64) = move _11; // scope 9 at $DIR/inst_combine_deref.rs:21:5: 21:17 - (_0.2: u64) = move _12; // scope 9 at $DIR/inst_combine_deref.rs:21:5: 21:17 - StorageDead(_12); // scope 9 at $DIR/inst_combine_deref.rs:21:16: 21:17 - StorageDead(_11); // scope 9 at $DIR/inst_combine_deref.rs:21:16: 21:17 - StorageDead(_10); // scope 9 at $DIR/inst_combine_deref.rs:21:16: 21:17 - StorageDead(_9); // scope 8 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_8); // scope 7 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_7); // scope 6 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_6); // scope 5 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_5); // scope 4 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_4); // scope 3 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_3); // scope 2 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_2); // scope 1 at $DIR/inst_combine_deref.rs:22:1: 22:2 - StorageDead(_1); // scope 0 at $DIR/inst_combine_deref.rs:22:1: 22:2 - return; // scope 0 at $DIR/inst_combine_deref.rs:22:2: 22:2 - } - } - diff --git a/src/test/mir-opt/inst_combine_deref.do_not_miscompile.InstCombine.diff b/src/test/mir-opt/inst_combine_deref.do_not_miscompile.InstCombine.diff deleted file mode 100644 index ee8fcdcde4095..0000000000000 --- a/src/test/mir-opt/inst_combine_deref.do_not_miscompile.InstCombine.diff +++ /dev/null @@ -1,85 +0,0 @@ -- // MIR for `do_not_miscompile` before InstCombine -+ // MIR for `do_not_miscompile` after InstCombine - - fn do_not_miscompile() -> () { - let mut _0: (); // return place in scope 0 at $DIR/inst_combine_deref.rs:54:24: 54:24 - let _1: i32; // in scope 0 at $DIR/inst_combine_deref.rs:55:9: 55:10 - let mut _5: &i32; // in scope 0 at $DIR/inst_combine_deref.rs:59:10: 59:12 - let _6: &i32; // in scope 0 at $DIR/inst_combine_deref.rs:59:10: 59:12 - let _7: (); // in scope 0 at $DIR/inst_combine_deref.rs:60:5: 60:23 - let mut _8: bool; // in scope 0 at $DIR/inst_combine_deref.rs:60:5: 60:23 - let mut _9: bool; // in scope 0 at $DIR/inst_combine_deref.rs:60:13: 60:21 - let mut _10: i32; // in scope 0 at $DIR/inst_combine_deref.rs:60:13: 60:15 - let mut _11: !; // in scope 0 at $DIR/inst_combine_deref.rs:60:5: 60:23 - scope 1 { - debug x => _1; // in scope 1 at $DIR/inst_combine_deref.rs:55:9: 55:10 - let _2: i32; // in scope 1 at $DIR/inst_combine_deref.rs:56:9: 56:10 - scope 2 { - debug a => _2; // in scope 2 at $DIR/inst_combine_deref.rs:56:9: 56:10 - let mut _3: &i32; // in scope 2 at $DIR/inst_combine_deref.rs:57:9: 57:14 - scope 3 { - debug y => _3; // in scope 3 at $DIR/inst_combine_deref.rs:57:9: 57:14 - let _4: &mut &i32; // in scope 3 at $DIR/inst_combine_deref.rs:58:9: 58:10 - scope 4 { - debug z => _4; // in scope 4 at $DIR/inst_combine_deref.rs:58:9: 58:10 - } - } - } - } - - bb0: { - StorageLive(_1); // scope 0 at $DIR/inst_combine_deref.rs:55:9: 55:10 - _1 = const 42_i32; // scope 0 at $DIR/inst_combine_deref.rs:55:13: 55:15 - StorageLive(_2); // scope 1 at $DIR/inst_combine_deref.rs:56:9: 56:10 - _2 = const 99_i32; // scope 1 at $DIR/inst_combine_deref.rs:56:13: 56:15 - StorageLive(_3); // scope 2 at $DIR/inst_combine_deref.rs:57:9: 57:14 - _3 = &_1; // scope 2 at $DIR/inst_combine_deref.rs:57:17: 57:19 - StorageLive(_4); // scope 3 at $DIR/inst_combine_deref.rs:58:9: 58:10 - _4 = &mut _3; // scope 3 at $DIR/inst_combine_deref.rs:58:13: 58:19 - StorageLive(_5); // scope 4 at $DIR/inst_combine_deref.rs:59:10: 59:12 - StorageLive(_6); // scope 4 at $DIR/inst_combine_deref.rs:59:10: 59:12 - _6 = &_2; // scope 4 at $DIR/inst_combine_deref.rs:59:10: 59:12 -- _5 = &(*_6); // scope 4 at $DIR/inst_combine_deref.rs:59:10: 59:12 -+ _5 = _6; // scope 4 at $DIR/inst_combine_deref.rs:59:10: 59:12 - (*_4) = move _5; // scope 4 at $DIR/inst_combine_deref.rs:59:5: 59:12 - StorageDead(_5); // scope 4 at $DIR/inst_combine_deref.rs:59:11: 59:12 - StorageDead(_6); // scope 4 at $DIR/inst_combine_deref.rs:59:12: 59:13 - StorageLive(_7); // scope 4 at $DIR/inst_combine_deref.rs:60:5: 60:23 - StorageLive(_8); // scope 4 at $DIR/inst_combine_deref.rs:60:5: 60:23 - StorageLive(_9); // scope 4 at $DIR/inst_combine_deref.rs:60:13: 60:21 - StorageLive(_10); // scope 4 at $DIR/inst_combine_deref.rs:60:13: 60:15 - _10 = (*_3); // scope 4 at $DIR/inst_combine_deref.rs:60:13: 60:15 - _9 = Eq(move _10, const 99_i32); // scope 4 at $DIR/inst_combine_deref.rs:60:13: 60:21 - StorageDead(_10); // scope 4 at $DIR/inst_combine_deref.rs:60:20: 60:21 - _8 = Not(move _9); // scope 4 at $DIR/inst_combine_deref.rs:60:5: 60:23 - StorageDead(_9); // scope 4 at $DIR/inst_combine_deref.rs:60:22: 60:23 - switchInt(move _8) -> [false: bb2, otherwise: bb1]; // scope 4 at $DIR/inst_combine_deref.rs:60:5: 60:23 - } - - bb1: { - StorageLive(_11); // scope 4 at $DIR/inst_combine_deref.rs:60:5: 60:23 - core::panicking::panic(const "assertion failed: *y == 99"); // scope 4 at $DIR/inst_combine_deref.rs:60:5: 60:23 - // mir::Constant - // + span: $DIR/inst_combine_deref.rs:60:5: 60:23 - // + literal: Const { ty: fn(&'static str) -> ! {core::panicking::panic}, val: Value(Scalar()) } - // ty::Const - // + ty: &str - // + val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 42, 121, 32, 61, 61, 32, 57, 57], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [67108863], len: Size { raw: 26 } }, size: Size { raw: 26 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 26 }) - // mir::Constant - // + span: $DIR/inst_combine_deref.rs:1:1: 1:1 - // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [97, 115, 115, 101, 114, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100, 58, 32, 42, 121, 32, 61, 61, 32, 57, 57], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [67108863], len: Size { raw: 26 } }, size: Size { raw: 26 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 26 }) } - } - - bb2: { - _7 = const (); // scope 4 at $DIR/inst_combine_deref.rs:60:23: 60:23 - StorageDead(_8); // scope 4 at $DIR/inst_combine_deref.rs:60:22: 60:23 - StorageDead(_7); // scope 4 at $DIR/inst_combine_deref.rs:60:22: 60:23 - _0 = const (); // scope 0 at $DIR/inst_combine_deref.rs:54:24: 61:2 - StorageDead(_4); // scope 3 at $DIR/inst_combine_deref.rs:61:1: 61:2 - StorageDead(_3); // scope 2 at $DIR/inst_combine_deref.rs:61:1: 61:2 - StorageDead(_2); // scope 1 at $DIR/inst_combine_deref.rs:61:1: 61:2 - StorageDead(_1); // scope 0 at $DIR/inst_combine_deref.rs:61:1: 61:2 - return; // scope 0 at $DIR/inst_combine_deref.rs:61:2: 61:2 - } - } - diff --git a/src/test/mir-opt/inst_combine_deref.dont_opt.InstCombine.diff b/src/test/mir-opt/inst_combine_deref.dont_opt.InstCombine.diff deleted file mode 100644 index 69036491a10b7..0000000000000 --- a/src/test/mir-opt/inst_combine_deref.dont_opt.InstCombine.diff +++ /dev/null @@ -1,53 +0,0 @@ -- // MIR for `dont_opt` before InstCombine -+ // MIR for `dont_opt` after InstCombine - - fn dont_opt() -> u64 { - let mut _0: u64; // return place in scope 0 at $DIR/inst_combine_deref.rs:43:18: 43:21 - let _1: i32; // in scope 0 at $DIR/inst_combine_deref.rs:44:9: 44:10 - let mut _5: &i32; // in scope 0 at $DIR/inst_combine_deref.rs:48:10: 48:14 - scope 1 { - debug y => _1; // in scope 1 at $DIR/inst_combine_deref.rs:44:9: 44:10 - let _2: &i32; // in scope 1 at $DIR/inst_combine_deref.rs:45:9: 45:13 - scope 2 { - debug _ref => _2; // in scope 2 at $DIR/inst_combine_deref.rs:45:9: 45:13 - let _3: i32; // in scope 2 at $DIR/inst_combine_deref.rs:46:9: 46:10 - scope 3 { - debug x => _3; // in scope 3 at $DIR/inst_combine_deref.rs:46:9: 46:10 - let mut _4: &i32; // in scope 3 at $DIR/inst_combine_deref.rs:47:9: 47:15 - scope 4 { - debug _1 => _4; // in scope 4 at $DIR/inst_combine_deref.rs:47:9: 47:15 - let _6: i32; // in scope 4 at $DIR/inst_combine_deref.rs:49:9: 49:11 - scope 5 { - debug _4 => _6; // in scope 5 at $DIR/inst_combine_deref.rs:49:9: 49:11 - } - } - } - } - } - - bb0: { - StorageLive(_1); // scope 0 at $DIR/inst_combine_deref.rs:44:9: 44:10 - _1 = const 5_i32; // scope 0 at $DIR/inst_combine_deref.rs:44:13: 44:14 - StorageLive(_2); // scope 1 at $DIR/inst_combine_deref.rs:45:9: 45:13 - _2 = &_1; // scope 1 at $DIR/inst_combine_deref.rs:45:16: 45:18 - StorageLive(_3); // scope 2 at $DIR/inst_combine_deref.rs:46:9: 46:10 - _3 = const 5_i32; // scope 2 at $DIR/inst_combine_deref.rs:46:13: 46:14 - StorageLive(_4); // scope 3 at $DIR/inst_combine_deref.rs:47:9: 47:15 - _4 = &_3; // scope 3 at $DIR/inst_combine_deref.rs:47:18: 47:20 - StorageLive(_5); // scope 4 at $DIR/inst_combine_deref.rs:48:10: 48:14 -- _5 = &(*_2); // scope 4 at $DIR/inst_combine_deref.rs:48:10: 48:14 -+ _5 = _2; // scope 4 at $DIR/inst_combine_deref.rs:48:10: 48:14 - _4 = move _5; // scope 4 at $DIR/inst_combine_deref.rs:48:5: 48:14 - StorageDead(_5); // scope 4 at $DIR/inst_combine_deref.rs:48:13: 48:14 - StorageLive(_6); // scope 4 at $DIR/inst_combine_deref.rs:49:9: 49:11 - _6 = (*_4); // scope 4 at $DIR/inst_combine_deref.rs:49:14: 49:17 - _0 = const 0_u64; // scope 5 at $DIR/inst_combine_deref.rs:50:5: 50:6 - StorageDead(_6); // scope 4 at $DIR/inst_combine_deref.rs:51:1: 51:2 - StorageDead(_4); // scope 3 at $DIR/inst_combine_deref.rs:51:1: 51:2 - StorageDead(_3); // scope 2 at $DIR/inst_combine_deref.rs:51:1: 51:2 - StorageDead(_2); // scope 1 at $DIR/inst_combine_deref.rs:51:1: 51:2 - StorageDead(_1); // scope 0 at $DIR/inst_combine_deref.rs:51:1: 51:2 - return; // scope 0 at $DIR/inst_combine_deref.rs:51:2: 51:2 - } - } - diff --git a/src/test/mir-opt/inst_combine_deref.opt_struct.InstCombine.diff b/src/test/mir-opt/inst_combine_deref.opt_struct.InstCombine.diff deleted file mode 100644 index c867543d05ea3..0000000000000 --- a/src/test/mir-opt/inst_combine_deref.opt_struct.InstCombine.diff +++ /dev/null @@ -1,44 +0,0 @@ -- // MIR for `opt_struct` before InstCombine -+ // MIR for `opt_struct` after InstCombine - - fn opt_struct(_1: S) -> u64 { - debug s => _1; // in scope 0 at $DIR/inst_combine_deref.rs:30:15: 30:16 - let mut _0: u64; // return place in scope 0 at $DIR/inst_combine_deref.rs:30:24: 30:27 - let _2: &u64; // in scope 0 at $DIR/inst_combine_deref.rs:31:9: 31:10 - let mut _5: u64; // in scope 0 at $DIR/inst_combine_deref.rs:34:5: 34:7 - let mut _6: u64; // in scope 0 at $DIR/inst_combine_deref.rs:34:10: 34:11 - scope 1 { - debug a => _2; // in scope 1 at $DIR/inst_combine_deref.rs:31:9: 31:10 - let _3: &u64; // in scope 1 at $DIR/inst_combine_deref.rs:32:9: 32:10 - scope 2 { - debug b => _3; // in scope 2 at $DIR/inst_combine_deref.rs:32:9: 32:10 - let _4: u64; // in scope 2 at $DIR/inst_combine_deref.rs:33:9: 33:10 - scope 3 { - debug x => _4; // in scope 3 at $DIR/inst_combine_deref.rs:33:9: 33:10 - } - } - } - - bb0: { - StorageLive(_2); // scope 0 at $DIR/inst_combine_deref.rs:31:9: 31:10 - _2 = &(_1.0: u64); // scope 0 at $DIR/inst_combine_deref.rs:31:13: 31:17 - StorageLive(_3); // scope 1 at $DIR/inst_combine_deref.rs:32:9: 32:10 - _3 = &(_1.1: u64); // scope 1 at $DIR/inst_combine_deref.rs:32:13: 32:17 - StorageLive(_4); // scope 2 at $DIR/inst_combine_deref.rs:33:9: 33:10 -- _4 = (*_2); // scope 2 at $DIR/inst_combine_deref.rs:33:13: 33:15 -+ _4 = (_1.0: u64); // scope 2 at $DIR/inst_combine_deref.rs:33:13: 33:15 - StorageLive(_5); // scope 3 at $DIR/inst_combine_deref.rs:34:5: 34:7 -- _5 = (*_3); // scope 3 at $DIR/inst_combine_deref.rs:34:5: 34:7 -+ _5 = (_1.1: u64); // scope 3 at $DIR/inst_combine_deref.rs:34:5: 34:7 - StorageLive(_6); // scope 3 at $DIR/inst_combine_deref.rs:34:10: 34:11 - _6 = _4; // scope 3 at $DIR/inst_combine_deref.rs:34:10: 34:11 - _0 = Add(move _5, move _6); // scope 3 at $DIR/inst_combine_deref.rs:34:5: 34:11 - StorageDead(_6); // scope 3 at $DIR/inst_combine_deref.rs:34:10: 34:11 - StorageDead(_5); // scope 3 at $DIR/inst_combine_deref.rs:34:10: 34:11 - StorageDead(_4); // scope 2 at $DIR/inst_combine_deref.rs:35:1: 35:2 - StorageDead(_3); // scope 1 at $DIR/inst_combine_deref.rs:35:1: 35:2 - StorageDead(_2); // scope 0 at $DIR/inst_combine_deref.rs:35:1: 35:2 - return; // scope 0 at $DIR/inst_combine_deref.rs:35:2: 35:2 - } - } - diff --git a/src/test/mir-opt/inst_combine_deref.simple_opt.InstCombine.diff b/src/test/mir-opt/inst_combine_deref.simple_opt.InstCombine.diff deleted file mode 100644 index f52dfe379ca30..0000000000000 --- a/src/test/mir-opt/inst_combine_deref.simple_opt.InstCombine.diff +++ /dev/null @@ -1,34 +0,0 @@ -- // MIR for `simple_opt` before InstCombine -+ // MIR for `simple_opt` after InstCombine - - fn simple_opt() -> u64 { - let mut _0: u64; // return place in scope 0 at $DIR/inst_combine_deref.rs:3:20: 3:23 - let _1: u64; // in scope 0 at $DIR/inst_combine_deref.rs:4:9: 4:10 - scope 1 { - debug x => _1; // in scope 1 at $DIR/inst_combine_deref.rs:4:9: 4:10 - let _2: &u64; // in scope 1 at $DIR/inst_combine_deref.rs:5:9: 5:10 - scope 2 { - debug y => _2; // in scope 2 at $DIR/inst_combine_deref.rs:5:9: 5:10 - let _3: u64; // in scope 2 at $DIR/inst_combine_deref.rs:6:9: 6:10 - scope 3 { - debug z => _3; // in scope 3 at $DIR/inst_combine_deref.rs:6:9: 6:10 - } - } - } - - bb0: { - StorageLive(_1); // scope 0 at $DIR/inst_combine_deref.rs:4:9: 4:10 - _1 = const 5_u64; // scope 0 at $DIR/inst_combine_deref.rs:4:13: 4:14 - StorageLive(_2); // scope 1 at $DIR/inst_combine_deref.rs:5:9: 5:10 - _2 = &_1; // scope 1 at $DIR/inst_combine_deref.rs:5:13: 5:15 - StorageLive(_3); // scope 2 at $DIR/inst_combine_deref.rs:6:9: 6:10 -- _3 = (*_2); // scope 2 at $DIR/inst_combine_deref.rs:6:13: 6:15 -+ _3 = _1; // scope 2 at $DIR/inst_combine_deref.rs:6:13: 6:15 - _0 = _3; // scope 3 at $DIR/inst_combine_deref.rs:7:5: 7:6 - StorageDead(_3); // scope 2 at $DIR/inst_combine_deref.rs:8:1: 8:2 - StorageDead(_2); // scope 1 at $DIR/inst_combine_deref.rs:8:1: 8:2 - StorageDead(_1); // scope 0 at $DIR/inst_combine_deref.rs:8:1: 8:2 - return; // scope 0 at $DIR/inst_combine_deref.rs:8:2: 8:2 - } - } - diff --git a/src/test/mir-opt/tls-access.rs b/src/test/mir-opt/tls-access.rs index 9036c57556dda..19344c8686212 100644 --- a/src/test/mir-opt/tls-access.rs +++ b/src/test/mir-opt/tls-access.rs @@ -1,3 +1,6 @@ +// EMIT_MIR tls_access.main.PreCodegen.after.mir +// compile-flags: -Zmir-opt-level=0 + #![feature(thread_local)] #[thread_local] @@ -9,6 +12,3 @@ fn main() { FOO = 42; } } - -// EMIT_MIR tls_access.main.SimplifyCfg-final.after.mir -// compile-flags: -Zmir-opt-level=0 diff --git a/src/test/mir-opt/tls_access.main.SimplifyCfg-final.after.mir b/src/test/mir-opt/tls_access.main.PreCodegen.after.mir similarity index 60% rename from src/test/mir-opt/tls_access.main.SimplifyCfg-final.after.mir rename to src/test/mir-opt/tls_access.main.PreCodegen.after.mir index de19a226e8f75..baa77497e3862 100644 --- a/src/test/mir-opt/tls_access.main.SimplifyCfg-final.after.mir +++ b/src/test/mir-opt/tls_access.main.PreCodegen.after.mir @@ -1,25 +1,28 @@ -// MIR for `main` after SimplifyCfg-final +// MIR for `main` after PreCodegen fn main() -> () { - let mut _0: (); // return place in scope 0 at $DIR/tls-access.rs:6:11: 6:11 - let _2: *mut u8; // in scope 0 at $DIR/tls-access.rs:8:18: 8:21 - let mut _3: *mut u8; // in scope 0 at $DIR/tls-access.rs:9:9: 9:12 + let mut _0: (); // return place in scope 0 at $DIR/tls-access.rs:9:11: 9:11 + let _2: *mut u8; // in scope 0 at $DIR/tls-access.rs:11:18: 11:21 + let mut _3: *mut u8; // in scope 0 at $DIR/tls-access.rs:12:9: 12:12 scope 1 { - let _1: &u8; // in scope 1 at $DIR/tls-access.rs:8:13: 8:14 + let _1: &u8; // in scope 1 at $DIR/tls-access.rs:11:13: 11:14 scope 2 { - debug a => _1; // in scope 2 at $DIR/tls-access.rs:8:13: 8:14 + debug a => _1; // in scope 2 at $DIR/tls-access.rs:11:13: 11:14 } } bb0: { - StorageLive(_1); // scope 1 at $DIR/tls-access.rs:8:13: 8:14 - StorageLive(_2); // scope 1 at $DIR/tls-access.rs:8:18: 8:21 - StorageLive(_3); // scope 2 at $DIR/tls-access.rs:9:9: 9:12 - _3 = &/*tls*/ mut FOO; // scope 2 at $DIR/tls-access.rs:9:9: 9:12 - (*_3) = const 42_u8; // scope 2 at $DIR/tls-access.rs:9:9: 9:17 - StorageDead(_3); // scope 2 at $DIR/tls-access.rs:9:17: 9:18 - StorageDead(_2); // scope 1 at $DIR/tls-access.rs:10:5: 10:6 - StorageDead(_1); // scope 1 at $DIR/tls-access.rs:10:5: 10:6 - return; // scope 0 at $DIR/tls-access.rs:11:2: 11:2 + StorageLive(_1); // scope 1 at $DIR/tls-access.rs:11:13: 11:14 + StorageLive(_2); // scope 1 at $DIR/tls-access.rs:11:18: 11:21 + _2 = &/*tls*/ mut FOO; // scope 1 at $DIR/tls-access.rs:11:18: 11:21 + _1 = &(*_2); // scope 1 at $DIR/tls-access.rs:11:17: 11:21 + StorageLive(_3); // scope 2 at $DIR/tls-access.rs:12:9: 12:12 + _3 = &/*tls*/ mut FOO; // scope 2 at $DIR/tls-access.rs:12:9: 12:12 + (*_3) = const 42_u8; // scope 2 at $DIR/tls-access.rs:12:9: 12:17 + StorageDead(_3); // scope 2 at $DIR/tls-access.rs:12:17: 12:18 + _0 = const (); // scope 1 at $DIR/tls-access.rs:10:5: 13:6 + StorageDead(_2); // scope 1 at $DIR/tls-access.rs:13:5: 13:6 + StorageDead(_1); // scope 1 at $DIR/tls-access.rs:13:5: 13:6 + return; // scope 0 at $DIR/tls-access.rs:14:2: 14:2 } } From dff602fc18be295d1b87196a6eee1c72673e6bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 31 May 2022 00:00:00 +0000 Subject: [PATCH 4/6] Add a pointer to address cast kind A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable. --- compiler/rustc_borrowck/src/type_check/mod.rs | 20 ++++++++-- compiler/rustc_codegen_cranelift/src/base.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 10 +++-- .../rustc_const_eval/src/interpret/cast.rs | 37 +++++++++++-------- .../src/transform/check_consts/check.rs | 13 ++----- .../src/transform/promote_consts.rs | 16 ++------ compiler/rustc_middle/src/mir/mod.rs | 10 +++++ compiler/rustc_middle/src/mir/tcx.rs | 17 --------- .../src/build/expr/as_rvalue.rs | 15 ++++++-- .../rustc_mir_dataflow/src/impls/liveness.rs | 23 ++++-------- .../src/dead_store_elimination.rs | 4 +- ..._prop_fails_gracefully.main.ConstProp.diff | 2 +- .../reify_fn_ptr.main.ConstProp.diff | 2 +- ...s.pointer_to_int.DeadStoreElimination.diff | 4 +- .../clippy_utils/src/qualify_min_const_fn.rs | 15 +++----- 15 files changed, 96 insertions(+), 94 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 4a2b2942008b8..d9d31ab2c89a1 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -2147,6 +2147,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } + CastKind::PointerAddress => { + let ty_from = op.ty(body, tcx); + let cast_ty_from = CastTy::from_ty(ty_from); + let cast_ty_to = CastTy::from_ty(*ty); + match (cast_ty_from, cast_ty_to) { + (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => (), + _ => { + span_mirbug!(self, rvalue, "Invalid cast {:?} -> {:?}", ty_from, ty) + } + } + } + CastKind::Misc => { let ty_from = op.ty(body, tcx); let cast_ty_from = CastTy::from_ty(ty_from); @@ -2155,7 +2167,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { (None, _) | (_, None | Some(CastTy::FnPtr)) | (Some(CastTy::Float), Some(CastTy::Ptr(_))) - | (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Float)) => { + | ( + Some(CastTy::Ptr(_) | CastTy::FnPtr), + Some(CastTy::Float | CastTy::Int(_)), + ) => { span_mirbug!(self, rvalue, "Invalid cast {:?} -> {:?}", ty_from, ty,) } ( @@ -2163,8 +2178,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Some(CastTy::Int(_) | CastTy::Float | CastTy::Ptr(_)), ) | (Some(CastTy::Float), Some(CastTy::Int(_) | CastTy::Float)) - | (Some(CastTy::Ptr(_)), Some(CastTy::Int(_) | CastTy::Ptr(_))) - | (Some(CastTy::FnPtr), Some(CastTy::Int(_) | CastTy::Ptr(_))) => (), + | (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Ptr(_))) => (), } } } diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 3fe112d794b44..7c59ce354c01a 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -607,7 +607,7 @@ fn codegen_stmt<'tcx>( let operand = codegen_operand(fx, operand); lval.write_cvalue(fx, operand.cast_pointer_to(to_layout)); } - Rvalue::Cast(CastKind::Misc, ref operand, to_ty) => { + Rvalue::Cast(CastKind::Misc | CastKind::PointerAddress, ref operand, to_ty) => { let operand = codegen_operand(fx, operand); let from_ty = operand.layout().ty; let to_ty = fx.monomorphize(to_ty); diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index fd29c9e281b92..bd88aa33372df 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -181,6 +181,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty)); let val = match *kind { + mir::CastKind::PointerAddress => { + assert!(bx.cx().is_backend_immediate(cast)); + let llptr = operand.immediate(); + let llcast_ty = bx.cx().immediate_backend_type(cast); + let lladdr = bx.ptrtoint(llptr, llcast_ty); + OperandValue::Immediate(lladdr) + } mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => { match *operand.layout.ty.kind() { ty::FnDef(def_id, substs) => { @@ -362,9 +369,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Ptr(_)) => { bx.pointercast(llval, ll_t_out) } - (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => { - bx.ptrtoint(llval, ll_t_out) - } (CastTy::Int(_), CastTy::Ptr(_)) => { let usize_llval = bx.intcast(llval, bx.cx().type_isize(), signed); bx.inttoptr(usize_llval, ll_t_out) diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index be34a77bdba96..af563c1450ea0 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -1,3 +1,4 @@ +use std::assert_matches::assert_matches; use std::convert::TryFrom; use rustc_apfloat::ieee::{Double, Single}; @@ -30,6 +31,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.unsize_into(src, cast_ty, dest)?; } + PointerAddress => { + let src = self.read_immediate(src)?; + let res = self.pointer_address_cast(&src, cast_ty)?; + self.write_immediate(res, dest)?; + } + Misc => { let src = self.read_immediate(src)?; let res = self.misc_cast(&src, cast_ty)?; @@ -174,23 +181,23 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // # The remaining source values are scalar and "int-like". let scalar = src.to_scalar()?; + Ok(self.cast_from_int_like(scalar, src.layout, cast_ty)?.into()) + } - // If we are casting from a pointer to something - // that is not a pointer, mark the pointer as exposed - if src.layout.ty.is_any_ptr() && !cast_ty.is_any_ptr() { - let ptr = self.scalar_to_ptr(scalar)?; - - match ptr.into_pointer_or_addr() { - Ok(ptr) => { - M::expose_ptr(self, ptr)?; - } - Err(_) => { - // do nothing, exposing an invalid pointer - // has no meaning - } - }; - } + pub fn pointer_address_cast( + &mut self, + src: &ImmTy<'tcx, M::PointerTag>, + cast_ty: Ty<'tcx>, + ) -> InterpResult<'tcx, Immediate> { + assert_matches!(src.layout.ty.kind(), ty::RawPtr(_) | ty::FnPtr(_)); + assert!(cast_ty.is_integral()); + let scalar = src.to_scalar()?; + let ptr = self.scalar_to_ptr(scalar)?; + match ptr.into_pointer_or_addr() { + Ok(ptr) => M::expose_ptr(self, ptr)?, + Err(_) => {} // do nothing, exposing an invalid pointer has no meaning + }; Ok(self.cast_from_int_like(scalar, src.layout, cast_ty)?.into()) } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index eea6e2a47a94b..4ef33d62a6bfe 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -8,7 +8,6 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{ImplSource, Obligation, ObligationCause}; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt}; use rustc_middle::ty::{Binder, TraitPredicate, TraitRef, TypeFoldable}; @@ -543,16 +542,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { // in the type of any local, which also excludes casts). } - Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => { - let operand_ty = operand.ty(self.body, self.tcx); - let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast"); - let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); - - if let (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) = (cast_in, cast_out) { - self.check_op(ops::RawPtrToIntCast); - } + Rvalue::Cast(CastKind::PointerAddress, _, _) => { + self.check_op(ops::RawPtrToIntCast); } + Rvalue::Cast(CastKind::Misc, _, _) => {} + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => {} Rvalue::ShallowInitBox(_, _) => {} diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index fc6b8a1a7234c..ea23bd14d2538 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -16,7 +16,6 @@ use rustc_hir as hir; use rustc_middle::mir::traversal::ReversePostorderIter; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::{self, List, TyCtxt, TypeFoldable}; use rustc_span::Span; @@ -502,18 +501,11 @@ impl<'tcx> Validator<'_, 'tcx> { Rvalue::ThreadLocalRef(_) => return Err(Unpromotable), - Rvalue::Cast(kind, operand, cast_ty) => { - if matches!(kind, CastKind::Misc) { - let operand_ty = operand.ty(self.body, self.tcx); - let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast"); - let cast_out = CastTy::from_ty(*cast_ty).expect("bad output type for cast"); - if let (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) = (cast_in, cast_out) { - // ptr-to-int casts are not possible in consts and thus not promotable - return Err(Unpromotable); - } - // int-to-ptr casts are fine, they just use the integer value at pointer type. - } + // ptr-to-int casts are not possible in consts and thus not promotable + Rvalue::Cast(CastKind::PointerAddress, _, _) => return Err(Unpromotable), + // int-to-ptr casts are fine, they just use the integer value at pointer type. + Rvalue::Cast(_, operand, _) => { self.validate_operand(operand)?; } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index b09d39996f4de..1b63c8d67ca14 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2604,9 +2604,19 @@ pub enum Rvalue<'tcx> { #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] static_assert_size!(Rvalue<'_>, 40); +impl<'tcx> Rvalue<'tcx> { + #[inline] + pub fn is_pointer_int_cast(&self) -> bool { + matches!(self, Rvalue::Cast(CastKind::PointerAddress, _, _)) + } +} + #[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] pub enum CastKind { Misc, + /// A pointer to address cast. A cast between a pointer and an integer type, + /// or between a function pointer and an integer type. + PointerAddress, Pointer(PointerCast), } diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index f1fb484a801ba..c93b7a9550229 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -4,7 +4,6 @@ */ use crate::mir::*; -use crate::ty::cast::CastTy; use crate::ty::subst::Subst; use crate::ty::{self, Ty, TyCtxt}; use rustc_hir as hir; @@ -224,22 +223,6 @@ impl<'tcx> Rvalue<'tcx> { _ => RvalueInitializationState::Deep, } } - - pub fn is_pointer_int_cast(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> bool - where - D: HasLocalDecls<'tcx>, - { - if let Rvalue::Cast(CastKind::Misc, src_op, dest_ty) = self { - if let Some(CastTy::Int(_)) = CastTy::from_ty(*dest_ty) { - let src_ty = src_op.ty(local_decls, tcx); - if let Some(CastTy::FnPtr | CastTy::Ptr(_)) = CastTy::from_ty(src_ty) { - return true; - } - } - } - - false - } } impl<'tcx> Operand<'tcx> { diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 0a0c7659b086d..2b137046c7f73 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -11,6 +11,7 @@ use rustc_middle::mir::AssertKind; use rustc_middle::mir::Place; use rustc_middle::mir::*; use rustc_middle::thir::*; +use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::{self, Ty, UpvarSubsts}; use rustc_span::Span; @@ -188,11 +189,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(Rvalue::Use(Operand::Move(Place::from(result)))) } ExprKind::Cast { source } => { + let source = &this.thir[source]; + let from_ty = CastTy::from_ty(source.ty); + let cast_ty = CastTy::from_ty(expr.ty); + let cast_kind = match (from_ty, cast_ty) { + (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => { + CastKind::PointerAddress + } + (_, _) => CastKind::Misc, + }; let source = unpack!( - block = - this.as_operand(block, scope, &this.thir[source], None, NeedsTemporary::No) + block = this.as_operand(block, scope, source, None, NeedsTemporary::No) ); - block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty)) + block.and(Rvalue::Cast(cast_kind, source, expr.ty)) } ExprKind::Pointer { cast, source } => { let source = unpack!( diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs index 4350eb6cdd3b1..7076fbe1bdb53 100644 --- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -1,7 +1,6 @@ use rustc_index::bit_set::{BitSet, ChunkedBitSet}; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; -use rustc_middle::mir::{self, Local, LocalDecls, Location, Place, StatementKind}; -use rustc_middle::ty::TyCtxt; +use rustc_middle::mir::{self, Local, Location, Place, StatementKind}; use crate::{Analysis, AnalysisDomain, Backward, CallReturnPlaces, GenKill, GenKillAnalysis}; @@ -193,27 +192,21 @@ impl DefUse { /// This is basically written for dead store elimination and nothing else. /// /// All of the caveats of `MaybeLiveLocals` apply. -pub struct MaybeTransitiveLiveLocals<'a, 'tcx> { +pub struct MaybeTransitiveLiveLocals<'a> { always_live: &'a BitSet, - local_decls: &'a LocalDecls<'tcx>, - tcx: TyCtxt<'tcx>, } -impl<'a, 'tcx> MaybeTransitiveLiveLocals<'a, 'tcx> { +impl<'a> MaybeTransitiveLiveLocals<'a> { /// The `always_alive` set is the set of locals to which all stores should unconditionally be /// considered live. /// /// This should include at least all locals that are ever borrowed. - pub fn new( - always_live: &'a BitSet, - local_decls: &'a LocalDecls<'tcx>, - tcx: TyCtxt<'tcx>, - ) -> Self { - MaybeTransitiveLiveLocals { always_live, local_decls, tcx } + pub fn new(always_live: &'a BitSet) -> Self { + MaybeTransitiveLiveLocals { always_live } } } -impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeTransitiveLiveLocals<'a, 'tcx> { +impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeTransitiveLiveLocals<'a> { type Domain = ChunkedBitSet; type Direction = Backward; @@ -241,7 +234,7 @@ impl<'a> GenKill for TransferWrapper<'a> { } } -impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a, 'tcx> { +impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> { fn apply_statement_effect( &self, trans: &mut Self::Domain, @@ -251,7 +244,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a, 'tcx> { // Compute the place that we are storing to, if any let destination = match &statement.kind { StatementKind::Assign(assign) => { - if assign.1.is_pointer_int_cast(self.local_decls, self.tcx) { + if assign.1.is_pointer_int_cast() { // Pointer to int casts may be side-effects due to exposing the provenance. // While the model is undecided, we should be conservative. See // diff --git a/compiler/rustc_mir_transform/src/dead_store_elimination.rs b/compiler/rustc_mir_transform/src/dead_store_elimination.rs index 84f2ee639e4d8..8becac34ed7ee 100644 --- a/compiler/rustc_mir_transform/src/dead_store_elimination.rs +++ b/compiler/rustc_mir_transform/src/dead_store_elimination.rs @@ -24,7 +24,7 @@ use rustc_mir_dataflow::{impls::MaybeTransitiveLiveLocals, Analysis}; /// The `borrowed` set must be a `BitSet` of all the locals that are ever borrowed in this body. It /// can be generated via the [`get_borrowed_locals`] function. pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitSet) { - let mut live = MaybeTransitiveLiveLocals::new(borrowed, &body.local_decls, tcx) + let mut live = MaybeTransitiveLiveLocals::new(borrowed) .into_engine(tcx, body) .iterate_to_fixpoint() .into_results_cursor(body); @@ -34,7 +34,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS for (statement_index, statement) in bb_data.statements.iter().enumerate().rev() { let loc = Location { block: bb, statement_index }; if let StatementKind::Assign(assign) = &statement.kind { - if assign.1.is_pointer_int_cast(&body.local_decls, tcx) { + if assign.1.is_pointer_int_cast() { continue; } } diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff index 466c286c9d7c9..4fdd4b2b4bb86 100644 --- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff @@ -21,7 +21,7 @@ // + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 // + literal: Const { ty: &i32, val: Unevaluated(FOO, [], None) } _2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 - _1 = move _2 as usize (Misc); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39 + _1 = move _2 as usize (PointerAddress); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39 StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:38: 7:39 StorageDead(_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:39: 7:40 StorageLive(_4); // scope 1 at $DIR/const_prop_fails_gracefully.rs:8:5: 8:12 diff --git a/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff b/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff index 1aeeae91d203f..7eb34ed5469ba 100644 --- a/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff @@ -17,7 +17,7 @@ // mir::Constant // + span: $DIR/reify_fn_ptr.rs:4:13: 4:17 // + literal: Const { ty: fn() {main}, val: Value(Scalar()) } - _2 = move _3 as usize (Misc); // scope 0 at $DIR/reify_fn_ptr.rs:4:13: 4:26 + _2 = move _3 as usize (PointerAddress); // scope 0 at $DIR/reify_fn_ptr.rs:4:13: 4:26 StorageDead(_3); // scope 0 at $DIR/reify_fn_ptr.rs:4:25: 4:26 _1 = move _2 as *const fn() (Misc); // scope 0 at $DIR/reify_fn_ptr.rs:4:13: 4:41 StorageDead(_2); // scope 0 at $DIR/reify_fn_ptr.rs:4:40: 4:41 diff --git a/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff b/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff index 2250159c81667..bf32245e30098 100644 --- a/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff +++ b/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff @@ -19,12 +19,12 @@ StorageLive(_2); // scope 0 at $DIR/provenance_soundness.rs:8:9: 8:11 StorageLive(_3); // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:15 _3 = _1; // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:15 - _2 = move _3 as usize (Misc); // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:24 + _2 = move _3 as usize (PointerAddress); // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:24 StorageDead(_3); // scope 0 at $DIR/provenance_soundness.rs:8:23: 8:24 StorageLive(_4); // scope 1 at $DIR/provenance_soundness.rs:9:9: 9:11 StorageLive(_5); // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:15 _5 = _1; // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:15 - _4 = move _5 as isize (Misc); // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:24 + _4 = move _5 as isize (PointerAddress); // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:24 StorageDead(_5); // scope 1 at $DIR/provenance_soundness.rs:9:23: 9:24 _0 = const (); // scope 0 at $DIR/provenance_soundness.rs:7:32: 10:2 StorageDead(_4); // scope 1 at $DIR/provenance_soundness.rs:10:1: 10:2 diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 78d8f1e213af0..283b20fc24d82 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -125,16 +125,11 @@ fn check_rvalue<'tcx>( Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { check_place(tcx, *place, span, body) }, - Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { - use rustc_middle::ty::cast::CastTy; - let cast_in = CastTy::from_ty(operand.ty(body, tcx)).expect("bad input type for cast"); - let cast_out = CastTy::from_ty(*cast_ty).expect("bad output type for cast"); - match (cast_in, cast_out) { - (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => { - Err((span, "casting pointers to ints is unstable in const fn".into())) - }, - _ => check_operand(tcx, operand, span, body), - } + Rvalue::Cast(CastKind::PointerAddress, _, _) => { + Err((span, "casting pointers to ints is unstable in const fn".into())) + }, + Rvalue::Cast(CastKind::Misc, operand, _) => { + check_operand(tcx, operand, span, body) }, Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), operand, _) => { check_operand(tcx, operand, span, body) From e6b1003c950221a4afac33ecd64877c3ca56ddf8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 30 May 2022 17:56:35 -0700 Subject: [PATCH 5/6] BTreeSet->BTreeMap (fix copy/paste mistake in documentation) Co-authored-by: lcnr --- library/alloc/src/collections/btree/map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 28b44e3acb9da..6027991a0ed2f 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -65,7 +65,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; /// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is /// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. /// The behavior resulting from such a logic error is not specified, but will be encapsulated to the -/// `BTreeSet` that observed the logic error and not result in undefined behavior. This could +/// `BTreeMap` that observed the logic error and not result in undefined behavior. This could /// include panics, incorrect results, aborts, memory leaks, and non-termination. /// /// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::values`], or From 5dae6c1b96cb832d20c2561852fa3504a341d4ad Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Tue, 31 May 2022 12:28:57 +0200 Subject: [PATCH 6/6] alloc: remove repeated word in comment Linux's `checkpatch.pl` reports: ```txt #42544: FILE: rust/alloc/vec/mod.rs:2692: WARNING: Possible repeated word: 'to' + // - Elements are :Copy so it's OK to to copy them, without doing ``` Signed-off-by: Miguel Ojeda --- library/alloc/src/vec/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index d222fcb445f58..fa3fbb865827a 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2470,7 +2470,7 @@ impl ExtendFromWithinSpec for Vec { // SAFETY: // - Both pointers are created from unique slice references (`&mut [_]`) // so they are valid and do not overlap. - // - Elements are :Copy so it's OK to to copy them, without doing + // - Elements are :Copy so it's OK to copy them, without doing // anything with the original values // - `count` is equal to the len of `source`, so source is valid for // `count` reads