Aaron Ballman | 66c653f | 2015-01-29 16:58:53 +0000 | [diff] [blame] | 1 | //===-- 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 Serebryany | e39fec5 | 2015-10-02 23:34:37 +0000 | [diff] [blame] | 18 | extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { |
Aaron Ballman | 66c653f | 2015-01-29 16:58:53 +0000 | [diff] [blame] | 19 | // 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 Serebryany | e39fec5 | 2015-10-02 23:34:37 +0000 | [diff] [blame] | 25 | return 0; |
Aaron Ballman | 66c653f | 2015-01-29 16:58:53 +0000 | [diff] [blame] | 26 | } |