microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.3

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

fuzz/fuzz_targets/compile.rs

41lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![no_main]
5
6#[cfg(feature = "do_fuzz")]
7use libfuzzer_sys::fuzz_target;
8use qsc::{hir::PackageId, target::Profile, PackageStore, SourceMap};
9
10fn compile(data: &[u8]) {
11 if let Ok(fuzzed_code) = std::str::from_utf8(data) {
12 thread_local! {
13 static STORE_STD: (PackageStore, PackageId) = {
14 let mut store = PackageStore::new(qsc::compile::core());
15 let std = store.insert(qsc::compile::std(&store, Profile::Unrestricted.into()));
16 (store, std)
17 };
18 }
19 let sources = SourceMap::new([("fuzzed_code".into(), fuzzed_code.into())], None);
20 STORE_STD.with(|(store, std)| {
21 let mut _unit = qsc::compile::compile(
22 store,
23 &[*std],
24 sources,
25 qsc::PackageType::Lib,
26 Profile::Unrestricted.into(),
27 );
28 });
29 }
30}
31
32#[cfg(feature = "do_fuzz")]
33fuzz_target!(|data: &[u8]| {
34 compile(data);
35});
36
37#[cfg(not(feature = "do_fuzz"))]
38#[no_mangle]
39pub extern "C" fn main() {
40 compile(&[]);
41}
42