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

Properly fail on type size overflows in LLVM #18041

Closed
wants to merge 11 commits into from

Conversation

arielb1
Copy link
Contributor

@arielb1 arielb1 commented Oct 14, 2014

Should fix #17913.

Also clean-up u64/u32-ness. I really should split this commit and add tests (I have no idea how to add them).

@arielb1 arielb1 force-pushed the no-size-overflow branch 2 times, most recently from ebfbbba to 73f1c7d Compare October 14, 2014 20:18
@arielb1 arielb1 changed the title Ensure oversized types don't trigger unsafety Properly fail on type size overflows in LLVM Oct 14, 2014
@klutzy
Copy link
Contributor

klutzy commented Oct 15, 2014

Does it pass on 32-bit as well? (test/run-pass/vec-fixed-length.rs overflows on 32-bit, so cfg!() should be changed to #[cfg])

Use the integer sizes LLVM uses, rather than having random projections
laying around. Sizes are u64, Alignments are u32, C_*int is target-dependent
but 64-bit is fine (the int -> C_int conversion is non-precision-losing,
but it can be preceded by `as int` conversions which are, so it is
somewhat ugly. However, being able to suffix a `u` to properly infer
integer types is nice).
LLVM generates wrong code (which may be an instance of compile-time UB) when
faced with types that take lots of memory - bigger than the address space.
Make using such types a trans error. While trans errors are bad, overbig
types are expected to be very rare.
@arielb1
Copy link
Contributor Author

arielb1 commented Oct 15, 2014

@klutzy

The tests should all pass on 32-bit as well. Actually currently I have a compile-time-object size limit of 2GiB on both 32 and 64-bit architectures (because I was too lazy to make it work properly).

@nikomatsakis nikomatsakis self-assigned this Oct 15, 2014
@nikomatsakis
Copy link
Contributor

I'll review this.

@alexcrichton any idea why high-five didn't kick in here?

@nikomatsakis
Copy link
Contributor

OK, so I looked it over; it looks close, I had a few questions.

@nikomatsakis
Copy link
Contributor

Oh, also, because I didn't say it explicitly: thanks a lot for tackling this so promptly! I'm excited to see this hole get closed.

@alexcrichton
Copy link
Member

@nikomatsakis I think that @nick29581 hasn't set up high-5 to work on all PRs just yet, it's just new contributors and those with r? @foo that get assignees

@nikomatsakis
Copy link
Contributor

@arielb1 Thanks. I'd still like to see the logic in the coment that rounds up fieldsize etc spelled out a bit more (presuming you don't want to use checked adds) -- also, can you add a comment to the max_obj_size() function explaining what limits are placed on its result? (in particular, why it is not uint::max or whatever)

@arielb1
Copy link
Contributor Author

arielb1 commented Oct 15, 2014

If const calculations don't truncate integers before they get here divisions would get the wrong result – so that would be a bug.

@arielb1
Copy link
Contributor Author

arielb1 commented Oct 16, 2014

This PR does not fix all problems – more investigation is needed (issues #18069 and #18072).

On 32-bit architectures, the size calculations on two of the tests wrap-around
in typeck, which gives the relevant arrays a size of 0, which is (correctly)
successfully allocated.
bors added a commit that referenced this pull request Oct 18, 2014
Should fix #17913.

Also clean-up u64/u32-ness. I really should split this commit and add tests (I have no idea how to add them).
@bors bors closed this Oct 18, 2014
@arielb1 arielb1 deleted the no-size-overflow branch March 16, 2015 21:34
lnicola pushed a commit to lnicola/rust that referenced this pull request Sep 25, 2024
feat: better name suggestions for fn

fix rust-lang#17631.

Better name suggestions for fn-calls / method-calls in the form of `from()`, `from_xxx()`, `into()`, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prevent size overflows in the type system
7 participants