microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
093ccfe61ad36cf37e941166f17d21c2a4bcd8f8

Branches

Tags

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

Clone

HTTPS

Download ZIP

fuzz/fuzz_targets/compile.rs

44lines · modecode

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