MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / generate_flags

Method generate_flags

cranelift/fuzzgen/src/lib.rs:175–262  ·  view source on GitHub ↗

Generate a random set of cranelift flags. Only semantics preserving flags are considered

(&mut self, target_arch: Architecture)

Source from the content-addressed store, hash-verified

173 /// Generate a random set of cranelift flags.
174 /// Only semantics preserving flags are considered
175 pub fn generate_flags(&mut self, target_arch: Architecture) -> arbitrary::Result<Flags> {
176 let mut builder = settings::builder();
177
178 let opt = self.u.choose(OptLevel::all())?;
179 builder.set("opt_level", &format!("{opt}")[..]).unwrap();
180
181 // Boolean flags
182 // TODO: enable_pinned_reg does not work with our current trampolines. See: #4376
183 // TODO: is_pic has issues:
184 // x86: https://github.com/bytecodealliance/wasmtime/issues/5005
185 // aarch64: https://github.com/bytecodealliance/wasmtime/issues/2735
186 let bool_settings = [
187 "enable_alias_analysis",
188 "unwind_info",
189 "preserve_frame_pointers",
190 "enable_heap_access_spectre_mitigation",
191 "enable_table_access_spectre_mitigation",
192 "enable_incremental_compilation_cache_checks",
193 "enable_compact_unwind_abi",
194 "regalloc_checker",
195 "enable_llvm_abi_extensions",
196 ];
197 for flag_name in bool_settings {
198 let enabled = self
199 .config
200 .compile_flag_ratio
201 .get(&flag_name)
202 .map(|&(num, denum)| self.u.ratio(num, denum))
203 .unwrap_or_else(|| bool::arbitrary(self.u))?;
204
205 let value = format!("{enabled}");
206 builder.set(flag_name, value.as_str()).unwrap();
207 }
208
209 let supports_inline_probestack = match target_arch {
210 Architecture::X86_64 => true,
211 Architecture::Aarch64(_) => true,
212 Architecture::Riscv64(_) => true,
213 _ => false,
214 };
215
216 // Optionally test inline stackprobes on supported platforms
217 // TODO: Test outlined stack probes.
218 if supports_inline_probestack && bool::arbitrary(self.u)? {
219 builder.enable("enable_probestack").unwrap();
220 builder.set("probestack_strategy", "inline").unwrap();
221
222 let size = self
223 .u
224 .int_in_range(self.config.stack_probe_size_log2.clone())?;
225 builder
226 .set("probestack_size_log2", &format!("{size}"))
227 .unwrap();
228 }
229
230 // Generate random basic block padding
231 let bb_padding = self
232 .u

Callers 2

generateMethod · 0.80
generateMethod · 0.80

Calls 10

OkFunction · 0.85
builderFunction · 0.50
newFunction · 0.50
unwrapMethod · 0.45
setMethod · 0.45
mapMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45
enableMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected