From 7b2b4faba84c1d43af35397d0103747fe085ee45 Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Sat, 23 Feb 2013 12:15:30 -0800 Subject: [PATCH] Add a test for enum discriminant range overflow. It causes an LLVM assertion for every host/target word-size combination on incoming at the time of this writing. --- src/librustc/middle/trans/adt.rs | 1 - .../run-pass/enum-discrim-range-overflow.rs | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/enum-discrim-range-overflow.rs diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index b4d2be83827..858479eaa64 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -139,7 +139,6 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool) fn load_discr(bcx: block, scrutinee: ValueRef, min: int, max: int) -> ValueRef { let ptr = GEPi(bcx, scrutinee, [0, 0]); - // XXX: write tests for the edge cases here if max + 1 == min { // i.e., if the range is everything. The lo==hi case would be // rejected by the LLVM verifier (it would mean either an diff --git a/src/test/run-pass/enum-discrim-range-overflow.rs b/src/test/run-pass/enum-discrim-range-overflow.rs new file mode 100644 index 00000000000..a6806fba142 --- /dev/null +++ b/src/test/run-pass/enum-discrim-range-overflow.rs @@ -0,0 +1,31 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub enum E64 { + H64 = 0x7FFF_FFFF_FFFF_FFFF, + L64 = 0x8000_0000_0000_0000 +} +pub enum E32 { + H32 = 0x7FFF_FFFF, + L32 = 0x8000_0000 +} + +pub fn f(e64: E64, e32: E32) -> (bool,bool) { + (match e64 { + H64 => true, + L64 => false + }, + match e32 { + H32 => true, + L32 => false + }) +} + +pub fn main() { }