|
9 | 9 | // except according to those terms. |
10 | 10 |
|
11 | 11 | use llvm::BasicBlockRef; |
12 | | -use middle::infer; |
13 | | -use middle::ty; |
14 | 12 | use rustc::mir::repr as mir; |
15 | 13 | use trans::adt; |
16 | 14 | use trans::base; |
17 | 15 | use trans::build; |
| 16 | +use trans::attributes; |
18 | 17 | use trans::common::{self, Block}; |
19 | 18 | use trans::debuginfo::DebugLoc; |
20 | 19 | use trans::type_of; |
| 20 | +use trans::type_::Type; |
21 | 21 |
|
22 | 22 | use super::MirContext; |
23 | 23 | use super::operand::OperandValue::{FatPtr, Immediate, Ref}; |
@@ -56,10 +56,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { |
56 | 56 |
|
57 | 57 | // The else branch of the Switch can't be hit, so branch to an unreachable |
58 | 58 | // instruction so LLVM knows that |
59 | | - // FIXME it might be nice to have just one such block (created lazilly), we could |
60 | | - // store it in the "MIR trans" state. |
61 | | - let unreachable_blk = bcx.fcx.new_temp_block("enum-variant-unreachable"); |
62 | | - build::Unreachable(unreachable_blk); |
| 59 | + let unreachable_blk = self.unreachable_block(); |
63 | 60 |
|
64 | 61 | let switch = build::Switch(bcx, discr, unreachable_blk.llbb, targets.len()); |
65 | 62 | assert_eq!(adt_def.variants.len(), targets.len()); |
@@ -164,6 +161,18 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { |
164 | 161 | } |
165 | 162 | } |
166 | 163 |
|
| 164 | + fn unreachable_block(&mut self) -> Block<'bcx, 'tcx> { |
| 165 | + match self.unreachable_block { |
| 166 | + Some(b) => b, |
| 167 | + None => { |
| 168 | + let bl = self.fcx.new_block(false, "unreachable", None); |
| 169 | + build::Unreachable(bl); |
| 170 | + self.unreachable_block = Some(bl); |
| 171 | + bl |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + |
167 | 176 | fn bcx(&self, bb: mir::BasicBlock) -> Block<'bcx, 'tcx> { |
168 | 177 | self.blocks[bb.index()] |
169 | 178 | } |
|
0 commit comments