You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-Z valid-value-checks: invalid enum discriminant not reported when the enum is not a scalar or scalar pair #5023
T-High PriorityTag issues that have high priorityZ-Kani CompilerIssues that require some changes to the compiler[C] BugThis is a bug. Something isn't working.[F] SoundnessKani failed to detect an issue
#[repr(C)]structRaw{a:u32,b:u32,c:u32}#[allow(dead_code)]#[repr(u8)]enumG{A(u32,u32),B}// tag at byte 0, size 12#[cfg_attr(kani, kani::proof)]fnaggregate_enum(){let raw = Raw{a:7,b:0,c:0};let g = unsafe{(&raw as*constRawas*constG).read()};// UB: tag 7
std::mem::forget(g);}
Verification fails. The value read has tag 7, which is not a discriminant of G (Rust Reference,
[undefined.validity.enum]: "An enum must have a valid discriminant"). Kani's soundness page lists
"enum discriminants are in range" among the -Z valid-value-checks checks.
Actual behavior
** 0 of 6 failed
VERIFICATION:- SUCCESSFUL
The same read into #[repr(u8)] enum F { A(u8), B(u8) } (a ScalarPair layout) fails:
Failed Checks: Undefined Behavior: Invalid value of type `F`
Cause
For a directly tagged enum, ty_validity_per_offset
(kani-compiler/src/kani_middle/transform/check_values.rs:1073-1097) takes the enum's requirement
from ValidValueReq::try_from_ty, which returns None for ValueRepr::Aggregate
(check_values.rs:222-226). The fields of G (u32) have no requirements either, so the result
is an empty list and nothing is checked. (If a field had requirements, the same code would report
"Unsupported Enum" instead.) The tag's scalar and offset are available from VariantsShape::Multiple { tag, tag_field, .. } and could be used instead.
T-High PriorityTag issues that have high priorityZ-Kani CompilerIssues that require some changes to the compiler[C] BugThis is a bug. Something isn't working.[F] SoundnessKani failed to detect an issue
Activity
Valid-value checks: check reads of untyped bytes, not untyped writes (m…