-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error on alignments greater than isize::MAX
#131633
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
This comment has been minimized.
This comment has been minimized.
d11b576
to
0f982de
Compare
This comment has been minimized.
This comment has been minimized.
"test compilation failed even though it shouldn't"... but it's a |
|
0f982de
to
aead2c5
Compare
This comment has been minimized.
This comment has been minimized.
aead2c5
to
ec07317
Compare
#![no_std]
#[repr(align(32768))]
struct Hello;
pub fn foo() -> usize { core::mem::align_of::<Hello>() } This currently compiles fine with error[E0589]: alignment must not be greater than `isize::MAX` bytes
--> src/lib.rs:4:8
|
4 | #[repr(align(32768))]
| ^^^^^^^^^^^^
|
= note: `isize::MAX` is 32767 for the current target
For more information about this error, try `rustc --explain E0589`. |
cc @Patryk27 as prospective maintainer for AVR You are the only targets affected by this, as all other targets have a bound on Do you think this Note that |
ah i see, i was under the impression |
I've never used Rust on an MSP430 with more than 10kB (8+2kB) of RAM. MSP430's max out at 512kB ROM and 66kB RAM. However, from what I can gather, actual existing MSP430s top out at 18kB (16+2kB) of RAM without relying on stuff unsupported by LLVM. Given such constraints, If LLVM gets these features to access 20-bit addresses, I don't see how I'd use such functionality for RAM; you only have 64kB continguous RAM anyway- the other 2kB is a |
I don't think so - I mean, I think ideally we'd throw this error on instantiating the struct, so that a mere fact of such type existing wasn't a failure (as in @zachs18's example), but I think there's no point in doing more complex analysis considering it's already quite an edge case. |
Okay! Then if people using the targets cannot think of a good reason for us to support an alignment greater than |
Unfortunately I don't know that this is the right place to emit this check, so having determined that, its implementation seems correct, but it would be good if someone with experience with |
hmm, recent history (and a coinflip) says... r? @jieyouxu |
I explored an alternative approach doing the error in the same location that the ... on further thought, should this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a reasonable place to check the attribute. I have some nits, but looks good otherwise.
should this
isize::MAX
check be done forrepr(packed(N))
? Sincerepr(packed)
can only lower alignment, it's probably not necessary?
That should be in a follow-up if that is determined desirable.
// ignore values greater than 2^29, a different error will be emitted | ||
if val <= 2_u64.pow(29) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem: please use a self.dcx().delayed_bug("...")
here to assert that an error is emitted
This is a strange one: lets you register an error without emitting it. If compilation ends without any other errors occurring, this will be emitted as a bug. Otherwise, it will be silently dropped. I.e. “expect other errors are emitted” semantics. Useful on code paths that should only be reached when compiling erroneous code.
-- https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/enum.Level.html#variant.DelayedBug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this is good, actually. The delayed bug caught the fact that we didn't even properly check the attr on certain targets in the first place, lmao.
@rustbot author |
ec07317
to
aa0b3c7
Compare
@rustbot ready will open a zulip thread about the potential follow up PR for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, one tiny nit then r=me.
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
aa0b3c7
to
6fc7ce4
Compare
Dropped the redundant |
Rollup of 7 pull requests Successful merges: - rust-lang#131633 (error on alignments greater than `isize::MAX`) - rust-lang#132086 (Tweak E0277 highlighting and "long type" path printing) - rust-lang#132220 (Add GUI regression test for doc struct fields margins) - rust-lang#132225 (Dynamically link run-make support) - rust-lang#132227 (Pass constness with span into lower_poly_trait_ref) - rust-lang#132242 (Support `char::is_digit` in const contexts.) - rust-lang#132243 (Remove `ObligationCause::span()` method) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#131633 - asquared31415:align_isize_max, r=jieyouxu error on alignments greater than `isize::MAX` Fixes rust-lang#131122 On zulip someone had a concern that it was legal to create a type with alignment `isize::MAX + 1`, but I do not believe this should be allowed for `repr(align)`, as `repr(align)` also increases the *size* of the type, and that would be larger than the maximum allowed size of objects. (cc `@workingjubilee` rust-lang#131276)
Fixes #131122
On zulip someone had a concern that it was legal to create a type with alignment
isize::MAX + 1
, but I do not believe this should be allowed forrepr(align)
, asrepr(align)
also increases the size of the type, and that would be larger than the maximum allowed size of objects.(cc @workingjubilee #131276)