File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed
kani-compiler/src/codegen_cprover_gotoc/codegen Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -1140,7 +1140,7 @@ impl<'tcx> GotocCtx<'tcx> {
1140
1140
1141
1141
/// Mapping enums to CBMC types is rather complicated. There are a few cases to consider:
1142
1142
/// 1. When there is only 0 or 1 variant, this is straightforward as the code shows
1143
- /// 2. When there are more variants, rust might decides to apply the typical encoding which
1143
+ /// 2. When there are more variants, rust might decide to apply the typical encoding which
1144
1144
/// regard enums as tagged union, or an optimized form, called niche encoding.
1145
1145
///
1146
1146
/// The direct encoding is straightforward. Enums are just mapped to C as a struct of union of structs.
@@ -1242,6 +1242,23 @@ impl<'tcx> GotocCtx<'tcx> {
1242
1242
)
1243
1243
} ) ,
1244
1244
) ) ;
1245
+ // Check if any padding is needed for alignment. This is needed for
1246
+ // https://github.com/model-checking/kani/issues/2857 for example.
1247
+ // The logic for determining the maximum variant size is taken from:
1248
+ // https://github.com/rust-lang/rust/blob/e60ebb2f2c1facba87e7971798f3cbdfd309cd23/compiler/rustc_session/src/code_stats.rs#L166
1249
+ let max_variant_size = variants
1250
+ . iter ( )
1251
+ . map ( |l : & LayoutS < FieldIdx , VariantIdx > | l. size )
1252
+ . max ( )
1253
+ . unwrap ( ) ;
1254
+ let max_variant_size = std:: cmp:: max ( max_variant_size, discr_offset) ;
1255
+ if let Some ( padding) = gcx. codegen_alignment_padding (
1256
+ max_variant_size,
1257
+ & layout,
1258
+ fields. len ( ) ,
1259
+ ) {
1260
+ fields. push ( padding) ;
1261
+ }
1245
1262
fields
1246
1263
} )
1247
1264
}
Original file line number Diff line number Diff line change
1
+ # Copyright Kani Contributors
2
+ # SPDX-License-Identifier: Apache-2.0 OR MIT
3
+ [package ]
4
+ name = " iss2857"
5
+ version = " 0.1.0"
6
+ edition = " 2021"
7
+
8
+ [dependencies ]
9
+ sec1 = " 0.7.3"
Original file line number Diff line number Diff line change
1
+ VERIFICATION:- SUCCESSFUL
Original file line number Diff line number Diff line change
1
+ // Copyright Kani Contributors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ // This test checks that https://github.com/model-checking/kani/issues/2857 is
5
+ // fixed
6
+
7
+ #[ kani:: proof]
8
+ fn check_der_error ( ) {
9
+ let e = sec1:: der:: Error :: incomplete ( sec1:: der:: Length :: ZERO ) ;
10
+ let _ = format ! ( "{e:?}" ) ;
11
+ }
12
+
13
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments