Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: const qualif failed to prevent mutable references with -Zmir-opt-level=3 #67640

Closed
matthiaskrgr opened this issue Dec 26, 2019 · 0 comments · Fixed by #68170
Closed

ICE: const qualif failed to prevent mutable references with -Zmir-opt-level=3 #67640

matthiaskrgr opened this issue Dec 26, 2019 · 0 comments · Fixed by #68170
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 26, 2019

rustc src/test/ui/argument-passing.rs -Zmir-opt-level=3

file:

// run-pass

struct X {
    x: isize
}

fn f1(a: &mut X, b: &mut isize, c: isize) -> isize {
    let r = a.x + *b + c;
    a.x = 0;
    *b = 10;
    return r;
}

fn f2<F>(a: isize, f: F) -> isize where F: FnOnce(isize) { f(1); return a; }

pub fn main() {
    let mut a = X {x: 1};
    let mut b = 2;
    let c = 3;
    assert_eq!(f1(&mut a, &mut b, c), 6);
    assert_eq!(a.x, 0);
    assert_eq!(b, 10);
    assert_eq!(f2(a.x, |_| a.x = 50), 0);
    assert_eq!(a.x, 50);
}
error: internal compiler error: src/librustc_mir/interpret/intern.rs:223: const qualif failed to prevent mutable references

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:891:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1057
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1426
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:195
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:215
  10: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /home/matthias/vcs/github/rust_debug_assertions/src/liballoc/boxed.rs:1029
  11: rustc_driver::report_ice
             at src/librustc_driver/lib.rs:1160
  12: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:476
  13: std::panicking::begin_panic
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/panicking.rs:401
  14: rustc_errors::HandlerInner::bug
             at src/librustc_errors/lib.rs:891
  15: rustc_errors::Handler::bug
             at src/librustc_errors/lib.rs:651
  16: rustc::util::bug::opt_span_bug_fmt::{{closure}}
             at src/librustc/util/bug.rs:36
  17: rustc::ty::context::tls::with_opt::{{closure}}
             at src/librustc/ty/context.rs:1875
  18: rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1827
  19: rustc::ty::context::tls::with_opt
             at src/librustc/ty/context.rs:1875
  20: rustc::util::bug::opt_span_bug_fmt
             at src/librustc/util/bug.rs:32
  21: rustc::util::bug::bug_fmt
             at src/librustc/util/bug.rs:12
  22: <rustc_mir::interpret::intern::InternVisitor<M> as rustc_mir::interpret::visitor::ValueVisitor<M>>::visit_primitive
             at src/librustc_mir/interpret/intern.rs:223
  23: rustc_mir::interpret::visitor::ValueVisitor::walk_value
             at src/librustc_mir/interpret/visitor.rs:271
  24: rustc_mir::interpret::visitor::ValueVisitor::visit_value
             at src/librustc_mir/interpret/visitor.rs:119
  25: rustc_mir::interpret::visitor::ValueVisitor::visit_field
             at src/librustc_mir/interpret/visitor.rs:151
  26: rustc_mir::interpret::visitor::ValueVisitor::walk_aggregate
             at src/librustc_mir/interpret/visitor.rs:200
  27: <rustc_mir::interpret::intern::InternVisitor<M> as rustc_mir::interpret::visitor::ValueVisitor<M>>::visit_aggregate
             at src/librustc_mir/interpret/intern.rs:180
  28: rustc_mir::interpret::visitor::ValueVisitor::walk_value
             at src/librustc_mir/interpret/visitor.rs:291
  29: rustc_mir::interpret::visitor::ValueVisitor::visit_value
             at src/librustc_mir/interpret/visitor.rs:119
  30: rustc_mir::interpret::intern::intern_const_alloc_recursive
             at src/librustc_mir/interpret/intern.rs:289
  31: rustc_mir::transform::const_prop::ConstPropagator::should_const_prop
             at src/librustc_mir/transform/const_prop.rs:662
  32: <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement
             at src/librustc_mir/transform/const_prop.rs:767
  33: rustc::mir::visit::MutVisitor::super_basic_block_data
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:322
  34: rustc::mir::visit::MutVisitor::visit_basic_block_data
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:93
  35: rustc::mir::visit::MutVisitor::super_body
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:275
  36: rustc::mir::visit::MutVisitor::visit_body
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:87
  37: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
             at src/librustc_mir/transform/const_prop.rs:97
  38: rustc_mir::transform::run_passes::{{closure}}
             at src/librustc_mir/transform/mod.rs:171
  39: rustc_mir::transform::run_passes
             at src/librustc_mir/transform/mod.rs:178
  40: rustc_mir::transform::run_optimization_passes
             at src/librustc_mir/transform/mod.rs:273
  41: rustc_mir::transform::optimized_mir
             at src/librustc_mir/transform/mod.rs:343
  42: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
             at src/librustc/ty/query/plumbing.rs:963
  43: rustc::dep_graph::graph::DepGraph::with_task_impl
             at src/librustc/dep_graph/graph.rs:325
  44: rustc::dep_graph::graph::DepGraph::with_task
             at src/librustc/dep_graph/graph.rs:193
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:543
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at src/librustc/ty/query/plumbing.rs:267
  47: rustc::ty::context::tls::enter_context::{{closure}}
             at src/librustc/ty/context.rs:1766
  48: rustc::ty::context::tls::set_tlv
             at src/librustc/ty/context.rs:1699
  49: rustc::ty::context::tls::enter_context
             at src/librustc/ty/context.rs:1766
  50: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at src/librustc/ty/query/plumbing.rs:267
  51: rustc::ty::context::tls::with_related_context::{{closure}}
             at src/librustc/ty/context.rs:1854
  52: rustc::ty::context::tls::with_context::{{closure}}
             at src/librustc/ty/context.rs:1838
  53: rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1827
  54: rustc::ty::context::tls::with_context
             at src/librustc/ty/context.rs:1838
  55: rustc::ty::context::tls::with_related_context
             at src/librustc/ty/context.rs:1851
  56: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at src/librustc/ty/query/plumbing.rs:256
  57: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at src/librustc/ty/query/plumbing.rs:533
  58: rustc::ty::query::plumbing::with_diagnostics
             at src/librustc/ty/query/plumbing.rs:201
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at src/librustc/ty/query/plumbing.rs:532
  60: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at src/librustc/ty/query/plumbing.rs:369
  61: rustc::ty::query::TyCtxtAt::optimized_mir
             at src/librustc/ty/query/plumbing.rs:1048
  62: rustc::ty::query::<impl rustc::ty::context::TyCtxt>::optimized_mir
             at src/librustc/ty/query/plumbing.rs:1040
  63: rustc::ty::<impl rustc::ty::context::TyCtxt>::instance_mir
             at src/librustc/ty/mod.rs:2955
  64: rustc_mir::monomorphize::collector::collect_neighbours
             at src/librustc_mir/monomorphize/collector.rs:1221
  65: rustc_mir::monomorphize::collector::collect_items_rec
             at src/librustc_mir/monomorphize/collector.rs:381
  66: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}::{{closure}}
             at src/librustc_mir/monomorphize/collector.rs:306
  67: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/libcore/iter/traits/iterator.rs:652
  68: core::iter::traits::iterator::Iterator::fold::ok::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/libcore/iter/traits/iterator.rs:1900
  69: core::iter::traits::iterator::Iterator::try_fold
             at /home/matthias/vcs/github/rust_debug_assertions/src/libcore/iter/traits/iterator.rs:1776
  70: core::iter::traits::iterator::Iterator::fold
             at /home/matthias/vcs/github/rust_debug_assertions/src/libcore/iter/traits/iterator.rs:1903
  71: core::iter::traits::iterator::Iterator::for_each
             at /home/matthias/vcs/github/rust_debug_assertions/src/libcore/iter/traits/iterator.rs:655
  72: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
             at src/librustc_mir/monomorphize/collector.rs:304
  73: rustc::util::common::time_ext
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/util/common.rs:54
  74: rustc::util::common::time
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/util/common.rs:46
  75: rustc_mir::monomorphize::collector::collect_crate_mono_items
             at src/librustc_mir/monomorphize/collector.rs:303
  76: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::{{closure}}
             at src/librustc_mir/monomorphize/partitioning.rs:870
  77: rustc::util::common::time_ext
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/util/common.rs:54
  78: rustc::util::common::time
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/util/common.rs:46
  79: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
             at src/librustc_mir/monomorphize/partitioning.rs:869
  80: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_and_partition_mono_items>::compute::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:971
  81: rustc::ty::query::__query_compute::collect_and_partition_mono_items
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:922
  82: rustc::dep_graph::graph::DepGraph::with_task_impl
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/dep_graph/graph.rs:325
  83: rustc::dep_graph::graph::DepGraph::with_eval_always_task
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/dep_graph/graph.rs:372
  84: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:535
  85: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:267
  86: rustc::ty::context::tls::enter_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1766
  87: rustc::ty::context::tls::set_tlv
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1699
  88: rustc::ty::context::tls::enter_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1766
  89: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:267
  90: rustc::ty::context::tls::with_related_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1854
  91: rustc::ty::context::tls::with_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1838
  92: rustc::ty::context::tls::with_context_opt
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1827
  93: rustc::ty::context::tls::with_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1838
  94: rustc::ty::context::tls::with_related_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1851
  95: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:256
  96: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:533
  97: rustc::ty::query::plumbing::with_diagnostics
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:201
  98: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:532
  99: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:369
 100: rustc::ty::query::TyCtxtAt::collect_and_partition_mono_items
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:1048
 101: rustc::ty::query::<impl rustc::ty::context::TyCtxt>::collect_and_partition_mono_items
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:1040
 102: rustc_codegen_ssa::base::codegen_crate
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_codegen_ssa/base.rs:532
 103: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
             at src/librustc_codegen_llvm/lib.rs:263
 104: rustc_interface::passes::start_codegen::{{closure}}
             at src/librustc_interface/passes.rs:985
 105: rustc::util::common::time_ext
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/util/common.rs:54
 106: rustc::util::common::time
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/util/common.rs:46
 107: rustc_interface::passes::start_codegen
             at src/librustc_interface/passes.rs:983
 108: rustc_interface::queries::Queries::ongoing_codegen::{{closure}}::{{closure}}
             at src/librustc_interface/queries.rs:282
 109: rustc_interface::passes::QueryContext::enter::{{closure}}
             at src/librustc_interface/passes.rs:711
 110: rustc::ty::context::tls::enter_global::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1789
 111: rustc::ty::context::tls::enter_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1766
 112: rustc::ty::context::tls::set_tlv
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1699
 113: rustc::ty::context::tls::enter_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1766
 114: rustc::ty::context::tls::enter_global
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1789
 115: rustc_interface::passes::QueryContext::enter
             at src/librustc_interface/passes.rs:711
 116: rustc_interface::queries::Queries::ongoing_codegen::{{closure}}
             at src/librustc_interface/queries.rs:276
 117: rustc_interface::queries::Query<T>::compute
             at src/librustc_interface/queries.rs:34
 118: rustc_interface::queries::Queries::ongoing_codegen
             at src/librustc_interface/queries.rs:274
 119: rustc_driver::run_compiler::{{closure}}::{{closure}}
             at src/librustc_driver/lib.rs:404
 120: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/queries.rs:332
 121: rustc_driver::run_compiler::{{closure}}
             at src/librustc_driver/lib.rs:295
 122: rustc_interface::interface::run_compiler_in_existing_thread_pool
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/interface.rs:184
 123: rustc_interface::interface::run_compiler::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/interface.rs:193
 124: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:154
 125: rustc::ty::context::tls::with_thread_locals::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1755
 126: std::thread::local::LocalKey<T>::try_with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:262
 127: std::thread::local::LocalKey<T>::with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:239
 128: rustc::ty::context::tls::with_thread_locals::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1747
 129: std::thread::local::LocalKey<T>::try_with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:262
 130: std::thread::local::LocalKey<T>::with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:239
 131: rustc::ty::context::tls::with_thread_locals
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1739
 132: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:154
 133: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
 134: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:150
 135: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
 136: syntax::with_globals::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/libsyntax/lib.rs:60
 137: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
 138: syntax::with_globals
             at /home/matthias/vcs/github/rust_debug_assertions/src/libsyntax/lib.rs:60
 139: rustc_interface::util::spawn_thread_pool::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:149
 140: rustc_interface::util::scoped_thread::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:126
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.42.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3

query stack during panic:
#0 [optimized_mir] processing `main`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

rustc @ bbf1372

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 27, 2019
bors added a commit that referenced this issue Jan 18, 2020
Turn off const propagation of ref taking

Fixes #67529
Fixes #67640
Fixes #67641
Fixes #67862

r? @oli-obk
@bors bors closed this as completed in 7f65475 Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants