about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/trans/controlflow.rs11
-rw-r--r--src/test/auxiliary/cfg_inner_static.rs17
-rw-r--r--src/test/run-pass/cfg_inner_static.rs18
3 files changed, 46 insertions, 0 deletions
diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs
index 2bf4e5c2bc6..bfa7beace8c 100644
--- a/src/librustc/middle/trans/controlflow.rs
+++ b/src/librustc/middle/trans/controlflow.rs
@@ -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");
@@ -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) => {
diff --git a/src/test/auxiliary/cfg_inner_static.rs b/src/test/auxiliary/cfg_inner_static.rs
new file mode 100644
index 00000000000..4331a1da2a2
--- /dev/null
+++ b/src/test/auxiliary/cfg_inner_static.rs
@@ -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 };
+}
diff --git a/src/test/run-pass/cfg_inner_static.rs b/src/test/run-pass/cfg_inner_static.rs
new file mode 100644
index 00000000000..2d06a10a05f
--- /dev/null
+++ b/src/test/run-pass/cfg_inner_static.rs
@@ -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();
+}