Index: lldb/unittests/Symbol/TestTypeSystemClang.cpp =================================================================== --- lldb/unittests/Symbol/TestTypeSystemClang.cpp +++ lldb/unittests/Symbol/TestTypeSystemClang.cpp @@ -17,6 +17,9 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/ExprCXX.h" #include "gtest/gtest.h" +#include "clang/Lex/HeaderSearchOptions.h" +#include "clang/CodeGen/BackendUtil.h" +#include "llvm/Support/ThreadPool.h" using namespace clang; using namespace lldb; @@ -741,3 +744,25 @@ ScratchTypeSystemClang::IsolatedASTKind::CppModules, ScratchTypeSystemClang::InferIsolatedASTKindFromLangOpts(lang_opts)); } + + +TEST_F(TestTypeSystemClang, FuzzClangBackend) { + llvm::ThreadPoolStrategy s; + s.ThreadsRequested = 4000; + llvm::ThreadPool Pool(s); + for (size_t i = 0; i < s.ThreadsRequested; ++i) { + Pool.async([this, i] { + clang::CodeGenOptions cgopts; + clang::HeaderSearchOptions hs; + clang::TargetOptions topts; + llvm::LLVMContext ctx; + llvm::Module m("foo", ctx); + auto os = std::make_unique(); + clang::EmitBackendOutput(m_ast->getASTContext().getDiagnostics(), hs, cgopts, + topts, *m_ast->GetLangOpts(), + m_ast->getASTContext().getTargetInfo().getDataLayout(), + &m, Backend_EmitNothing, std::move(os)); + }); + } + Pool.wait(); +} Index: llvm/lib/Support/CommandLine.cpp =================================================================== --- llvm/lib/Support/CommandLine.cpp +++ llvm/lib/Support/CommandLine.cpp @@ -44,6 +44,7 @@ #include #include #include +#include using namespace llvm; using namespace cl; @@ -207,12 +208,16 @@ void addOption(Option *O, SubCommand *SC) { bool HadErrors = false; if (O->hasArgStr()) { + if (O->ArgStr == "h") + llvm::errs() << (void*)SC << "\n"; // If it's a DefaultOption, check to make sure it isn't already there. if (O->isDefaultOption() && SC->OptionsMap.find(O->ArgStr) != SC->OptionsMap.end()) return; + usleep(rand() % 20); // Add argument to the argument map! + llvm::errs() << "Inserting " << O->ArgStr << "\n"; if (!SC->OptionsMap.insert(std::make_pair(O->ArgStr, O)).second) { errs() << ProgramName << ": CommandLine Error: Option '" << O->ArgStr << "' registered more than once!\n"; @@ -237,8 +242,10 @@ // indicate serious issues such as conflicting option names or an // incorrectly // linked LLVM distribution. - if (HadErrors) + if (HadErrors) { + abort(); report_fatal_error("inconsistency in registered CommandLine options"); + } // If we're adding this to all sub-commands, add it to the ones that have // already been registered. Index: llvm/utils/unittest/UnitTestMain/TestMain.cpp =================================================================== --- llvm/utils/unittest/UnitTestMain/TestMain.cpp +++ llvm/utils/unittest/UnitTestMain/TestMain.cpp @@ -27,7 +27,7 @@ // Initialize both gmock and gtest. testing::InitGoogleMock(&argc, argv); - llvm::cl::ParseCommandLineOptions(argc, argv); + //llvm::cl::ParseCommandLineOptions(argc, argv); // Make it easy for a test to re-execute itself by saving argv[0]. TestMainArgv0 = argv[0];