Skip to content

Commit

Permalink
auto merge of rust-lang#9484 : alexcrichton/rust/fix-cfg-inner-item, …
Browse files Browse the repository at this point in the history
…r=pcwalton

If an item is skipped due to it being unreachable or for some optimization, then
it shouldn't be encoded into the metadata (because it wasn't present in the
first place).
  • Loading branch information
bors committed Sep 26, 2013
2 parents f210a16 + daee1b4 commit 48499c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use syntax::ast;
use syntax::ast::Name;
use syntax::ast_util;
use syntax::codemap::Span;
use syntax::visit::Visitor;

pub fn trans_block(bcx: @mut Block, b: &ast::Block, dest: expr::Dest) -> @mut Block {
let _icx = push_ctxt("trans_block");
Expand Down Expand Up @@ -64,12 +65,22 @@ pub fn trans_if(bcx: @mut Block,
// Drop branches that are known to be impossible
if is_const(cond_val) && !is_undef(cond_val) {
if const_to_uint(cond_val) == 1 {
match els {
Some(elexpr) => {
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx };
trans.visit_expr(elexpr, ());
}
None => {}
}
// if true { .. } [else { .. }]
return do with_scope(bcx, thn.info(), "if_true_then") |bcx| {
let bcx_out = trans_block(bcx, thn, dest);
trans_block_cleanups(bcx_out, block_cleanups(bcx))
}
} else {
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx } ;
trans.visit_block(thn, ());

match els {
// if false { .. } else { .. }
Some(elexpr) => {
Expand Down
17 changes: 17 additions & 0 deletions src/test/auxiliary/cfg_inner_static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// this used to just ICE on compiling
pub fn foo() {
if cfg!(foo) {
static a: int = 3;
a
} else { 3 };
}
18 changes: 18 additions & 0 deletions src/test/run-pass/cfg_inner_static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:cfg_inner_static.rs
// xfail-fast

extern mod cfg_inner_static;

fn main() {
cfg_inner_static::foo();
}

0 comments on commit 48499c7

Please sign in to comment.