rust/compiler
bors 5d328a1f62 Auto merge of #117329 - RalfJung:offset-by-zero, r=oli-obk,scottmcm
offset: allow zero-byte offset on arbitrary pointers

As per prior `@rust-lang/opsem` [discussion](https://github.com/rust-lang/opsem-team/issues/10) and [FCP](https://github.com/rust-lang/unsafe-code-guidelines/issues/472#issuecomment-1793409130):

- Zero-sized reads and writes are allowed on all sufficiently aligned pointers, including the null pointer
- Inbounds-offset-by-zero is allowed on all pointers, including the null pointer
- `offset_from` on two pointers derived from the same allocation is always allowed when they have the same address

This removes surprising UB (in particular, even C++ allows "nullptr + 0", which we currently disallow), and it brings us one step closer to an important theoretical property for our semantics ("provenance monotonicity": if operations are valid on bytes without provenance, then adding provenance can't make them invalid).

The minimum LLVM we require (v17) includes https://reviews.llvm.org/D154051, so we can finally implement this.

The `offset_from` change is needed to maintain the equivalence with `offset`: if `let ptr2 = ptr1.offset(N)` is well-defined, then `ptr2.offset_from(ptr1)` should be well-defined and return N. Now consider the case where N is 0 and `ptr1` dangles: we want to still allow offset_from here.

I think we should change offset_from further, but that's a separate discussion.

Fixes https://github.com/rust-lang/rust/issues/65108
[Tracking issue](https://github.com/rust-lang/rust/issues/117945) | [T-lang summary](https://github.com/rust-lang/rust/pull/117329#issuecomment-1951981106)

Cc `@nikic`
2024-05-22 13:04:14 +00:00
..
rustc Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...` 2024-05-02 19:48:29 +02:00
rustc_abi Temporarily revert to NonZeroUsize in rustc-abi to fix building on stable 2024-05-18 11:27:29 +03:00
rustc_arena
rustc_ast Auto merge of #125326 - weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors 2024-05-22 04:14:08 +00:00
rustc_ast_ir Remove `extern crate rustc_macros` from numerous crates. 2024-04-29 10:21:54 +10:00
rustc_ast_lowering Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
rustc_ast_passes Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_ast_pretty Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
rustc_attr Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_baked_icu_data
rustc_borrowck Uplift OutlivesPredicate, remove a bunch of unnecessary associated types from Interner 2024-05-21 17:00:45 -04:00
rustc_builtin_macros Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_codegen_cranelift Rollup merge of #125266 - workingjubilee:stream-plastic-love, r=RalfJung,nikic 2024-05-21 12:47:06 +02:00
rustc_codegen_gcc Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
rustc_codegen_llvm Rollup merge of #125266 - workingjubilee:stream-plastic-love, r=RalfJung,nikic 2024-05-21 12:47:06 +02:00
rustc_codegen_ssa Auto merge of #124676 - djkoloski:relax_multiple_sanitizers, r=cuviper,rcvalle 2024-05-21 15:35:29 +00:00
rustc_const_eval Auto merge of #117329 - RalfJung:offset-by-zero, r=oli-obk,scottmcm 2024-05-22 13:04:14 +00:00
rustc_data_structures Rollup merge of #124818 - compiler-errors:ena, r=Mark-Simulacrum 2024-05-11 08:00:15 +02:00
rustc_driver
rustc_driver_impl Don't call `env::set_var` in `rustc_driver::install_ice_hook` 2024-05-13 09:37:29 +02:00
rustc_error_codes Remove a stray backtick in an error explanation. 2024-05-13 07:53:38 +10:00
rustc_error_messages Rename `SubdiagnosticMessage` as `SubdiagMessage`. 2024-03-05 12:14:49 +11:00
rustc_errors Auto merge of #125335 - compiler-errors:binder, r=lcnr 2024-05-22 08:33:34 +00:00
rustc_expand Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_feature Auto merge of #125326 - weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors 2024-05-22 04:14:08 +00:00
rustc_fluent_macro Rename `SubdiagnosticMessage` as `SubdiagMessage`. 2024-03-05 12:14:49 +11:00
rustc_fs_util Stabilize `std::path::absolute` 2024-04-24 14:35:02 +00:00
rustc_graphviz
rustc_hir Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
rustc_hir_analysis Auto merge of #125335 - compiler-errors:binder, r=lcnr 2024-05-22 08:33:34 +00:00
rustc_hir_pretty Rollup merge of #125158 - Nilstrieb:block-indent, r=compiler-errors 2024-05-21 00:47:02 +02:00
rustc_hir_typeck Auto merge of #124227 - compiler-errors:hack-check-method-res, r=estebank 2024-05-22 10:57:59 +00:00
rustc_incremental Auto merge of #123441 - saethlin:fixed-len-file-names, r=oli-obk 2024-05-03 17:41:48 +00:00
rustc_index Simplify `static_assert_size`s. 2024-04-18 15:36:25 +10:00
rustc_index_macros rustc_index: Add a `ZERO` constant to index types 2024-04-03 19:06:22 +03:00
rustc_infer Uplift OutlivesPredicate, remove a bunch of unnecessary associated types from Interner 2024-05-21 17:00:45 -04:00
rustc_interface Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_lexer Improved the compiler code with clippy 2024-04-24 09:41:44 +02:00
rustc_lint Fix typo in deprecation lint message 2024-05-21 20:16:39 +00:00
rustc_lint_defs Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_llvm Update cc crate to v1.0.97 2024-05-08 15:06:35 +00:00
rustc_log Construct `SourceMap` at the same time as `SessionGlobals`. 2024-04-16 13:02:53 +10:00
rustc_macros Fix subdiagnostic-only enum variants not generating code 2024-05-21 20:11:42 +00:00
rustc_metadata Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_middle Auto merge of #125335 - compiler-errors:binder, r=lcnr 2024-05-22 08:33:34 +00:00
rustc_mir_build Rollup merge of #125173 - scottmcm:never-checked, r=davidtwco 2024-05-20 18:13:48 +02:00
rustc_mir_dataflow Remove `Rvalue::CheckedBinaryOp` 2024-05-17 20:33:02 -07:00
rustc_mir_transform Rollup merge of #125173 - scottmcm:never-checked, r=davidtwco 2024-05-20 18:13:48 +02:00
rustc_monomorphize Add and use generics.is_empty() and generics.is_own_empty, rather than using generics' attributes 2024-05-19 11:10:56 -03:00
rustc_next_trait_solver Uplift binder 2024-05-21 17:00:45 -04:00
rustc_parse Auto merge of #124417 - Xiretza:translate-early-lints, r=fmease 2024-05-21 21:36:09 +00:00
rustc_parse_format Simplify `static_assert_size`s. 2024-04-18 15:36:25 +10:00
rustc_passes Auto merge of #125326 - weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors 2024-05-22 04:14:08 +00:00
rustc_pattern_analysis Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
rustc_privacy split out AliasTy -> AliasTerm 2024-05-13 11:59:42 -04:00
rustc_query_impl Remove `extern crate rustc_middle` from `rustc_query_impl`. 2024-05-13 08:20:18 +10:00
rustc_query_system Remove some unneeded `Cargo.toml` dependencies. 2024-05-03 15:33:52 +10:00
rustc_resolve Auto merge of #125326 - weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors 2024-05-22 04:14:08 +00:00
rustc_sanitizers Fix typos (taking into account review comments) 2024-05-18 18:12:18 +02:00
rustc_serialize Step bootstrap cfgs 2024-05-01 22:19:11 -04:00
rustc_session Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_smir Uplift OutlivesPredicate, remove a bunch of unnecessary associated types from Interner 2024-05-21 17:00:45 -04:00
rustc_span Auto merge of #125358 - matthiaskrgr:rollup-mx841tg, r=matthiaskrgr 2024-05-21 12:50:09 +00:00
rustc_symbol_mangling Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
rustc_target Auto merge of #124676 - djkoloski:relax_multiple_sanitizers, r=cuviper,rcvalle 2024-05-21 15:35:29 +00:00
rustc_trait_selection Auto merge of #125335 - compiler-errors:binder, r=lcnr 2024-05-22 08:33:34 +00:00
rustc_traits split out AliasTy -> AliasTerm 2024-05-13 11:59:42 -04:00
rustc_transmute Align: add bytes_usize and bits_usize 2024-05-01 15:57:33 +02:00
rustc_ty_utils Rollup merge of #125173 - scottmcm:never-checked, r=davidtwco 2024-05-20 18:13:48 +02:00
rustc_type_ir Uplift OutlivesPredicate, remove a bunch of unnecessary associated types from Interner 2024-05-21 17:00:45 -04:00
rustc_type_ir_macros Uplift `TraitPredicate` 2024-05-11 18:20:00 -04:00
stable_mir Implement BOXED_SLICE_INTO_ITER 2024-05-20 19:21:30 -04:00