wip
[bigint-presentation-code.git] / register_allocator / fuzz / fuzz_targets / fn_new.rs
index 0dae9509d16e0f6389e8b70037edfd14ffe18fca..76897217a12228bb062e1a1926abc924872cd155 100644 (file)
@@ -1,7 +1,20 @@
 #![no_main]
-use bigint_presentation_code_register_allocator::function::{FnFields, Function};
-use libfuzzer_sys::fuzz_target;
+use bigint_presentation_code_register_allocator::{
+    function::{FnFields, Function},
+    interned::GlobalState,
+};
+use libfuzzer_sys::{
+    arbitrary::{Arbitrary, Unstructured},
+    fuzz_target, Corpus,
+};
 
-fuzz_target!(|fields: FnFields| {
-    Function::new(fields).expect("should succeed");
+fuzz_target!(|data: &[u8]| -> Corpus {
+    GlobalState::scope(|| {
+        let u = Unstructured::new(data);
+        let Ok(fields) = FnFields::arbitrary_take_rest(u) else {
+            return Corpus::Reject;
+        };
+        Function::new(fields).expect("should succeed");
+        Corpus::Keep
+    })
 });