1//===-- ClangFormatFuzzer.cpp - Fuzz the Clang format tool ----------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8/// 9/// \file 10/// This file implements a function that runs Clang format on a single 11/// input. This function is then linked into the Fuzzer library. 12/// 13//===----------------------------------------------------------------------===// 14 15#include "clang/Format/Format.h" 16 17extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { 18 // FIXME: fuzz more things: different styles, different style features. 19 std::string s((const char *)data, size); 20 auto Style = getGoogleStyle(clang::format::FormatStyle::LK_Cpp); 21 Style.ColumnLimit = 60; 22 auto Replaces = reformat(Style, s, clang::tooling::Range(0, s.size())); 23 auto Result = applyAllReplacements(s, Replaces); 24 25 // Output must be checked, as otherwise we crash. 26 if (!Result) {} 27 return 0; 28} 29