diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 0f19d48da7c..ebdc0bedf41 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -6061,12 +6061,23 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) -> ret trans_check_expr(cx, a, "Predicate"); } case (ast::expr_check(ast::unchecked, ?a)) { - if (cx.fcx.lcx.ccx.sess.get_opts().check_claims) { - ret trans_check_expr(cx, a, "Claim"); - } - else { - ret rslt(cx, C_nil()); - } + /* Claims are turned on and off by a global variable + that the RTS sets. This case generates code to + check the value of that variable, doing nothing + if it's set to false and acting like a check + otherwise. */ + auto c = get_extern_const(cx.fcx.lcx.ccx.externs, + cx.fcx.lcx.ccx.llmod, + "check_claims", T_bool()); + auto cond = cx.build.Load(c); + + auto then_cx = new_scope_block_ctxt(cx, "claim_then"); + auto check_res = trans_check_expr(then_cx, a, "Claim"); + auto else_cx = new_scope_block_ctxt(cx, "else"); + auto els = rslt(else_cx, C_nil()); + + cx.build.CondBr(cond, then_cx.llbb, else_cx.llbb); + ret rslt(join_branches(cx, [check_res, els]), C_nil()); } case (ast::expr_break) { ret trans_break(e.span, cx); } case (ast::expr_cont) { ret trans_cont(e.span, cx); } diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp index 02ab54fd2e1..bd2a5ad1b95 100644 --- a/src/rt/rust.cpp +++ b/src/rt/rust.cpp @@ -91,10 +91,16 @@ int get_num_threads() * initialize the kernel, create the root domain and run it. */ +int check_claims = 0; + +void enable_claims(void* ck) { check_claims = (ck != 0); } + extern "C" CDECL int rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) { update_log_settings(crate_map, getenv("RUST_LOG")); + enable_claims(getenv("CHECK_CLAIMS")); + rust_srv *srv = new rust_srv(); rust_kernel *kernel = new rust_kernel(srv); kernel->start(); diff --git a/src/rt/rust.h b/src/rt/rust.h index 1ca5dddd5e6..61a8e8d78e4 100644 --- a/src/rt/rust.h +++ b/src/rt/rust.h @@ -20,6 +20,10 @@ #define FASTCALL #endif +/* Controls whether claims are turned into checks */ +/* Variable name must be kept consistent with trans.rs */ +extern "C" int check_claims; + /* * Local Variables: * fill-column: 78; diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index f3212bbeb00..b3b0e9a6121 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -1,4 +1,5 @@ align_of +check_claims debug_box debug_fn debug_obj diff --git a/src/test/run-fail/fn-constraint-claim.rs b/src/test/run-fail/fn-constraint-claim.rs index d70bef210f1..2608f15aab0 100644 --- a/src/test/run-fail/fn-constraint-claim.rs +++ b/src/test/run-fail/fn-constraint-claim.rs @@ -1,4 +1,5 @@ // xfail-stage0 +// xfail-stage1 // error-pattern:quux use std; import std::str::*; diff --git a/src/test/run-pass/claim-nonterm.rs b/src/test/run-pass/claim-nonterm.rs index d86154e9ea8..67257a90c29 100644 --- a/src/test/run-pass/claim-nonterm.rs +++ b/src/test/run-pass/claim-nonterm.rs @@ -1,4 +1,5 @@ // xfail-stage0 +// xfail-stage1 // tests that the pred in a claim isn't actually eval'd use std; import std::str::*;