Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 15 additions & 1 deletion src/pass/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,21 @@ impl<'a> Emitter<'a> {
(TypeT::SizeT, TypeT::SpecInt | TypeT::SpecNat) => {
unaryfn(Doc::text("SizeT.v"), val_doc)
}
(TypeT::SizeT, TypeT::Int { signed, width }) => {
if let Some(m) = get_int_mod(signed, width) {
unaryfn(
Doc::text(format!(
"{}.{} (SizeT.v",
m,
if *signed { "int_to_t" } else { "uint_to_t" }
)),
val_doc.append(Doc::text(")")),
)
} else {
self.report(default_msg.clone(), &v.loc);
Doc::text("(admit())")
}
}
(TypeT::Int { signed, width }, TypeT::SizeT) => {
if let Some(m) = get_int_mod(signed, width) {
unaryfn(
Expand Down Expand Up @@ -1893,7 +1908,6 @@ impl<'a> Emitter<'a> {
// (TypeT::Int { signed, width }, TypeT::SizeT) => todo!(),
// (TypeT::Int { signed, width }, TypeT::SLProp) => todo!(),
// (TypeT::SizeT, TypeT::Bool) => todo!(),
// (TypeT::SizeT, TypeT::Int { signed, width }) => todo!(),
// (TypeT::SizeT, TypeT::SLProp) => todo!(),
// (TypeT::Pointer { to, kind }, TypeT::Bool) => todo!(),
(TypeT::Pointer(_, kind), TypeT::Bool) => {
Expand Down
1 change: 1 addition & 0 deletions test/cast_sizet_to_uint32/Makefile
17 changes: 17 additions & 0 deletions test/cast_sizet_to_uint32/cast_sizet_to_uint32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "pal.h"
#include <stddef.h>
#include <stdint.h>

uint32_t sizet_to_u32(size_t n)
_requires((_specint) n <= UINT32_MAX)
Comment thread
KimayaBedarkar marked this conversation as resolved.
_ensures((_specint) return == n)
{
return (uint32_t) n;
}
Comment thread
KimayaBedarkar marked this conversation as resolved.

int32_t sizet_to_i32(size_t n)
_requires((_specint) n <= INT32_MAX)
_ensures((_specint) return == n)
{
return (int32_t) n;
}
1 change: 1 addition & 0 deletions test/cast_sizet_to_uint32/fstar.fst.config.json
1 change: 1 addition & 0 deletions test/cast_sizet_to_uint32/pal.config.json
1 change: 1 addition & 0 deletions test/cast_sizet_to_uint32/pal.h
Loading