blob: 5334ce873eca40e7281c451a25d7a2b00c210736 [file] [log] [blame]
Aaron Ballman66c653f2015-01-29 16:58:53 +00001//===-- ClangFormatFuzzer.cpp - Fuzz the Clang format tool ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file implements a function that runs Clang format on a single
12/// input. This function is then linked into the Fuzzer library.
13///
14//===----------------------------------------------------------------------===//
15
16#include "clang/Format/Format.h"
17
Kostya Serebryanye39fec52015-10-02 23:34:37 +000018extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
Aaron Ballman66c653f2015-01-29 16:58:53 +000019 // FIXME: fuzz more things: different styles, different style features.
20 std::string s((const char *)data, size);
21 auto Style = getGoogleStyle(clang::format::FormatStyle::LK_Cpp);
22 Style.ColumnLimit = 60;
23 applyAllReplacements(s, clang::format::reformat(
24 Style, s, {clang::tooling::Range(0, s.size())}));
Kostya Serebryanye39fec52015-10-02 23:34:37 +000025 return 0;
Aaron Ballman66c653f2015-01-29 16:58:53 +000026}