Commit Graph

57 Commits

Author SHA1 Message Date
Ralf Jung
e3b1966137 make the const-unstable-in-stable error more clear 2024-08-31 15:11:48 +02:00
Ralf Jung
7a290fce90 interpret: do not make const-eval query result depend on tcx.sess 2024-08-26 17:08:52 +02:00
Ralf Jung
ba24121ad6 tweak rustc_allow_const_fn_unstable hint, and add back test for stable-const-can-only-call-stable-const 2024-08-25 13:50:55 +02:00
Pavel Grigorenko
a11922d568 rustc_const_eval: make LazyLock suggestion translatable 2024-08-10 14:32:55 +03:00
Pavel Grigorenko
3a18c6b55f rustc_const_eval: make message about "const stable" translatable 2024-08-10 14:32:55 +03:00
Matthias Krüger
67fcb58347
Rollup merge of #128453 - RalfJung:raw_eq, r=saethlin
raw_eq: using it on bytes with provenance is not UB (outside const-eval)

The current behavior of raw_eq violates provenance monotonicity. See https://github.com/rust-lang/rust/pull/124921 for an explanation of provenance monotonicity. It is violated in raw_eq because comparing bytes without provenance is well-defined, but adding provenance makes the operation UB.

So remove the no-provenance requirement from raw_eq. However, the requirement stays in-place for compile-time invocations of raw_eq, that indeed cannot deal with provenance.

Cc `@rust-lang/opsem`
2024-08-02 06:43:43 +02:00
Ralf Jung
db1652e07b fix the way we detect overflow for inbounds arithmetic (and tweak the error message) 2024-08-01 14:38:58 +02:00
Ralf Jung
de78cb56b2 on a signed deref check, mention the right pointer in the error 2024-08-01 14:25:19 +02:00
Ralf Jung
f97aba2271 raw_eq: using it on bytes with provenance is not UB (outside const-eval) 2024-07-31 20:26:20 +02:00
Ralf Jung
f8ebe8d783 improve dangling/oob errors and make them more uniform 2024-07-27 21:12:54 +02:00
Ralf Jung
5b38b149dc miri: fix offset_from behavior on wildcard pointers 2024-07-27 17:18:35 +02:00
Ralf Jung
763e3131cc don't ICE when encountering an extern type field during validation 2024-06-22 17:39:01 +02:00
Michael Goulet
ffd72b1700 Fix remaining cases 2024-06-21 19:00:18 -04:00
León Orell Valerian Liehr
035285b464
Rollup merge of #126154 - RalfJung:storage-live, r=compiler-errors
StorageLive: refresh storage (instead of UB) when local is already live

Blocked on [this FCP](https://github.com/rust-lang/rust/issues/99160#issuecomment-2155924538), which also contains the motivation.

Fixes https://github.com/rust-lang/rust/issues/99160
Fixes https://github.com/rust-lang/rust/issues/98896 (by declaring it not-a-bug)
Fixes https://github.com/rust-lang/rust/issues/119366
Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/129
2024-06-19 13:04:58 +02:00
Oli Scherer
4e5dfb61e4 Remove an unused validation error variant 2024-06-17 10:55:42 +00:00
Ralf Jung
9b05e154f3 StorageLive: refresh storage (instead of UB) when local is already live 2024-06-08 12:24:48 +02:00
Ralf Jung
c0b4b454c3 interpret: make overflowing binops just normal binops 2024-05-21 14:50:09 +02:00
Ralf Jung
41d36a0951 interpret/miri: better errors on failing offset_from 2024-05-09 13:09:47 +02:00
Ralf Jung
875f0c2da0 Miri: detect wrong vtables in wide pointers 2024-04-21 13:04:51 +02:00
Oli Scherer
64b75f736d Forbid implicit nested statics in thread local statics 2024-04-02 13:00:46 +00:00
Ben Kimock
9e0d1a3284 Print a backtrace in const eval if interrupted 2024-03-17 11:55:20 -04:00
Oli Scherer
a316c21dc8 Rename some things around validation error reporting to signal that it is in fact about validation failures 2024-03-14 12:21:35 +00:00
Matthias Krüger
fdcd05178d
Rollup merge of #121860 - mu001999:master, r=Nilstrieb
Add a tidy check that checks whether the fluent slugs only appear once

As ``````@Nilstrieb`````` said in https://github.com/rust-lang/rust/pull/121828#issuecomment-1972622855:
> Might make sense to have a tidy check that checks whether the fluent slugs only appear once in the source code and lint for that
there's a tidy check already for sorting

We can get the tidy check error:
```
tidy check
tidy error: /path/to/rust/compiler/rustc_const_eval/messages.ftl: message `const_eval_invalid_align` is not used
tidy error: /path/to/rust/compiler/rustc_lint/messages.ftl: message `lint_trivial_untranslatable_diag` is not used
tidy error: /path/to/rust/compiler/rustc_parse/messages.ftl: message `parse_invalid_literal_suffix` is not used
tidy error: /path/to/rust/compiler/rustc_infer/messages.ftl: message `infer_need_type_info_in_coroutine` is not used
tidy error: /path/to/rust/compiler/rustc_passes/messages.ftl: message `passes_expr_not_allowed_in_context` is not used
tidy error: /path/to/rust/compiler/rustc_passes/messages.ftl: message `passes_layout` is not used
tidy error: /path/to/rust/compiler/rustc_parse/messages.ftl: message `parse_not_supported` is not used
```

r? ``````@Nilstrieb``````
2024-03-10 10:58:16 +01:00
Matthias Krüger
d774fbea7c
Rollup merge of #119365 - nbdd0121:asm-goto, r=Amanieu
Add asm goto support to `asm!`

Tracking issue: #119364

This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto).

Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary.

r? ``@Amanieu``
cc ``@ojeda``
2024-03-08 08:19:17 +01:00
r0cky
d88c7ffc62 Remove unused fluent messages 2024-03-03 00:57:45 +08:00
Ralf Jung
3cc8c8d44b allow statics pointing to mutable statics 2024-02-29 09:34:15 +01:00
Gary Guo
b044aaa905 Change InlineAsm to allow multiple targets instead 2024-02-24 18:50:09 +00:00
Ralf Jung
0702701297 allow mutable references in const values when they point to no memory 2024-02-16 10:09:12 +01:00
Oli Scherer
73b38c661d Do not allocate a second "background" alloc id for the main allocation of a static.
Instead we re-use the static's alloc id within the interpreter for its initializer to refer to the `Allocation` that only exists within the interpreter.
2024-02-15 10:25:18 +00:00
Matthias Krüger
09bbcd6667
Rollup merge of #120883 - RalfJung:extern-static-err, r=oli-obk
interpret: rename ReadExternStatic → ExternStatic

This error shows up for reads and writes, so `ReadExternStatic` is misleading.
2024-02-11 01:37:56 +01:00
Matthias Krüger
e82e087582
Rollup merge of #120882 - RalfJung:set-discriminant, r=compiler-errors
interpret/write_discriminant: when encoding niched variant, ensure the stored value matches

Cc https://github.com/rust-lang/unsafe-code-guidelines/issues/487
2024-02-11 01:37:55 +01:00
Ralf Jung
77f8c3caea detect consts that reference extern statics 2024-02-10 16:13:48 +01:00
Ralf Jung
9c0623fe8f validation: descend from consts into statics 2024-02-10 16:13:47 +01:00
Ralf Jung
4e77e368eb unstably allow constants to refer to statics and read from immutable statics 2024-02-10 16:12:55 +01:00
Ralf Jung
d56f3b6a5d interpret: rename ReadExternStatic → ExternStatic 2024-02-10 16:06:02 +01:00
Ralf Jung
18ed966ab5 interpret/write_discriminant: when encoding niched variant, ensure the stored value matches 2024-02-10 15:33:58 +01:00
Ralf Jung
0288a0bfa0 raw pointers are not references 2024-01-22 09:28:00 +01:00
Ralf Jung
2f1a8e2d7a const-eval interner: from-scratch rewrite using mutability information from provenance rather than types 2024-01-22 09:28:00 +01:00
Ralf Jung
4d93590d59 compile-time evaluation: emit a lint when a write through an immutable pointer occurs 2023-12-07 17:46:36 +01:00
Ralf Jung
e24835c6e0 more precise error for 'based on misaligned pointer' case 2023-10-15 18:13:33 +02:00
Ralf Jung
b1ebf002c3 don't UB on dangling ptr deref, instead check inbounds on projections 2023-10-15 18:12:46 +02:00
Ralf Jung
9ac8b363e3 don't point at const usage site for resolution-time errors
also share the code that emits the actual error
2023-09-14 22:34:05 +02:00
Ralf Jung
a09df43d9f move marking-locals-live out of push_stack_frame, so it happens with argument passing
this entirely avoids even creating unsized locals in Immediate::Uninitialized state
2023-08-30 13:46:54 +02:00
Ralf Jung
a7132bf387 interpret: remove incomplete protection against invalid where clauses 2023-08-08 10:35:22 +02:00
Ralf Jung
7767cbb3b0 const validation: point at where we found a pointer but expected an integer 2023-08-02 18:51:50 +02:00
Ralf Jung
8496292dda properly track why we checked whether a pointer is in-bounds
also simplify the in-bounds checking in Miri's borrow trackers
2023-08-01 17:57:13 +02:00
Ralf Jung
a2bcafa500 interpret: refactor projection code to work on a common trait, and use that for visitors 2023-07-25 14:30:58 +02:00
Ralf Jung
a593de4fab interpret: support projecting into Place::Local without force_allocation 2023-07-24 15:35:47 +02:00
David Tolnay
5bbf0a8306
Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"
This reverts commit 557359f925, reversing
changes made to 1e6c09a803.
2023-07-21 22:35:57 -07:00
Moulins
76c49aead6 support non-null pointer niches in CTFE 2023-07-21 03:31:45 +02:00