Skip to content

Commit 707309b

Browse files
authored
Implement f16 and f128 cases in codegen_float_type (#3943)
See #3069 (comment) for a description of the issue. Resolves #3069 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent ce89f61 commit 707309b

File tree

2 files changed

+17
-3
lines changed
  • kani-compiler/src/codegen_cprover_gotoc/codegen
  • tests/kani/FloatingPoint

2 files changed

+17
-3
lines changed

kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,11 +1400,10 @@ impl<'tcx> GotocCtx<'tcx> {
14001400

14011401
pub fn codegen_float_type(&self, f: Float) -> Ty<'tcx> {
14021402
match f {
1403+
Float::F16 => self.tcx.types.f16,
14031404
Float::F32 => self.tcx.types.f32,
14041405
Float::F64 => self.tcx.types.f64,
1405-
// `F16` and `F128` are not yet handled.
1406-
// Tracked here: <https://github.com/model-checking/kani/issues/3069>
1407-
Float::F16 | Float::F128 => unimplemented!(),
1406+
Float::F128 => self.tcx.types.f128,
14081407
}
14091408
}
14101409

tests/kani/FloatingPoint/main.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#![feature(f16)]
55
#![feature(f128)]
6+
#![feature(repr_simd)]
67

78
macro_rules! test_floats {
89
($ty:ty) => {
@@ -35,3 +36,17 @@ fn main() {
3536
test_floats!(f64);
3637
test_floats!(f128);
3738
}
39+
40+
// Test that we can codegen floats when we hit them in codegen_float_type,
41+
// c.f. https://github.com/model-checking/kani/issues/3069#issuecomment-2730501056
42+
#[repr(simd)]
43+
struct f16x16([f16; 16]);
44+
45+
fn make_float_array() -> f16x16 {
46+
f16x16([1.0; 16])
47+
}
48+
49+
#[kani::proof]
50+
fn make_float_array_harness() {
51+
let _ = make_float_array();
52+
}

0 commit comments

Comments
 (0)