-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
In consteval, mixing pointers to the same allocation but with different offsets gives results that depend on a static's address. #146291
Copy link
Copy link
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullC-bugCategory: This is a bug.Category: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-opsemRelevant to the opsem teamRelevant to the opsem teamregression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullC-bugCategory: This is a bug.Category: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-opsemRelevant to the opsem teamRelevant to the opsem teamregression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Code
I tried this code:
I expected this to produce a compile error. Instead, in nightly rust, it compiles fine. The resulting program sometimes (but not always) produces an assertion failure.
(Note that the two pointers differ by exactly
0x100000000.)The
mix_ptrfunction returns a pointer whose high 4 bytes are from(&raw const A).wrapping_add(1000000000), and whose low 4 bytes are from&raw const A.Consteval seems to be incorrectly assuming that the resulting pointer is equivalent to
&raw const A. This is wrong when the address ofAis within 1000000000 bytes of an address that is a multiple of2^32.Jointly discovered with @HomelikeBrick42
Presumably regressed in #144081. cc @RalfJung
Version it worked on
The above code correctly produces a compiler error on the playground with version
1.90.0-beta.7 (2025-08-29 fb918cec013920472f69)Version with regression
The above code compiles and has incorrect behavior on the playground with version
1.91.0-nightly (2025-09-06 1ed3cd7030718935a5c5)