Skip to content

Commit 4e37685

Browse files
committed
Fix max_sz bug that ended up causing us to index incorrectly into a vec of tag types. Add a testcase.
1 parent 6bce296 commit 4e37685

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \
507507
rec-tup.rs \
508508
rec.rs \
509509
simple-obj.rs \
510+
size-and-align.rs \
510511
spawn-fn.rs \
511512
spawn-module-qualified.rs \
512513
spawn.rs \

src/boot/util/common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ let rec max_sz (a:size) (b:size) : size =
686686
| (SIZE_rt_max (b, c), a) when a = c -> max_sz a b
687687
| (SIZE_fixed a, SIZE_fixed b) -> SIZE_fixed (i64_max a b)
688688
| (SIZE_fixed 0L, b) when no_negs b -> b
689-
| (a, SIZE_fixed 0L) when no_negs a -> b
689+
| (a, SIZE_fixed 0L) when no_negs a -> a
690690
| (a, SIZE_fixed b) -> max_sz (SIZE_fixed b) a
691691
| (a, b) when a = b -> a
692692
| (a, b) -> SIZE_rt_max (a, b)

src/test/run-pass/size-and-align.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// -*- rust -*-
2+
3+
use std;
4+
import std._vec;
5+
6+
type clam[T] = tag(a(T, int), b());
7+
8+
fn uhoh[T](vec[clam[T]] v) {
9+
alt (v.(1)) {
10+
case (a[T](t, u)) { log "incorrect"; log u; fail; }
11+
case (b[T]()) { log "correct"; }
12+
}
13+
}
14+
15+
fn main() {
16+
let vec[clam[int]] v = vec(b[int](), b[int](), a[int](42, 17));
17+
uhoh[int](v);
18+
}

0 commit comments

Comments
 (0)