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
15 changes: 14 additions & 1 deletion kani-compiler/src/codegen_cprover_gotoc/context/goto_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,20 @@ impl<'tcx> LayoutOfHelpers<'tcx> for GotocCtx<'tcx, '_> {

#[inline]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
// Handle SizeOverflow errors gracefully instead of causing an ICE
if let LayoutError::SizeOverflow(_) = err {
self.tcx
.dcx()
.struct_span_err(
span,
format!("values of the type `{}` are too big for the target architecture", ty),
)
.emit();
self.tcx.dcx().abort_if_errors();
unreachable!()
} else {
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/ui/ice-size-overflow/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture\
lib/rustlib/src/rust/library/core/src/mem/mod.rs\
|\
const SIZE: usize = intrinsics::size_of::<Self>();\
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `<S<u8> as std::mem::SizedTypeProperties>::SIZE` failed here\

note: the above error was encountered while instantiating `fn std::mem::size_of::<S<u8>>`\
tests/ui/ice-size-overflow/large_array.rs\
|\
std::mem::size_of::<S<u8>>()\
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error; 1 warning emitted
20 changes: 20 additions & 0 deletions tests/ui/ice-size-overflow/large_array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test checks that the compiler handles extremely large array sizes
//! gracefully with a proper error message instead of causing an ICE.
//! Previously, this would trigger an internal compiler error at
//! kani-compiler/src/codegen_cprover_gotoc/context/goto_ctx.rs:371:9

struct S<T> {
x: [T; !0],
}

pub fn f() -> usize {
std::mem::size_of::<S<u8>>()
}

#[kani::proof]
fn main() {
let _x = f();
}
Loading