Skip to content

Commit 6076e8b

Browse files
committed
---
yaml --- r: 156419 b: refs/heads/snap-stage3 c: e74e059 h: refs/heads/master i: 156417: f113a5d 156415: bc185d2 v: v3
1 parent bc24a26 commit 6076e8b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: c29a7520e7fb4a5b4d4eccfc594e05793ef6688d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5bcd0a0b5030487613bee37ed38945e42c4e6b85
4+
refs/heads/snap-stage3: e74e059bd428332216d1b780e608cb824bc8c150
55
refs/heads/try: 6601b0501e31d08d3892a2d5a7d8a57ab120bf75
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/trans/adt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,16 @@ fn ensure_struct_fits_in_address_space(ccx: &CrateContext,
471471
scapegoat: ty::t) {
472472
let mut offset = 0;
473473
for &llty in fields.iter() {
474+
// Invariant: offset < ccx.max_obj_size() <= 1<<61
474475
if !packed {
475476
let type_align = machine::llalign_of_min(ccx, llty);
476477
offset = roundup(offset, type_align);
477478
}
479+
// type_align is a power-of-2, so still offset < ccx.max_obj_size()
480+
// llsize_of_alloc(ccx, llty) is also less than ccx.max_obj_size()
481+
// so the sum is less than 1<<62 (and therefore can't overflow).
478482
offset += machine::llsize_of_alloc(ccx, llty);
479483

480-
// We can get away with checking for overflow once per iteration,
481-
// because field sizes are less than 1<<61.
482484
if offset >= ccx.max_obj_size() {
483485
ccx.report_overbig_object(scapegoat);
484486
}
@@ -498,7 +500,8 @@ fn ensure_enum_fits_in_address_space(ccx: &CrateContext,
498500
let discr_size = machine::llsize_of_alloc(ccx, ll_inttype(ccx, discr));
499501
let (field_size, field_align) = union_size_and_align(fields);
500502

501-
// This can't overflow because field_size, discr_size, field_align < 1<<61
503+
// field_align < 1<<32, discr_size <= 8, field_size < MAX_OBJ_SIZE <= 1<<61
504+
// so the sum is less than 1<<62 (and can't overflow).
502505
let total_size = roundup(discr_size, field_align) + field_size;
503506

504507
if total_size >= ccx.max_obj_size() {

0 commit comments

Comments
 (0)