[clang-tools-extra] r357654 - Make clangd-fuzzer use the normal add_llvm_fuzzer() machinery
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 3 17:05:53 PDT 2019
Author: nico
Date: Wed Apr 3 17:05:53 2019
New Revision: 357654
URL: http://llvm.org/viewvc/llvm-project?rev=357654&view=rev
Log:
Make clangd-fuzzer use the normal add_llvm_fuzzer() machinery
This allows building it even if no fuzzer is enabled. (Sadly, it only
builds on Linux at the moment.)
Differential Revision: https://reviews.llvm.org/D60201
Added:
clang-tools-extra/trunk/clangd/fuzzer/DummyClangdMain.cpp
clang-tools-extra/trunk/clangd/fuzzer/clangd-fuzzer.cpp
Removed:
clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt
Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=357654&r1=357653&r2=357654&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Wed Apr 3 17:05:53 2019
@@ -116,7 +116,8 @@ add_clang_library(clangDaemon
)
add_subdirectory(refactor/tweaks)
-if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE )
+if (LINUX)
+ # FIXME: Make fuzzer not use linux-specific APIs, build it everywhere.
add_subdirectory(fuzzer)
endif()
add_subdirectory(tool)
Modified: clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt?rev=357654&r1=357653&r2=357654&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt Wed Apr 3 17:05:53 2019
@@ -2,13 +2,10 @@ include_directories(${CMAKE_CURRENT_SOUR
set(LLVM_LINK_COMPONENTS support)
-if(LLVM_USE_SANITIZE_COVERAGE)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
-endif()
-
-add_clang_executable(clangd-fuzzer
- EXCLUDE_FROM_ALL
- ClangdFuzzer.cpp
+# This fuzzer runs on oss-fuzz, so keep it around even if it looks unreferenced.
+add_llvm_fuzzer(clangd-fuzzer
+ clangd-fuzzer.cpp
+ DUMMY_MAIN DummyClangdMain.cpp
)
target_link_libraries(clangd-fuzzer
@@ -20,5 +17,4 @@ target_link_libraries(clangd-fuzzer
clangSema
clangTooling
clangToolingCore
- ${LLVM_LIB_FUZZING_ENGINE}
)
Removed: clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp?rev=357653&view=auto
==============================================================================
--- clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp (original)
+++ clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp (removed)
@@ -1,42 +0,0 @@
-//===-- ClangdFuzzer.cpp - Fuzz clangd ------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file implements a function that runs clangd on a single input.
-/// This function is then linked into the Fuzzer library.
-///
-//===----------------------------------------------------------------------===//
-
-#include "ClangdLSPServer.h"
-#include "ClangdServer.h"
-#include "CodeComplete.h"
-#include "FSProvider.h"
-#include <cstdio>
-#include <sstream>
-
-using namespace clang::clangd;
-
-extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
- if (size == 0)
- return 0;
-
- // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
- std::FILE *In = fmemopen(data, size, "r");
- auto Transport = newJSONTransport(In, llvm::nulls(),
- /*InMirror=*/nullptr, /*Pretty=*/false,
- /*Style=*/JSONStreamStyle::Delimited);
- RealFileSystemProvider FS;
- CodeCompleteOptions CCOpts;
- CCOpts.EnableSnippets = false;
- ClangdServer::Options Opts;
-
- // Initialize and run ClangdLSPServer.
- ClangdLSPServer LSPServer(*Transport, FS, CCOpts, llvm::None, false, Opts);
- LSPServer.run();
- return 0;
-}
Added: clang-tools-extra/trunk/clangd/fuzzer/DummyClangdMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/DummyClangdMain.cpp?rev=357654&view=auto
==============================================================================
--- clang-tools-extra/trunk/clangd/fuzzer/DummyClangdMain.cpp (added)
+++ clang-tools-extra/trunk/clangd/fuzzer/DummyClangdMain.cpp Wed Apr 3 17:05:53 2019
@@ -0,0 +1,18 @@
+//===---- DummyClangdMain.cpp - Entry point to sanity check the fuzzer ----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of main so we can build and test without linking libFuzzer.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/FuzzMutate/FuzzerCLI.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
+int main(int argc, char *argv[]) {
+ return llvm::runFuzzerOnInputs(argc, argv, LLVMFuzzerTestOneInput);
+}
Added: clang-tools-extra/trunk/clangd/fuzzer/clangd-fuzzer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/clangd-fuzzer.cpp?rev=357654&view=auto
==============================================================================
--- clang-tools-extra/trunk/clangd/fuzzer/clangd-fuzzer.cpp (added)
+++ clang-tools-extra/trunk/clangd/fuzzer/clangd-fuzzer.cpp Wed Apr 3 17:05:53 2019
@@ -0,0 +1,42 @@
+//===-- ClangdFuzzer.cpp - Fuzz clangd ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file implements a function that runs clangd on a single input.
+/// This function is then linked into the Fuzzer library.
+///
+//===----------------------------------------------------------------------===//
+
+#include "ClangdLSPServer.h"
+#include "ClangdServer.h"
+#include "CodeComplete.h"
+#include "FSProvider.h"
+#include <cstdio>
+#include <sstream>
+
+using namespace clang::clangd;
+
+extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+ if (size == 0)
+ return 0;
+
+ // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
+ std::FILE *In = fmemopen(data, size, "r");
+ auto Transport = newJSONTransport(In, llvm::nulls(),
+ /*InMirror=*/nullptr, /*Pretty=*/false,
+ /*Style=*/JSONStreamStyle::Delimited);
+ RealFileSystemProvider FS;
+ CodeCompleteOptions CCOpts;
+ CCOpts.EnableSnippets = false;
+ ClangdServer::Options Opts;
+
+ // Initialize and run ClangdLSPServer.
+ ClangdLSPServer LSPServer(*Transport, FS, CCOpts, llvm::None, false, Opts);
+ LSPServer.run();
+ return 0;
+}
More information about the cfe-commits
mailing list