-
Notifications
You must be signed in to change notification settings - Fork 121
Update toolchain to nightly-2022-07-19 #1399
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
Changes from 1 commit
e0745a4
c29ac66
f490b22
2ec7e76
c392308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ use rustc_middle::ty::{self, Const, ConstKind, FloatTy, Instance, IntTy, Ty, Uin | |
use rustc_span::def_id::DefId; | ||
use rustc_span::Span; | ||
use rustc_target::abi::{FieldsShape, Size, TagEncoding, Variants}; | ||
use tracing::debug; | ||
use tracing::{debug, trace}; | ||
|
||
enum AllocData<'a> { | ||
Bytes(&'a [u8]), | ||
|
@@ -23,6 +23,7 @@ enum AllocData<'a> { | |
|
||
impl<'tcx> GotocCtx<'tcx> { | ||
pub fn codegen_operand(&mut self, o: &Operand<'tcx>) -> Expr { | ||
trace!(operand=?o, "codegen_operand"); | ||
match o { | ||
Operand::Copy(d) | Operand::Move(d) => | ||
// TODO: move shouldn't be the same as copy | ||
|
@@ -44,6 +45,7 @@ impl<'tcx> GotocCtx<'tcx> { | |
} | ||
|
||
fn codegen_constant(&mut self, c: &Constant<'tcx>) -> Expr { | ||
trace!(constant=?c, "codegen_constant"); | ||
let const_ = match self.monomorphize(c.literal) { | ||
ConstantKind::Ty(ct) => ct, | ||
ConstantKind::Val(val, ty) => return self.codegen_const_value(val, ty, Some(&c.span)), | ||
|
@@ -145,6 +147,7 @@ impl<'tcx> GotocCtx<'tcx> { | |
lit_ty: Ty<'tcx>, | ||
span: Option<&Span>, | ||
) -> Expr { | ||
trace!(val=?v, ?lit_ty, "codegen_const_value"); | ||
match v { | ||
ConstValue::Scalar(s) => self.codegen_scalar(s, lit_ty, span), | ||
ConstValue::Slice { data, start, end } => { | ||
|
@@ -160,11 +163,15 @@ impl<'tcx> GotocCtx<'tcx> { | |
.cast_to(self.codegen_ty(lit_ty).to_pointer()) | ||
.dereference() | ||
} | ||
ConstValue::ZeroSized => match lit_ty.kind() { | ||
ty::FnDef(d, substs) => self.codegen_fndef(*d, substs, span), | ||
_ => unimplemented!(), | ||
}, | ||
} | ||
} | ||
|
||
fn codegen_scalar(&mut self, s: Scalar, ty: Ty<'tcx>, span: Option<&Span>) -> Expr { | ||
debug! {"codegen_scalar\n{:?}\n{:?}\n{:?}\n{:?}",s, ty, span, &ty.kind()}; | ||
debug!(scalar=?s, ?ty, kind=?ty.kind(), ?span, "codegen_scalar"); | ||
match (s, &ty.kind()) { | ||
(Scalar::Int(_), ty::Int(it)) => match it { | ||
IntTy::I8 => Expr::int_constant(s.to_i8().unwrap(), Type::signed_int(8)), | ||
|
@@ -199,9 +206,8 @@ impl<'tcx> GotocCtx<'tcx> { | |
FloatTy::F64 => Expr::double_constant_from_bitpattern(s.to_u64().unwrap()), | ||
} | ||
} | ||
(Scalar::Int(int), ty::FnDef(d, substs)) => { | ||
assert_eq!(int.size(), Size::ZERO); | ||
self.codegen_fndef(*d, substs, span) | ||
(Scalar::Int(..), ty::FnDef(..)) => { | ||
unreachable!("ZST is no longer represented as a scalar") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment that points to the rustc PR? |
||
} | ||
(Scalar::Int(_), ty::RawPtr(tm)) => { | ||
Expr::pointer_constant(s.to_u64().unwrap(), self.codegen_ty(tm.ty).to_pointer()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,6 +419,7 @@ impl<'tcx> GotocCtx<'tcx> { | |
|
||
pub fn codegen_rvalue(&mut self, rv: &Rvalue<'tcx>, loc: Location) -> Expr { | ||
let res_ty = self.rvalue_ty(rv); | ||
debug!(?rv, "codegen_rvalue"); | ||
adpaco-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
match rv { | ||
Rvalue::Use(p) => self.codegen_operand(p), | ||
Rvalue::Repeat(op, sz) => self.codegen_rvalue_repeat(op, sz, res_ty), | ||
|
@@ -493,6 +494,9 @@ impl<'tcx> GotocCtx<'tcx> { | |
"https://github.com/model-checking/kani/issues/541", | ||
) | ||
} | ||
Rvalue::CopyForDeref(place) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be helpful to refer to the comment in rustc that mentions that at the codegen level, this is just a read: https://github.com/rust-lang/rust/blob/1673f1450eeaf4a5452e086db0fe2ae274a0144f/compiler/rustc_middle/src/mir/syntax.rs#L1055 |
||
unwrap_or_return_codegen_unimplemented!(self, self.codegen_place(place)).goto_expr | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// | ||
// Modifications Copyright Kani Contributors | ||
// See GitHub history for details. | ||
|
||
/// Adapted from: | ||
/// https://github.com/rust-lang/rust/blob/29c5a028b0c92aa5da6a8eb6d6585a389fcf1035/src/test/mir-opt/derefer_test.rs | ||
celinval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[kani::proof] | ||
fn check_deref_copy() { | ||
let mut a = (42, 43); | ||
let mut b = (99, &mut a); | ||
let x = &mut (*b.1).0; | ||
let y = &mut (*b.1).1; | ||
assert_eq!(*x, 42); | ||
assert_eq!(*y, 43); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// | ||
// Modifications Copyright Kani Contributors | ||
// See GitHub history for details. | ||
|
||
//! Tests that check handling of opaque casts. Tests were adapted from the rustc repository. | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
#[derive(Copy, Clone)] | ||
struct Foo((u32, u32)); | ||
|
||
/// Adapted from: | ||
/// <https://github.com/rust-lang/rust/blob/29c5a028b0c92aa5da6a8eb6d6585a389fcf1035/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-upvar.rs> | ||
#[kani::proof] | ||
fn check_unconstrained_upvar() { | ||
type T = impl Copy; | ||
let foo: T = Foo((1u32, 2u32)); | ||
let x = move || { | ||
let Foo((a, b)) = foo; | ||
assert_eq!(a, 1u32); | ||
assert_eq!(b, 2u32); | ||
}; | ||
} | ||
|
||
/// Adapted from: | ||
/// <https://github.com/rust-lang/rust/blob/29c5a028b0c92aa5da6a8eb6d6585a389fcf1035/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-struct.rs> | ||
#[kani::proof] | ||
fn check_unconstrained_struct() { | ||
type U = impl Copy; | ||
let foo: U = Foo((1u32, 2u32)); | ||
let Foo((a, b)) = foo; | ||
assert_eq!(a, 1u32); | ||
assert_eq!(b, 2u32); | ||
} | ||
|
||
/// Adapted from: | ||
/// https://github.com/rust-lang/rust/issues/96572#issuecomment-1125117692 | ||
celinval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[kani::proof] | ||
fn check_unpack_option_tuple() { | ||
type T = impl Copy; | ||
let foo: T = Some((1u32, 2u32)); | ||
match foo { | ||
None => (), | ||
Some((a, b)) => { | ||
assert_eq!(a, 1u32); | ||
assert_eq!(b, 2u32) | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.