Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,9 @@ impl<'tcx> GotocCtx<'tcx> {
macro_rules! codegen_size_align {
($which: ident) => {{
let tp_ty = instance.substs.type_at(0);
if tp_ty.is_generator() {
let e = self.codegen_unimplemented_expr(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this previously missed because sitting inside a macro made it hard to find references? Just curious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the macro had no effect on this as far as I can tell.

"size or alignment of a generator type",
cbmc_ret_ty,
loc,
"https://github.com/model-checking/kani/issues/1395",
);
self.codegen_expr_to_place(p, e)
} else {
let arg = fargs.remove(0);
let size_align = self.size_and_align_of_dst(tp_ty, arg);
self.codegen_expr_to_place(p, size_align.$which)
}
let arg = fargs.remove(0);
let size_align = self.size_and_align_of_dst(tp_ty, arg);
self.codegen_expr_to_place(p, size_align.$which)
}};
}

Expand Down
2 changes: 1 addition & 1 deletion kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ impl<'tcx> GotocCtx<'tcx> {
name: field_name,
typ: ctx.codegen_ty(field_ty),
});
offset += field_size;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core of the fix right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was the bug.

offset = field_offset + field_size;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment here? You really only care about the last field, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of comment do you mean? We also use the offset earlier to figure out how much padding to insert before a field.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. That's fine, thanks

}
fields.extend(ctx.codegen_alignment_padding(
offset,
Expand Down
20 changes: 20 additions & 0 deletions tests/kani/Generator/issue-1593.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::{
future::Future,
pin::Pin,
sync::{
atomic::{AtomicI64, Ordering},
Arc,
},
};

#[kani::proof]
fn issue_1593() {
let x = Arc::new(AtomicI64::new(0));
let x2 = x.clone();
let gen = async move {
async {}.await;
x2.fetch_add(1, Ordering::Relaxed);
};
assert_eq!(std::mem::size_of_val(&gen), 16);
let pinbox = Box::pin(gen); // check that vtables work
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ fn cycle(
}

#[kani::proof]
#[kani::unwind(260)]
fn main() {
// Has only one invalid discr. value.
let gen_u8_tiny_niche = || {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ fn overlap_x_and_y() -> impl Generator<Yield = (), Return = ()> {

#[kani::proof]
fn main() {
// FIXME: size of generators does not work reliably (https://github.com/model-checking/kani/issues/1395)
assert_eq!(1025, std::mem::size_of_val(&move_before_yield()));
// The following assertion fails for some reason (tracking issue: https://github.com/model-checking/kani/issues/1395).
// But it also fails for WASM (https://github.com/rust-lang/rust/issues/62807),
// so it is probably not a big problem:
assert_eq!(1026, std::mem::size_of_val(&move_before_yield_with_noop()));
// With panic=unwind, the following assertion passes:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please improve this doc. Maybe add as a document of the harness itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// assert_eq!(1026, std::mem::size_of_val(&move_before_yield_with_noop()));
assert_eq!(1025, std::mem::size_of_val(&move_before_yield_with_noop()));
assert_eq!(2051, std::mem::size_of_val(&overlap_move_points()));
assert_eq!(1026, std::mem::size_of_val(&overlap_x_and_y()));
}