Skip to content

Commit 3498bc1

Browse files
committed
Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlin
Insert checks for enum discriminants when debug assertions are enabled Similar to the existing null-pointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR rust-lang/rust#104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@. r? `@saethlin`
2 parents 9a007c9 + f74d535 commit 3498bc1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub const MIRI_DEFAULT_ARGS: &[&str] = &[
168168
"-Zmir-emit-retag",
169169
"-Zmir-preserve-ub",
170170
"-Zmir-opt-level=0",
171-
"-Zmir-enable-passes=-CheckAlignment,-CheckNull",
171+
"-Zmir-enable-passes=-CheckAlignment,-CheckNull,-CheckEnums",
172172
// Deduplicating diagnostics means we miss events when tracking what happens during an
173173
// execution. Let's not do that.
174174
"-Zdeduplicate-diagnostics=no",

0 commit comments

Comments
 (0)