blob: 3c50f81303aa9e4cc357752f2b827fc93e7b3aa5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//===-- ClangFuzzer.cpp - Fuzz Clang --------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file implements a function that runs Clang on a single
/// input. This function is then linked into the Fuzzer library.
///
//===----------------------------------------------------------------------===//
#include "clang/Tooling/Tooling.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/CompilerInstance.h"
using namespace clang;
extern "C" void TestOneInput(uint8_t *data, size_t size) {
std::string s((const char *)data, size);
llvm::IntrusiveRefCntPtr<FileManager> Files(
new FileManager(FileSystemOptions()));
tooling::ToolInvocation Invocation({"clang", "-c", "test.cc"},
new clang::SyntaxOnlyAction, Files.get());
IgnoringDiagConsumer Diags;
Invocation.setDiagnosticConsumer(&Diags);
Invocation.mapVirtualFile("test.cc", s);
Invocation.run();
}
|