thakis created this revision.
thakis added a reviewer: bkramer.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ioeric, 
ilya-biryukov, mgorny.

This allows building it even if no fuzzer is enabled. (Sadly, it only builds on 
Linux at the moment.)


https://reviews.llvm.org/D60201

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/fuzzer/CMakeLists.txt
  clang-tools-extra/clangd/fuzzer/ClangdFuzzer.cpp
  clang-tools-extra/clangd/fuzzer/DummyClangdMain.cpp
  clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp


Index: clang-tools-extra/clangd/fuzzer/DummyClangdMain.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/fuzzer/DummyClangdMain.cpp
@@ -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);
+}
Index: clang-tools-extra/clangd/fuzzer/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/fuzzer/CMakeLists.txt
+++ clang-tools-extra/clangd/fuzzer/CMakeLists.txt
@@ -2,13 +2,10 @@
 
 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 @@
   clangSema
   clangTooling
   clangToolingCore
-  ${LLVM_LIB_FUZZING_ENGINE}
   )
Index: clang-tools-extra/clangd/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -116,7 +116,8 @@
   )
 
 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)


Index: clang-tools-extra/clangd/fuzzer/DummyClangdMain.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/fuzzer/DummyClangdMain.cpp
@@ -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);
+}
Index: clang-tools-extra/clangd/fuzzer/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/fuzzer/CMakeLists.txt
+++ clang-tools-extra/clangd/fuzzer/CMakeLists.txt
@@ -2,13 +2,10 @@
 
 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 @@
   clangSema
   clangTooling
   clangToolingCore
-  ${LLVM_LIB_FUZZING_ENGINE}
   )
Index: clang-tools-extra/clangd/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -116,7 +116,8 @@
   )
 
 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)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to