Index: unittests/Passes/CMakeLists.txt =================================================================== --- unittests/Passes/CMakeLists.txt +++ unittests/Passes/CMakeLists.txt @@ -1,3 +1,7 @@ +# Hack to bypass LLVM's CMake source checks so we can have both a library and +# an executable built from this directory. +set(LLVM_OPTIONAL_SOURCES TestPlugin.cpp) + set(LLVM_LINK_COMPONENTS Support Passes Core) # If plugins are disabled, this test will disable itself at runtime. Otherwise, @@ -9,7 +13,7 @@ add_llvm_unittest(PluginsTests PluginsTest.cpp) export_executable_symbols(PluginsTests) -add_library(TestPlugin MODULE TestPlugin.cxx) +add_library(TestPlugin MODULE TestPlugin.cpp) set_output_directory(TestPlugin BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR} Index: unittests/Passes/TestPlugin.cpp =================================================================== --- unittests/Passes/TestPlugin.cpp +++ unittests/Passes/TestPlugin.cpp @@ -1,4 +1,4 @@ -//===- unittests/Passes/Plugins/Plugin.cxx --------------------------------===// +//===- unittests/Passes/Plugins/Plugin.cpp --------------------------------===// // // The LLVM Compiler Infrastructure // Index: unittests/Passes/TestPlugin.cxx =================================================================== --- unittests/Passes/TestPlugin.cxx +++ unittests/Passes/TestPlugin.cxx @@ -1,39 +0,0 @@ -//===- unittests/Passes/Plugins/Plugin.cxx --------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Passes/PassBuilder.h" -#include "llvm/Passes/PassPlugin.h" - -#include "TestPlugin.h" - -using namespace llvm; - -struct TestModulePass : public PassInfoMixin { - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) { - return PreservedAnalyses::all(); - } -}; - -void registerCallbacks(PassBuilder &PB) { - PB.registerPipelineParsingCallback( - [](StringRef Name, ModulePassManager &PM, - ArrayRef InnerPipeline) { - if (Name == "plugin-pass") { - PM.addPass(TestModulePass()); - return true; - } - return false; - }); -} - -extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK LLVM_PLUGIN_EXPORT -llvmGetPassPluginInfo() { - return {LLVM_PLUGIN_API_VERSION, TEST_PLUGIN_NAME, TEST_PLUGIN_VERSION, - registerCallbacks}; -} Index: unittests/Support/DynamicLibrary/CMakeLists.txt =================================================================== --- unittests/Support/DynamicLibrary/CMakeLists.txt +++ unittests/Support/DynamicLibrary/CMakeLists.txt @@ -1,6 +1,10 @@ +# Hack to bypass LLVM's CMake source checks so we can have both a library and +# an executable built from this directory. +set(LLVM_OPTIONAL_SOURCES ExportedFuncs.cpp PipSqueak.cpp) + set(LLVM_LINK_COMPONENTS Support) -add_library(DynamicLibraryLib STATIC ExportedFuncs.cxx) +add_library(DynamicLibraryLib STATIC ExportedFuncs.cpp) set_target_properties(DynamicLibraryLib PROPERTIES FOLDER "Tests") add_llvm_unittest(DynamicLibraryTests DynamicLibraryTest.cpp) @@ -8,7 +12,7 @@ export_executable_symbols(DynamicLibraryTests) function(dynlib_add_module NAME) - add_library(${NAME} SHARED PipSqueak.cxx) + add_library(${NAME} SHARED PipSqueak.cpp) set_target_properties(${NAME} PROPERTIES FOLDER "Tests") set_output_directory(${NAME} Index: unittests/Support/DynamicLibrary/ExportedFuncs.cpp =================================================================== --- unittests/Support/DynamicLibrary/ExportedFuncs.cpp +++ unittests/Support/DynamicLibrary/ExportedFuncs.cpp @@ -1,4 +1,4 @@ -//===- llvm/unittest/Support/DynamicLibrary/DynamicLibraryLib.cpp ---------===// +//===- llvm/unittest/Support/DynamicLibrary/ExportedFuncs.cpp -------------===// // // The LLVM Compiler Infrastructure // Index: unittests/Support/DynamicLibrary/ExportedFuncs.cxx =================================================================== --- unittests/Support/DynamicLibrary/ExportedFuncs.cxx +++ unittests/Support/DynamicLibrary/ExportedFuncs.cxx @@ -1,16 +0,0 @@ -//===- llvm/unittest/Support/DynamicLibrary/DynamicLibraryLib.cpp ---------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "PipSqueak.h" - -#ifndef PIPSQUEAK_TESTA_RETURN -#define PIPSQUEAK_TESTA_RETURN "ProcessCall" -#endif - -extern "C" PIPSQUEAK_EXPORT const char *TestA() { return PIPSQUEAK_TESTA_RETURN; } Index: unittests/Support/DynamicLibrary/PipSqueak.cpp =================================================================== --- unittests/Support/DynamicLibrary/PipSqueak.cpp +++ unittests/Support/DynamicLibrary/PipSqueak.cpp @@ -1,4 +1,4 @@ -//===- llvm/unittest/Support/DynamicLibrary/PipSqueak.cxx -----------------===// +//===- llvm/unittest/Support/DynamicLibrary/PipSqueak.cpp -----------------===// // // The LLVM Compiler Infrastructure // @@ -46,4 +46,4 @@ } #define PIPSQUEAK_TESTA_RETURN "LibCall" -#include "ExportedFuncs.cxx" +#include "ExportedFuncs.cpp" Index: unittests/Support/DynamicLibrary/PipSqueak.cxx =================================================================== --- unittests/Support/DynamicLibrary/PipSqueak.cxx +++ unittests/Support/DynamicLibrary/PipSqueak.cxx @@ -1,49 +0,0 @@ -//===- llvm/unittest/Support/DynamicLibrary/PipSqueak.cxx -----------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "PipSqueak.h" - -struct Global { - std::string *Str; - std::vector *Vec; - Global() : Str(nullptr), Vec(nullptr) {} - ~Global() { - if (Str) { - if (Vec) - Vec->push_back(*Str); - *Str = "Global::~Global"; - } - } -}; - -static Global Glb; - -struct Local { - std::string &Str; - Local(std::string &S) : Str(S) { - Str = "Local::Local"; - if (Glb.Str && !Glb.Str->empty()) - Str += std::string("(") + *Glb.Str + std::string(")"); - } - ~Local() { Str = "Local::~Local"; } -}; - - -extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr, - std::string &LStr) { - Glb.Str = &GStr; - static Local Lcl(LStr); -} - -extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector &V) { - Glb.Vec = &V; -} - -#define PIPSQUEAK_TESTA_RETURN "LibCall" -#include "ExportedFuncs.cxx"