blob: d440a6124b670088781fcc43258ff0b5c6e76ad1 [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;
George Karpenkov8d15bbb2017-08-24 00:30:28 +000023 auto Replaces = reformat(Style, s, clang::tooling::Range(0, s.size()));
24 auto Result = applyAllReplacements(s, Replaces);
25
26 // Output must be checked, as otherwise we crash.
27 if (!Result) {}
Kostya Serebryanye39fec52015-10-02 23:34:37 +000028 return 0;
Aaron Ballman66c653f2015-01-29 16:58:53 +000029}