Skip to content
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

Upgrade the toolchain to nightly-2023-04-16 #2406

Merged
merged 13 commits into from
May 16, 2023
Merged
Prev Previous commit
Merge remote-tracking branch 'origin/main' into issue-2383-toolchain
Conflicts:
    kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs
    kani-compiler/src/codegen_cprover_gotoc/context/goto_ctx.rs

Required change:
    kani-compiler/src/kani_middle/attributes.rs
  • Loading branch information
celinval committed May 16, 2023
commit 67c7f3c89687ad0440298331e46bfee750ef0c06
30 changes: 7 additions & 23 deletions kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,8 @@ impl GotocCodegenBackend {
GotocCodegenBackend { queries }
}

impl CodegenBackend for GotocCodegenBackend {
fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader)
}

fn provide(&self, providers: &mut Providers) {
provide::provide(providers, &self.queries.lock().unwrap());
}

fn provide_extern(&self, providers: &mut ty::query::ExternProviders) {
provide::provide_extern(providers);
}

fn print_version(&self) {
println!("Kani-goto version: {}", env!("CARGO_PKG_VERSION"));
}

fn locale_resource(&self) -> &'static str {
// We don't currently support multiple languages.
DEFAULT_LOCALE_RESOURCE
}

fn codegen_crate(
/// Generate code that is reachable from the given starting points.
fn codegen_items<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
starting_items: &[MonoItem<'tcx>],
Expand Down Expand Up @@ -222,6 +201,11 @@ impl CodegenBackend for GotocCodegenBackend {
println!("Kani-goto version: {}", env!("CARGO_PKG_VERSION"));
}

fn locale_resource(&self) -> &'static str {
// We don't currently support multiple languages.
DEFAULT_LOCALE_RESOURCE
}

fn codegen_crate(
&self,
tcx: TyCtxt,
Expand Down
114 changes: 0 additions & 114 deletions kani-compiler/src/codegen_cprover_gotoc/context/goto_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use rustc_middle::ty::layout::{
TyAndLayout,
};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::Session;
use rustc_span::source_map::{respan, Span};
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{HasDataLayout, TargetDataLayout};
Expand Down Expand Up @@ -391,116 +390,3 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for GotocCtx<'tcx> {
}
}
}

/// Builds a machine model which is required by CBMC
fn machine_model_from_session(sess: &Session) -> MachineModel {
// The model assumes a `x86_64-unknown-linux-gnu`, `x86_64-apple-darwin`
// or `aarch64-apple-darwin` platform. We check the target platform in function
// `check_target` from src/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs
// and error if it is not any of the ones we expect.
let architecture = &sess.target.arch;
let pointer_width = sess.target.pointer_width.into();

// The model assumes the following values for session options:
// * `min_global_align`: 1
// * `endian`: `Endian::Little`
//
// We check these options in function `check_options` from
// src/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs
// and error if their values are not the ones we expect.
let alignment = sess.target.options.min_global_align.unwrap_or(1);
let is_big_endian = match sess.target.options.endian {
Endian::Little => false,
Endian::Big => true,
};

// The values below cannot be obtained from the session so they are
// hardcoded using standard ones for the supported platforms
// see /tools/sizeofs/main.cpp.
// For reference, the definition in CBMC:
//https://github.com/diffblue/cbmc/blob/develop/src/util/config.cpp
match architecture.as_ref() {
"x86_64" => {
let bool_width = 8;
let char_is_unsigned = false;
let char_width = 8;
let double_width = 64;
let float_width = 32;
let int_width = 32;
let long_double_width = 128;
let long_int_width = 64;
let long_long_int_width = 64;
let short_int_width = 16;
let single_width = 32;
let wchar_t_is_unsigned = false;
let wchar_t_width = 32;

MachineModel {
architecture: architecture.to_string(),
alignment,
bool_width,
char_is_unsigned,
char_width,
double_width,
float_width,
int_width,
is_big_endian,
long_double_width,
long_int_width,
long_long_int_width,
memory_operand_size: int_width / 8,
null_is_zero: true,
pointer_width,
rounding_mode: RoundingMode::ToNearest,
short_int_width,
single_width,
wchar_t_is_unsigned,
wchar_t_width,
word_size: int_width,
}
}
"aarch64" => {
let bool_width = 8;
let char_is_unsigned = true;
let char_width = 8;
let double_width = 64;
let float_width = 32;
let int_width = 32;
let long_double_width = 64;
let long_int_width = 64;
let long_long_int_width = 64;
let short_int_width = 16;
let single_width = 32;
let wchar_t_is_unsigned = false;
let wchar_t_width = 32;

MachineModel {
// CBMC calls it arm64, not aarch64
architecture: "arm64".to_string(),
alignment,
bool_width,
char_is_unsigned,
char_width,
double_width,
float_width,
int_width,
is_big_endian,
long_double_width,
long_int_width,
long_long_int_width,
memory_operand_size: int_width / 8,
null_is_zero: true,
pointer_width,
rounding_mode: RoundingMode::ToNearest,
short_int_width,
single_width,
wchar_t_is_unsigned,
wchar_t_width,
word_size: int_width,
}
}
_ => {
panic!("Unsupported architecture: {architecture}");
}
}
}
2 changes: 1 addition & 1 deletion kani-compiler/src/kani_middle/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn is_test_harness_description(tcx: TyCtxt, def_id: DefId) -> bool {
/// Extract the test harness name from the `#[rustc_test_maker]`
pub fn test_harness_name(tcx: TyCtxt, def_id: DefId) -> String {
let attrs = tcx.get_attrs_unchecked(def_id);
let marker = tcx.sess.find_by_name(attrs, rustc_span::symbol::sym::rustc_test_marker).unwrap();
let marker = attr::find_by_name(attrs, rustc_span::symbol::sym::rustc_test_marker).unwrap();
parse_str_value(&marker).unwrap()
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.