Skip to content

Commit

Permalink
Move fixes to <size|align>_of_val to a new PR
Browse files Browse the repository at this point in the history
Revert changes to intrinsics and remove tests for now
  • Loading branch information
celinval committed Nov 18, 2024
1 parent f5c2135 commit a10a746
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 229 deletions.
16 changes: 13 additions & 3 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ impl GotocCtx<'_> {
}};
}

macro_rules! codegen_size_align {
($which: ident) => {{
let args = instance_args(&instance);
// The type `T` that we'll compute the size or alignment.
let target_ty = args.0[0].expect_ty();
let arg = fargs.remove(0);
let size_align = self.size_and_align_of_dst(*target_ty, arg);
self.codegen_expr_to_place_stable(place, size_align.$which, loc)
}};
}

// Most atomic intrinsics do:
// 1. Perform an operation on a primary argument (e.g., addition)
// 2. Return the previous value of the primary argument
Expand Down Expand Up @@ -411,6 +422,7 @@ impl GotocCtx<'_> {
Intrinsic::MaxNumF32 => codegen_simple_intrinsic!(Fmaxf),
Intrinsic::MaxNumF64 => codegen_simple_intrinsic!(Fmax),
Intrinsic::MinAlignOf => codegen_intrinsic_const!(),
Intrinsic::MinAlignOfVal => codegen_size_align!(align),
Intrinsic::MinNumF32 => codegen_simple_intrinsic!(Fminf),
Intrinsic::MinNumF64 => codegen_simple_intrinsic!(Fmin),
Intrinsic::MulWithOverflow => {
Expand Down Expand Up @@ -504,6 +516,7 @@ impl GotocCtx<'_> {
loc,
),
Intrinsic::SimdXor => codegen_intrinsic_binop!(bitxor),
Intrinsic::SizeOfVal => codegen_size_align!(size),
Intrinsic::SqrtF32 => codegen_simple_intrinsic!(Sqrtf),
Intrinsic::SqrtF64 => codegen_simple_intrinsic!(Sqrt),
Intrinsic::SubWithOverflow => self.codegen_op_with_overflow(
Expand Down Expand Up @@ -546,9 +559,6 @@ impl GotocCtx<'_> {
assert!(self.place_ty_stable(place).kind().is_unit());
self.codegen_write_bytes(fargs, farg_types, loc)
}
Intrinsic::SizeOfVal | Intrinsic::MinAlignOfVal => {
unreachable!("Intrinsic `{}` is handled before codegen", intrinsic_str)
}
// Unimplemented
Intrinsic::Unimplemented { name, issue_link } => {
self.codegen_unimplemented_stmt(&name, loc, &issue_link)
Expand Down
4 changes: 0 additions & 4 deletions kani-compiler/src/kani_middle/kani_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ pub enum KaniIntrinsic {
pub enum KaniModel {
#[strum(serialize = "AlignOfDynObjectModel")]
AlignOfDynObject,
#[strum(serialize = "AlignOfValRawModel")]
AlignOfVal,
#[strum(serialize = "AnyModel")]
Any,
#[strum(serialize = "CopyInitStateModel")]
Expand Down Expand Up @@ -97,8 +95,6 @@ pub enum KaniModel {
SizeOfDynObject,
#[strum(serialize = "SizeOfSliceObjectModel")]
SizeOfSliceObject,
#[strum(serialize = "SizeOfValRawModel")]
SizeOfVal,
#[strum(serialize = "StoreArgumentModel")]
StoreArgument,
#[strum(serialize = "WriteAnySliceModel")]
Expand Down
3 changes: 0 additions & 3 deletions kani-compiler/src/kani_middle/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use stable_mir::mir::mono::{Instance, MonoItem};
use std::collections::HashMap;
use std::fmt::Debug;

use crate::kani_middle::transform::rustc_intrinsics::RustcIntrinsicsPass;
pub use internal_mir::RustcInternalMir;

pub(crate) mod body;
Expand All @@ -44,7 +43,6 @@ mod dump_mir_pass;
mod internal_mir;
mod kani_intrinsics;
mod loop_contracts;
mod rustc_intrinsics;
mod stubs;

/// Object used to retrieve a transformed instance body.
Expand Down Expand Up @@ -90,7 +88,6 @@ impl BodyTransformation {
});
transformer.add_pass(queries, IntrinsicGeneratorPass::new(check_type, &queries));
transformer.add_pass(queries, LoopContractPass::new(tcx, queries, &unit));
transformer.add_pass(queries, RustcIntrinsicsPass::new(&queries));
transformer
}

Expand Down
112 changes: 0 additions & 112 deletions kani-compiler/src/kani_middle/transform/rustc_intrinsics.rs

This file was deleted.

34 changes: 0 additions & 34 deletions library/kani_core/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,6 @@
#[allow(clippy::crate_in_macro_def)]
macro_rules! generate_models {
() => {
/// Model rustc intrinsics. These definitions are not visible to the crate user.
/// They are used by Kani's compiler.
#[allow(dead_code)]
mod rustc_intrinsics {
use crate::kani;
use core::ptr::Pointee;
#[kanitool::fn_marker = "SizeOfValRawModel"]
pub fn size_of_val_raw<T: ?Sized>(ptr: *const T) -> usize {
if let Some(size) = kani::mem::checked_size_of_raw(ptr) {
size
} else if core::mem::size_of::<<T as Pointee>::Metadata>() == 0 {
kani::panic("cannot compute `size_of_val` for extern types")
} else {
kani::safety_check(false, "failed to compute `size_of_val`");
// Unreachable without panic.
kani::kani_intrinsic()
}
}

#[kanitool::fn_marker = "AlignOfValRawModel"]
pub fn align_of_val_raw<T: ?Sized>(ptr: *const T) -> usize {
if let Some(size) = kani::mem::checked_align_of_raw(ptr) {
size
} else if core::mem::size_of::<<T as Pointee>::Metadata>() == 0 {
kani::panic("cannot compute `align_of_val` for extern types")
} else {
// Note that today we trigger a safety check for foreign types.
kani::safety_check(false, "failed to compute `align_of_val`");
// Unreachable without panic.
kani::kani_intrinsic()
}
}
}

#[allow(dead_code)]
mod mem_models {
use core::ptr::{self, DynMetadata, Pointee};
Expand Down
20 changes: 0 additions & 20 deletions tests/expected/intrinsics/size_of_dst.expected

This file was deleted.

53 changes: 0 additions & 53 deletions tests/expected/intrinsics/size_of_dst.rs

This file was deleted.

0 comments on commit a10a746

Please sign in to comment.