-
Notifications
You must be signed in to change notification settings - Fork 135
Upgrade toolchain to nightly-2022-09-13 #1737
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 2 commits
9b2657b
e6fcc13
54f237c
0d43ce8
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 |
|---|---|---|
|
|
@@ -313,13 +313,6 @@ impl<'tcx> GotocCtx<'tcx> { | |
| ($f:ident) => {{ codegen_intrinsic_binop!($f) }}; | ||
| } | ||
|
|
||
| // Intrinsics which encode a pointer comparison (e.g., `ptr_guaranteed_eq`). | ||
| // These behave as regular pointer comparison at runtime: | ||
| // https://doc.rust-lang.org/beta/std/primitive.pointer.html#method.guaranteed_eq | ||
| macro_rules! codegen_ptr_guaranteed_cmp { | ||
| ($f:ident) => {{ self.binop(p, fargs, |a, b| a.$f(b).cast_to(Type::c_bool())) }}; | ||
| } | ||
|
|
||
| // Intrinsics which encode a simple binary operation | ||
| macro_rules! codegen_intrinsic_binop { | ||
| ($f:ident) => {{ self.binop(p, fargs, |a, b| a.$f(b)) }}; | ||
|
|
@@ -596,8 +589,7 @@ impl<'tcx> GotocCtx<'tcx> { | |
| "powif32" => unstable_codegen!(codegen_simple_intrinsic!(Powif)), | ||
| "powif64" => unstable_codegen!(codegen_simple_intrinsic!(Powi)), | ||
| "pref_align_of" => codegen_intrinsic_const!(), | ||
| "ptr_guaranteed_eq" => codegen_ptr_guaranteed_cmp!(eq), | ||
| "ptr_guaranteed_ne" => codegen_ptr_guaranteed_cmp!(neq), | ||
| "ptr_guaranteed_cmp" => self.codegen_ptr_guaranteed_cmp(fargs, p), | ||
| "ptr_offset_from" => self.codegen_ptr_offset_from(fargs, p, loc), | ||
| "ptr_offset_from_unsigned" => self.codegen_ptr_offset_from_unsigned(fargs, p, loc), | ||
| "raw_eq" => self.codegen_intrinsic_raw_eq(instance, fargs, p, loc), | ||
|
|
@@ -1012,6 +1004,26 @@ impl<'tcx> GotocCtx<'tcx> { | |
| Stmt::block(vec![src_align_check, dst_align_check, overflow_check, copy_expr], loc) | ||
| } | ||
|
|
||
| // In some contexts (e.g., compilation-time evaluation), | ||
|
Contributor
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. Nice documentation!
Contributor
Author
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. Kudos to @adpaco-aws. :) |
||
| // `ptr_guaranteed_cmp` compares two pointers and returns: | ||
| // * 2 if the result is unknown. | ||
| // * 1 if they are guaranteed to be equal. | ||
| // * 0 if they are guaranteed to be not equal. | ||
| // But at runtime, this intrinsic behaves as a regular pointer comparison. | ||
| // Therefore, we return 1 if the pointers are equal and 0 otherwise. | ||
| // | ||
| // This intrinsic replaces `ptr_guaranteed_eq` and `ptr_guaranteed_ne`: | ||
| // https://doc.rust-lang.org/beta/std/primitive.pointer.html#method.guaranteed_eq | ||
| fn codegen_ptr_guaranteed_cmp(&mut self, mut fargs: Vec<Expr>, p: &Place<'tcx>) -> Stmt { | ||
| let a = fargs.remove(0); | ||
| let b = fargs.remove(0); | ||
| let place_type = self.place_ty(p); | ||
| let res_type = self.codegen_ty(place_type); | ||
| let eq_expr = a.eq(b); | ||
| let cmp_expr = Expr::if_then_else_expr(eq_expr, res_type.one(), res_type.zero()); | ||
| self.codegen_expr_to_place(p, cmp_expr) | ||
| } | ||
|
|
||
| /// Computes the offset from a pointer. | ||
| /// | ||
| /// Note that this function handles code generation for: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,8 @@ use kani_queries::UserInput; | |
| use rustc_hir::def_id::DefId; | ||
| use rustc_middle::mir; | ||
| use rustc_middle::mir::{ | ||
| AssertKind, BasicBlock, Operand, Place, Statement, StatementKind, SwitchTargets, Terminator, | ||
| TerminatorKind, | ||
| AssertKind, BasicBlock, NonDivergingIntrinsic, Operand, Place, Statement, StatementKind, | ||
| SwitchTargets, Terminator, TerminatorKind, | ||
| }; | ||
| use rustc_middle::ty; | ||
| use rustc_middle::ty::layout::LayoutOf; | ||
|
|
@@ -89,8 +89,8 @@ impl<'tcx> GotocCtx<'tcx> { | |
| self.codegen_discriminant_field(place_goto_expr, pt) | ||
| .assign(discr, location) | ||
| } | ||
| TagEncoding::Niche { dataful_variant, niche_variants, niche_start } => { | ||
| if dataful_variant != variant_index { | ||
| TagEncoding::Niche { untagged_variant, niche_variants, niche_start } => { | ||
| if untagged_variant != variant_index { | ||
| let offset = match &layout.fields { | ||
| FieldsShape::Arbitrary { offsets, .. } => offsets[0], | ||
| _ => unreachable!("niche encoding must have arbitrary fields"), | ||
|
|
@@ -122,11 +122,9 @@ impl<'tcx> GotocCtx<'tcx> { | |
| } | ||
| StatementKind::StorageLive(_) => Stmt::skip(location), // TODO: fix me | ||
| StatementKind::StorageDead(_) => Stmt::skip(location), // TODO: fix me | ||
| StatementKind::CopyNonOverlapping(box mir::CopyNonOverlapping { | ||
| ref src, | ||
| ref dst, | ||
| ref count, | ||
| }) => { | ||
| mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( | ||
|
||
| mir::CopyNonOverlapping { ref src, ref dst, ref count }, | ||
| )) => { | ||
| // Pack the operands and their types, then call `codegen_copy` | ||
| let fargs = vec![ | ||
| self.codegen_operand(src), | ||
|
|
@@ -137,6 +135,15 @@ impl<'tcx> GotocCtx<'tcx> { | |
| &[self.operand_ty(src), self.operand_ty(dst), self.operand_ty(count)]; | ||
| self.codegen_copy("copy_nonoverlapping", true, fargs, farg_types, None, location) | ||
| } | ||
| StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => { | ||
| let cond = self.codegen_operand(op).cast_to(Type::bool()); | ||
| self.codegen_assert_assume( | ||
| cond, | ||
| PropertyClass::Assume, | ||
| "assumption failed", | ||
| location, | ||
| ) | ||
| } | ||
| StatementKind::FakeRead(_) | ||
| | StatementKind::Retag(_, _) | ||
| | StatementKind::AscribeUserType(_, _) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as the
ternarymethod?kani/cprover_bindings/src/goto_program/expr.rs
Line 862 in 38ba4b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Let me replace that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mea culpa, I wasn't able to find it.