镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Check aggregate-layout enum discriminants under -Z valid-value-checks - #5069

Open
kasimte wants to merge 1 commit into
model-checking:mainfrom
kasimte:fix-5023-aggregate-enum-validity
Open

kasimte wants to merge 1 commit into
model-checking:mainfrom
kasimte:fix-5023-aggregate-enum-validity

Conversation

@kasimte

@kasimte kasimte commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Resolves #5023.

-Z valid-value-checks did not report an invalid discriminant when an enum's layout is an aggregate rather than a scalar or scalar pair.

The fix reads the tag scalar's valid range in the VariantsShape::Multiple arm and checks it at the tag's offset. Aggregate-layout enums now get the same validity treatment as scalar and scalar-pair enums, including the mutable-cast restriction.

Testing

tests/expected/valid-value-checks/aggregate_enum.rs: a raw-pointer read with an out-of-range tag fails Invalid value of type `G` , a tag one past the valid range fails too, and valid tags verify.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

Reading an out-of-range discriminant for an enum whose layout is an
aggregate (not a scalar or scalar pair) was reported as valid. The
validity requirement was derived only from the type's top-level scalar,
which an aggregate layout lacks, so the discriminant tag went unchecked.

Build the tag's range check directly from the tag scalar in the
VariantsShape::Multiple arm, at the tag's offset. Scalar and scalar-pair
enums already get this from their top-level scalar, so skip them there.

Resolves model-checking#5023
@kasimte
kasimte requested review from a team as code owners October 27, 2026 00:08
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Oct 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-Z valid-value-checks: invalid enum discriminant not reported when the enum is not a scalar or scalar pair

1 participant