microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.2.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

fuzz/fuzz_targets/compile.rs

42lines · 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, LanguageFeatures, 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 LanguageFeatures::default(),
28 );
29 });
30 }
31}
32
33#[cfg(feature = "do_fuzz")]
34fuzz_target!(|data: &[u8]| {
35 compile(data);
36});
37
38#[cfg(not(feature = "do_fuzz"))]
39#[no_mangle]
40pub extern "C" fn main() {
41 compile(&[]);
42}
43