Skip to content
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

Always error on SizeOverflow during mir evaluation #63152

Merged
merged 13 commits into from
Aug 7, 2019

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jul 31, 2019

Fix #55878, fix #25116.

r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2019
LL | println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>());
| ---------------------------------------------------
|
= note: `#[deny(const_err)]` on by default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait... the issue describes the snippet above as a soundness hole enabling illegal instructions yet this is using a lint to ensure soundness?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, we'd need to change

if let EvalErrorKind::ReferencedConstant = err.error {
, too

but all of this is just papering over the issue. I think you can also ICE the compiler if you do this size_of call inside a static.

Note that there is no unsoundness. I'm certain that we are hitting

// Allow RalfJ to sleep soundly knowing that even refactorings that remove
// the above error (or silence it under some conditions) will not cause UB
bx.abort();
// We've errored, so we don't have to produce working code.
let layout = bx.cx().layout_of(ty);
bx.load_operand(PlaceRef::new_sized(
bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout))),
layout,
layout.align.abi,
))

We need to redesign this properly.

@estebank what were the tests that broke when you inserted the unconditional delay_span_bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During compilation I got a lot of the following

error: internal compiler error: erroneous constant used
   --> src/libcore/mem/mod.rs:243:5
    |
243 |     intrinsics::size_of::<T>()
    |     ^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: erroneous constant used
   --> src/libcore/num/mod.rs:171:16
    |
171 |         self.0.fmt(f)
    |                ^^^

error: internal compiler error: erroneous constant used
   --> src/libcore/num/dec2flt/algorithm.rs:211:25
    |
211 |                     z = prev_float(z);
    |                         ^^^^^^^^^^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Centril turned it into an error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there is no unsoundness. I'm certain that we are hitting

/me is happy that a block of code commented "Allow RalfJ to sleep soundly" is preventing this from being a soundness issue. ;)

@bors

This comment has been minimized.

@estebank
Copy link
Contributor Author

estebank commented Aug 3, 2019

While I was at it I took a detour to also fix #25116 and give "type too big" errors a span.

@rust-highfive

This comment has been minimized.

src/librustc_codegen_ssa/mir/analyze.rs Outdated Show resolved Hide resolved
src/librustc_codegen_ssa/mir/analyze.rs Outdated Show resolved Hide resolved
src/librustc_codegen_ssa/mir/rvalue.rs Outdated Show resolved Hide resolved
--> $SRC_DIR/libcore/mem/mod.rs:LL:COL
|
LL | intrinsics::size_of::<T>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 18446744073709551615]` is too big for the current architecture
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine merging as is with a FIXME in place for adding a useful (not duplicated) note here. It's likely a bit involeved in the const eval engine, since the way I'm imagining it requires annotating every layout_of call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that too and came to the same conclusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have a way to make a separate label that won't be too hacky. What do you think a good wording for this error would be/what the end result should look like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that there are many situations in const eval that compute layouts and could thus fail. I think we should label each with their own message. If we hardcode a message for just this case it will be nonsensical in all other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed the label altogether and left the main message only

@@ -1,4 +1,8 @@
error: the type `[u8; N]` is too big for the current architecture
--> $DIR/huge-array-simple.rs:12:9
|
LL | let _fat : [u8; (1<<61)+(1<<31)] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That span isn't ideal, but it's hard to do better in the MIR, especially as there may be no HIR local in the case of temporaries. Not sure what to do about it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but at the same time it's a huge improvement over the current "good luck finding where the problem is" state of this error.

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

src/test/ui/huge-enum.rs Outdated Show resolved Hide resolved
@oli-obk
Copy link
Contributor

oli-obk commented Aug 4, 2019

r=me with 32 bit test fixed

@estebank
Copy link
Contributor Author

estebank commented Aug 4, 2019

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Aug 4, 2019

📌 Commit f621f89 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2019
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 6, 2019
Centril added a commit to Centril/rust that referenced this pull request Aug 6, 2019
Always error on `SizeOverflow` during mir evaluation

Fix rust-lang#55878, fix rust-lang#25116.

r? @oli-obk
@Centril
Copy link
Contributor

Centril commented Aug 6, 2019

@bors r- Failed in #63325 (comment).

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 6, 2019
@estebank
Copy link
Contributor Author

estebank commented Aug 6, 2019

@bors try

@bors
Copy link
Contributor

bors commented Aug 6, 2019

⌛ Trying commit 613c0a8 with merge fd57268...

bors added a commit that referenced this pull request Aug 6, 2019
Always error on `SizeOverflow` during mir evaluation

Fix #55878, fix #25116.

r? @oli-obk
@estebank
Copy link
Contributor Author

estebank commented Aug 6, 2019

@Centril will try test all targets?

I moved the failing ui test to compile-fail, as I don't see how to resolve the discrepancy otherwise.

@RalfJung
Copy link
Member

RalfJung commented Aug 6, 2019

will try test all targets?

No. It doesn't really test much more than what is tested in a PR already; the reason to do a try build is if you want a built compiler to download and test locally, or do perf/crater.

// error-pattern: is too big for the current architecture
fn main() {
println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the error here for 32bit vs 64bit, that this cannot be handled by normalization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a span from (at least) one specific target that is present in others:

error[E0080]: the type `[u8; SIZE]` is too big for the current architecture	
  --> $SRC_DIR/libcore/mem/mod.rs:LL:COL	
   |	
LL |     intrinsics::size_of::<T>()	
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^	
   | 	
  ::: $DIR/issue-55878.rs:6:26	
   |	
LL |     println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>());	
   |                          ---------------------------------------------------	

vs

error[E0080]: the type `[u8; SIZE]` is too big for the current architecture	
   | 	
  ::: $DIR/issue-55878.rs:6:26	
   |	
LL |     println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>());	
   |                          ---------------------------------------------------	

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's extremely odd, isn't it?

Normalization could still handle this -- or you use the two-test-cases approach with ignore-32bit and ignore-64bit? AFAIK compile-fail is on the way out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The divergence is not due to 32bit vs 64bit, it's because the dist-i586-gnu-i586-i686-musl rustc seems to be packaged slightly different than the other targets, so we miss core and std information to point spans to. Adding this info was a relatively recent improvement from the last year.

I agree that compile-fail should be discouraged, but short of waiting for us to fix the packaging issue I don't see a good solution to this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see.

Is it possible to ignore musl targets, or so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is but I have no way of knowing a priori wether this is a musl-only discrepancy or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super happy about adding more compile-fail tests, but oh well... :)

@estebank
Copy link
Contributor Author

estebank commented Aug 6, 2019

@bors r=oli-obk

crosses fingers

@bors
Copy link
Contributor

bors commented Aug 6, 2019

📌 Commit 3144b0a has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 6, 2019
@bors
Copy link
Contributor

bors commented Aug 7, 2019

⌛ Testing commit 3144b0a with merge 5421d94...

bors added a commit that referenced this pull request Aug 7, 2019
Always error on `SizeOverflow` during mir evaluation

Fix #55878, fix #25116.

r? @oli-obk
@bors
Copy link
Contributor

bors commented Aug 7, 2019

☀️ Test successful - checks-azure
Approved by: oli-obk
Pushing 5421d94 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 7, 2019
@bors bors merged commit 3144b0a into rust-lang:master Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
6 participants