]> git.lizzy.rs Git - rust.git/commitdiff
debuginfo: Fix an ICE related to local variables in unreachable code.
authorMichael Woerister <michaelwoerister@posteo>
Thu, 1 Jan 2015 17:43:48 +0000 (18:43 +0100)
committerMichael Woerister <michaelwoerister@posteo>
Thu, 1 Jan 2015 17:43:48 +0000 (18:43 +0100)
src/librustc_trans/trans/debuginfo.rs
src/test/debuginfo/unreachable-locals.rs [new file with mode: 0644]

index bce446b741271c3c5bb50c6e422f383565b8ab8c..95b8fdb2ec9993bb2b0c13927c7c5de1a6027d45 100644 (file)
@@ -853,7 +853,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
 /// local in `bcx.fcx.lllocals`.
 /// Adds the created metadata nodes directly to the crate's IR.
 pub fn create_local_var_metadata(bcx: Block, local: &ast::Local) {
-    if fn_should_be_ignored(bcx.fcx) {
+    if bcx.unreachable.get() || fn_should_be_ignored(bcx.fcx) {
         return;
     }
 
@@ -897,7 +897,7 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                                                 env_index: uint,
                                                 captured_by_ref: bool,
                                                 span: Span) {
-    if fn_should_be_ignored(bcx.fcx) {
+    if bcx.unreachable.get() || fn_should_be_ignored(bcx.fcx) {
         return;
     }
 
@@ -980,7 +980,7 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
 pub fn create_match_binding_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                                                  variable_ident: ast::Ident,
                                                  binding: BindingInfo<'tcx>) {
-    if fn_should_be_ignored(bcx.fcx) {
+    if bcx.unreachable.get() || fn_should_be_ignored(bcx.fcx) {
         return;
     }
 
@@ -1020,7 +1020,7 @@ pub fn create_match_binding_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
 /// argument in `bcx.fcx.lllocals`.
 /// Adds the created metadata nodes directly to the crate's IR.
 pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
-    if fn_should_be_ignored(bcx.fcx) {
+    if bcx.unreachable.get() || fn_should_be_ignored(bcx.fcx) {
         return;
     }
 
@@ -1074,7 +1074,7 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) {
 /// loop variable in `bcx.fcx.lllocals`.
 /// Adds the created metadata nodes directly to the crate's IR.
 pub fn create_for_loop_var_metadata(bcx: Block, pat: &ast::Pat) {
-    if fn_should_be_ignored(bcx.fcx) {
+    if bcx.unreachable.get() || fn_should_be_ignored(bcx.fcx) {
         return;
     }
 
diff --git a/src/test/debuginfo/unreachable-locals.rs b/src/test/debuginfo/unreachable-locals.rs
new file mode 100644 (file)
index 0000000..c15dcd1
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright 2013-2014 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.
+
+// ignore-android: FIXME(#10381)
+// min-lldb-version: 310
+
+// compile-flags:-g
+
+#![allow(unused_variables)]
+#![omit_gdb_pretty_printer_section]
+
+// No need to actually run the debugger, just make sure that the compiler can
+// handle locals in unreachable code.
+
+fn after_return() {
+    return;
+    let x = "0";
+    let (ref y,z) = (1i32, 2u32);
+    match (20i32, 'c') {
+        (a, ref b) => {}
+    }
+    for a in [111i32].iter() {}
+}
+
+fn after_panic() {
+    panic!();
+    let x = "0";
+    let (ref y,z) = (1i32, 2u32);
+    match (20i32, 'c') {
+        (a, ref b) => {}
+    }
+    for a in [111i32].iter() {}
+}
+
+fn after_diverging_function() {
+    diverge();
+    let x = "0";
+    let (ref y,z) = (1i32, 2u32);
+    match (20i32, 'c') {
+        (a, ref b) => {}
+    }
+    for a in [111i32].iter() {}
+}
+
+fn after_break() {
+    loop {
+        break;
+        let x = "0";
+        let (ref y,z) = (1i32, 2u32);
+        match (20i32, 'c') {
+            (a, ref b) => {}
+        }
+        for a in [111i32].iter() {}
+    }
+}
+
+fn after_continue() {
+    for _ in range(0, 10i32) {
+        break;
+        let x = "0";
+        let (ref y,z) = (1i32, 2u32);
+        match (20i32, 'c') {
+            (a, ref b) => {}
+        }
+        for a in [111i32].iter() {}
+    }
+}
+
+fn main() {
+    after_return();
+    after_panic();
+    after_diverging_function();
+    after_break();
+    after_continue();
+}
+
+fn diverge() -> ! {
+    panic!();
+}