Skip to content

Commit 7dad847

Browse files
authored
Remove further uses of Location::none (rust-lang#3253)
We now only have 12 uses of `Location::none` left, all of which have no reasonable location to use. Resolves: rust-lang#136
1 parent d588c01 commit 7dad847

File tree

16 files changed

+204
-159
lines changed

16 files changed

+204
-159
lines changed

cprover_bindings/src/goto_program/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub enum ExprValue {
140140
/// `({ op1; op2; ...})`
141141
StatementExpression {
142142
statements: Vec<Stmt>,
143+
location: Location,
143144
},
144145
/// A raw string constant. Note that you normally actually want a pointer to the first element.
145146
/// `"s"`
@@ -739,10 +740,10 @@ impl Expr {
739740
/// <https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html>
740741
/// e.g. `({ int y = foo (); int z; if (y > 0) z = y; else z = - y; z; })`
741742
/// `({ op1; op2; ...})`
742-
pub fn statement_expression(ops: Vec<Stmt>, typ: Type) -> Self {
743+
pub fn statement_expression(ops: Vec<Stmt>, typ: Type, loc: Location) -> Self {
743744
assert!(!ops.is_empty());
744745
assert_eq!(ops.last().unwrap().get_expression().unwrap().typ, typ);
745-
expr!(StatementExpression { statements: ops }, typ)
746+
expr!(StatementExpression { statements: ops, location: loc }, typ).with_location(loc)
746747
}
747748

748749
/// Internal helper function for Struct initalizer

cprover_bindings/src/irep/to_irep.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ impl ToIrep for ExprValue {
299299
named_sub: linear_map![],
300300
},
301301
ExprValue::SelfOp { op, e } => side_effect_irep(op.to_irep_id(), vec![e.to_irep(mm)]),
302-
ExprValue::StatementExpression { statements: ops } => side_effect_irep(
302+
ExprValue::StatementExpression { statements: ops, location: loc } => side_effect_irep(
303303
IrepId::StatementExpression,
304-
vec![Stmt::block(ops.to_vec(), Location::none()).to_irep(mm)],
304+
vec![Stmt::block(ops.to_vec(), *loc).to_irep(mm)],
305305
),
306306
ExprValue::StringConstant { s } => Irep {
307307
id: IrepId::StringConstant,

kani-compiler/src/codegen_cprover_gotoc/codegen/assert.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'tcx> GotocCtx<'tcx> {
252252
t.nondet().as_stmt(loc),
253253
];
254254

255-
Expr::statement_expression(body, t).with_location(loc)
255+
Expr::statement_expression(body, t, loc)
256256
}
257257

258258
/// Kani does not currently support all MIR constructs.
@@ -356,7 +356,7 @@ impl<'tcx> GotocCtx<'tcx> {
356356
// Encode __CPROVER_r_ok(ptr, size).
357357
// First, generate a CBMC expression representing the pointer.
358358
let ptr = {
359-
let ptr_projection = self.codegen_place_stable(&ptr_place).unwrap();
359+
let ptr_projection = self.codegen_place_stable(&ptr_place, *loc).unwrap();
360360
let place_ty = self.place_ty_stable(place);
361361
if self.use_thin_pointer_stable(place_ty) {
362362
ptr_projection.goto_expr().clone()

kani-compiler/src/codegen_cprover_gotoc/codegen/contract.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::codegen_cprover_gotoc::GotocCtx;
44
use crate::kani_middle::attributes::KaniAttributes;
55
use cbmc::goto_program::FunctionContract;
6-
use cbmc::goto_program::Lambda;
6+
use cbmc::goto_program::{Lambda, Location};
77
use kani_metadata::AssignsContract;
88
use rustc_hir::def_id::DefId as InternalDefId;
99
use rustc_smir::rustc_internal;
@@ -105,7 +105,11 @@ impl<'tcx> GotocCtx<'tcx> {
105105

106106
/// Convert the Kani level contract into a CBMC level contract by creating a
107107
/// CBMC lambda.
108-
fn codegen_modifies_contract(&mut self, modified_places: Vec<Local>) -> FunctionContract {
108+
fn codegen_modifies_contract(
109+
&mut self,
110+
modified_places: Vec<Local>,
111+
loc: Location,
112+
) -> FunctionContract {
109113
let goto_annotated_fn_name = self.current_fn().name();
110114
let goto_annotated_fn_typ = self
111115
.symbol_table
@@ -120,7 +124,7 @@ impl<'tcx> GotocCtx<'tcx> {
120124
Lambda::as_contract_for(
121125
&goto_annotated_fn_typ,
122126
None,
123-
self.codegen_place_stable(&local.into()).unwrap().goto_expr.dereference(),
127+
self.codegen_place_stable(&local.into(), loc).unwrap().goto_expr.dereference(),
124128
)
125129
})
126130
.collect();
@@ -138,7 +142,8 @@ impl<'tcx> GotocCtx<'tcx> {
138142
assert!(self.current_fn.is_none());
139143
let body = instance.body().unwrap();
140144
self.set_current_fn(instance, &body);
141-
let goto_contract = self.codegen_modifies_contract(modified_places);
145+
let goto_contract =
146+
self.codegen_modifies_contract(modified_places, self.codegen_span_stable(body.span));
142147
let name = self.current_fn().name();
143148

144149
self.symbol_table.attach_contract(name, goto_contract);

kani-compiler/src/codegen_cprover_gotoc/codegen/foreign_function.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl<'tcx> GotocCtx<'tcx> {
5050
pub fn codegen_foreign_fn(&mut self, instance: Instance) -> &Symbol {
5151
debug!(?instance, "codegen_foreign_function");
5252
let fn_name = self.symbol_name_stable(instance).intern();
53+
let loc = self.codegen_span_stable(instance.def.span());
5354
if self.symbol_table.contains(fn_name) {
5455
// Symbol has been added (either a built-in CBMC function or a Rust allocation function).
5556
self.symbol_table.lookup(fn_name).unwrap()
@@ -63,8 +64,7 @@ impl<'tcx> GotocCtx<'tcx> {
6364
// https://github.com/model-checking/kani/issues/2426
6465
self.ensure(fn_name, |gcx, _| {
6566
let typ = gcx.codegen_ffi_type(instance);
66-
Symbol::function(fn_name, typ, None, instance.name(), Location::none())
67-
.with_is_extern(true)
67+
Symbol::function(fn_name, typ, None, instance.name(), loc).with_is_extern(true)
6868
})
6969
} else {
7070
let shim_name = format!("{fn_name}_ffi_shim");
@@ -77,7 +77,7 @@ impl<'tcx> GotocCtx<'tcx> {
7777
typ,
7878
Some(gcx.codegen_ffi_shim(shim_name.as_str().into(), instance)),
7979
instance.name(),
80-
Location::none(),
80+
loc,
8181
)
8282
})
8383
}
@@ -109,7 +109,7 @@ impl<'tcx> GotocCtx<'tcx> {
109109
} else {
110110
let ret_expr = unwrap_or_return_codegen_unimplemented_stmt!(
111111
self,
112-
self.codegen_place_stable(ret_place)
112+
self.codegen_place_stable(ret_place, loc)
113113
)
114114
.goto_expr;
115115
let ret_type = ret_expr.typ().clone();

kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ impl<'tcx> GotocCtx<'tcx> {
3333
place: &Place,
3434
mut fargs: Vec<Expr>,
3535
f: F,
36+
loc: Location,
3637
) -> Stmt {
3738
let arg1 = fargs.remove(0);
3839
let arg2 = fargs.remove(0);
3940
let expr = f(arg1, arg2);
40-
self.codegen_expr_to_place_stable(place, expr, Location::none())
41+
self.codegen_expr_to_place_stable(place, expr, loc)
4142
}
4243

4344
/// Given a call to an compiler intrinsic, generate the call and the `goto` terminator
@@ -178,7 +179,7 @@ impl<'tcx> GotocCtx<'tcx> {
178179

179180
// Intrinsics which encode a simple binary operation
180181
macro_rules! codegen_intrinsic_binop {
181-
($f:ident) => {{ self.binop(place, fargs, |a, b| a.$f(b)) }};
182+
($f:ident) => {{ self.binop(place, fargs, |a, b| a.$f(b), loc) }};
182183
}
183184

184185
// Intrinsics which encode a simple binary operation which need a machine model
@@ -208,7 +209,7 @@ impl<'tcx> GotocCtx<'tcx> {
208209
let alloc = stable_instance.try_const_eval(place_ty).unwrap();
209210
// We assume that the intrinsic has type checked at this point, so
210211
// we can use the place type as the expression type.
211-
let expr = self.codegen_allocation(&alloc, place_ty, Some(span));
212+
let expr = self.codegen_allocation(&alloc, place_ty, loc);
212213
self.codegen_expr_to_place_stable(&place, expr, loc)
213214
}};
214215
}
@@ -727,7 +728,7 @@ impl<'tcx> GotocCtx<'tcx> {
727728
let res = self.codegen_binop_with_overflow(binop, left, right, result_type.clone(), loc);
728729
self.codegen_expr_to_place_stable(
729730
place,
730-
Expr::statement_expression(vec![res.as_stmt(loc)], result_type),
731+
Expr::statement_expression(vec![res.as_stmt(loc)], result_type, loc),
731732
loc,
732733
)
733734
}
@@ -1042,9 +1043,11 @@ impl<'tcx> GotocCtx<'tcx> {
10421043
let is_lhs_ok = lhs_var.clone().is_nonnull();
10431044
let is_rhs_ok = rhs_var.clone().is_nonnull();
10441045
let should_skip_pointer_checks = is_len_zero.and(is_lhs_ok).and(is_rhs_ok);
1045-
let place_expr =
1046-
unwrap_or_return_codegen_unimplemented_stmt!(self, self.codegen_place_stable(place))
1047-
.goto_expr;
1046+
let place_expr = unwrap_or_return_codegen_unimplemented_stmt!(
1047+
self,
1048+
self.codegen_place_stable(place, loc)
1049+
)
1050+
.goto_expr;
10481051
let res = should_skip_pointer_checks.ternary(
10491052
Expr::int_constant(0, place_expr.typ().clone()), // zero bytes are always equal (as long as pointers are nonnull and aligned)
10501053
BuiltinFn::Memcmp
@@ -1634,7 +1637,7 @@ impl<'tcx> GotocCtx<'tcx> {
16341637
loc,
16351638
)
16361639
} else {
1637-
self.binop(p, fargs, op_fun)
1640+
self.binop(p, fargs, op_fun, loc)
16381641
}
16391642
}
16401643

0 commit comments

Comments
 (0)