Commit Graph

99 Commits

Author SHA1 Message Date
clubby789 8ea3b09381 Pass alloc-variant-zeroed to LLVM 2025-08-20 17:08:46 +01:00
Daniel Paoliello 2b22d0f0d2 Make __rust_alloc_error_handler_should_panic a function 2025-07-03 10:52:21 -07:00
Daniel Paoliello 6906b44e1c Change __rust_no_alloc_shim_is_unstable to be a function 2025-06-16 10:54:07 -07:00
Boxy c93005ee65 update cfgs 2025-04-09 12:29:59 +01:00
bjorn3 42de015549 Mark imports of #[rustc_std_internal_symbol] items with this attribute
This ensures that they will be correctly mangled in a future commit.
2025-03-17 14:06:56 +00:00
bjorn3 ae5687e4b0 Fully test the alloc crate through alloctests
For the tests that make use of internal implementation details, we
include the module to test using #[path] in alloctests now.
2025-03-07 19:11:13 +00:00
Kevin Reid 33ee398fda More precisely document Global::deallocate()'s safety.
There is a subtlety which "other conditions must be upheld by the caller"
does not capture: `GlobalAlloc`/`alloc::dealloc()` require that the
provided layout will be *equal*, not just that it "fits", the layout
used to allocate. This is always true here due to how `allocate()`,
`grow()`, and `shrink()` are implemented (they never return a larger
allocation than requested), but that is a non-local property of the
implementation, so it should be documented explicitly.
2025-02-25 13:07:52 -08:00
Michael Goulet a4e7f8f9bf Mark extern blocks as unsafe 2025-02-09 17:11:13 +00:00
Ralf Jung ac9cb908ac turn rustc_box into an intrinsic 2025-01-03 12:01:31 +01:00
bjorn3 b440ef8cdf Move some alloc tests to the alloctests crate
Unit tests directly inside of standard library crates require a very
fragile way of building that is hard to reproduce outside of bootstrap.
2024-12-04 14:32:04 +00:00
m 8542175b6f fix Allocator method names in alloc free function docs 2024-11-24 16:38:29 -08:00
Josh Stone 2ddb91acd1 Check for null in the alloc_zeroed example
We should demonstrate good behavior, just like #99198 did for `alloc`.
2024-11-11 16:30:37 -08:00
Ben Kimock 46761442b0 read_volatile __rust_no_alloc_shim_is_unstable in alloc_zeroed 2024-09-17 22:26:21 -04:00
Ralf Jung 03e8c95809 make basic allocation functions track_caller in Miri for nicer backtraces 2024-09-11 22:38:21 +02:00
The 8472 6d8f0bd930 apply #[optimize(size)] to #[cold] ones and part of the panick machinery 2024-08-14 20:50:04 +02:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
John Arundel a19472a93e Fix doc nits
Many tiny changes to stdlib doc comments to make them consistent (for example
"Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph
breaks, backticks for monospace style, and other minor nits.

https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-26 13:26:33 +01:00
Kevin Reid a9a4830d25 Replace WriteCloneIntoRaw with CloneToUninit. 2024-06-22 08:08:00 -07:00
Mark Rousskov 02f1930595 step cfgs 2024-03-20 08:49:13 -04:00
Matthias Krüger b08837f180 Rollup merge of #122018 - RalfJung:box-custom-alloc, r=oli-obk
only set noalias on Box with the global allocator

As discovered in https://github.com/rust-lang/miri/issues/3341, `noalias` and custom allocators don't go well together.

rustc can now check whether a Box uses the global allocator. This replaces the previous ad-hoc and rather unprincipled check for a zero-sized allocator.

This is the rustc part of fixing that; Miri will also need a patch.
2024-03-05 22:10:02 +01:00
Ralf Jung f391c0793b only set noalias on Box with the global allocator 2024-03-05 15:03:33 +01:00
Ralf Jung 374607d6b9 const_eval_select: make it safe but be careful with what we expose on stable for now 2024-03-02 16:09:31 +01:00
joboet fa9a911a57 libs: use assert_unchecked instead of intrinsic 2024-01-13 20:10:00 +01:00
r0cky c751bfa015 Add proper cfgs 2023-11-28 09:02:34 +08:00
Ben Kimock 2e7364a586 Increase the reach of panic_immediate_abort 2023-10-29 09:31:07 -04:00
Matthias Krüger 32053f7602 Rollup merge of #115280 - RalfJung:panic-cleanup-triple-backtrace, r=Amanieu
avoid triple-backtrace due to panic-during-cleanup

Supersedes https://github.com/rust-lang/rust/pull/115020
Cc https://github.com/rust-lang/rust/issues/114954
r? ``@Amanieu``
2023-08-28 08:13:59 +02:00
Ralf Jung 1087e90a2e avoid triple-backtrace due to panic-during-cleanup 2023-08-27 20:02:46 +02:00
Kevin Reid 3dde25edc4 Correct and expand documentation of handle_alloc_error and set_alloc_error_hook.
Add the following facts:

* `handle_alloc_error` may panic instead of aborting.
* What happens if a hook returns rather than diverging.
* A hook may panic. (This was already demonstrated in an example,
  but not stated in prose.)
* A hook must be sound to call — it cannot assume that it is only
  called by the runtime, since its function pointer can be retrieved by
  safe code.
2023-08-19 13:27:03 -07:00
James Dietz db4a153440 remove additional [allow(unused_unsafe)] 2023-07-24 17:56:38 -04:00
Mark Rousskov 67b0cfc761 Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
DrMeepster a5c6cb888e remove box_free and replace with drop impl 2023-06-16 13:41:06 -07:00
Mark Rousskov 42e757192d Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
bjorn3 66982a383b Prevent insta-stable no alloc shim support
You will need to add the following as replacement for the old __rust_*
definitions when not using the alloc shim.

    #[no_mangle]
    static __rust_no_alloc_shim_is_unstable: u8 = 0;
2023-05-11 14:35:09 +00:00
Matthias Krüger 23a363821d Revert "Report allocation errors as panics"
This reverts commit c9a6e41026.
2023-04-25 00:08:37 +02:00
Matthias Krüger f54dbe6e31 Revert "Remove #[alloc_error_handler] from the compiler and library"
This reverts commit abc0660118.
2023-04-25 00:08:35 +02:00
Matthias Krüger 33253fa6a4 Revert "Rename -Zoom=panic to -Zoom=unwind"
This reverts commit 4b981c2648.
2023-04-25 00:08:33 +02:00
Amanieu d'Antras 4b981c2648 Rename -Zoom=panic to -Zoom=unwind 2023-04-16 11:50:32 -07:00
Amanieu d'Antras abc0660118 Remove #[alloc_error_handler] from the compiler and library 2023-04-16 08:35:50 -07:00
Amanieu d'Antras c9a6e41026 Report allocation errors as panics 2023-04-16 08:35:44 -07:00
Jubilee Young e34ad76363 Remove ~const from alloc 2023-03-28 10:37:16 -07:00
André Vennberg 0b35f448f8 Remove various double spaces in source comments. 2023-01-14 17:22:04 +01:00
Michael Goulet f6b0f4707b Rollup merge of #106045 - RalfJung:oom-nounwind-panic, r=Amanieu
default OOM handler: use non-unwinding panic, to match std handler

The OOM handler in std will by default abort. This adjusts the default in liballoc to do the same, using the `can_unwind` flag on the panic info to indicate a non-unwinding panic.

In practice this probably makes little difference since the liballoc default will only come into play in no-std situations where people write a custom panic handler, which most likely will not implement unwinding. But still, this seems more consistent.

Cc `@rust-lang/wg-allocators,` https://github.com/rust-lang/rust/issues/66741
2023-01-03 17:19:26 -08:00
Ralf Jung 5974f6f0a5 default OOM handler: use non-unwinding panic (unless -Zoom=panic is set), to match std handler 2023-01-02 16:35:14 +01:00
jonathanCogan db47071df2 Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
Pietro Albini 11191279b7 Update bootstrap cfg 2022-12-28 09:18:43 -05:00
Mark Rousskov 40290505fb cfg-step code 2022-11-06 17:21:21 -05:00
Amanieu d'Antras 56074b5231 Rewrite implementation of #[alloc_error_handler]
The new implementation doesn't use weak lang items and instead changes
`#[alloc_error_handler]` to an attribute macro just like
`#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by
the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom`
function is defined in any crate then the compiler shim will call
`__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with
`default_alloc_error_handler`: `__rg_oom` was previously defined in the
alloc crate and would attempt to reference the `oom` lang item, even if
it didn't exist. This worked as long as `__rg_oom` was excluded from
linking since it was not called.

This is a prerequisite for the stabilization of
`default_alloc_error_handler` (#102318).
2022-10-31 16:32:57 +00:00
Ralf Jung 2b50cd1877 rename rustc_allocator_nounwind to rustc_nounwind 2022-10-11 22:47:31 +02:00
Mark Rousskov 154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Augie Fackler 130a1df71e codegen: use new {re,de,}allocator annotations in llvm
This obviates the patch that teaches LLVM internals about
_rust_{re,de}alloc functions by putting annotations directly in the IR
for the optimizer.

The sole test change is required to anchor FileCheck to the body of the
`box_uninitialized` method, so it doesn't see the `allocalign` on
`__rust_alloc` and get mad about the string `alloca` showing up. Since I
was there anyway, I added some checks on the attributes to prove the
right attributes got set.

While we're here, we also emit allocator attributes on
__rust_alloc_zeroed. This should allow LLVM to perform more
optimizations for zeroed blocks, and probably fixes #90032. [This
comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157)
mentions "weird UB-like behaviour with bitvec iterators in
rustc_data_structures" so we may need to back this change out if things
go wrong.

The new test cases require LLVM 15, so we copy them into LLVM
14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-26 09:43:28 -04:00