[PATCH] D99650: Demonstrating lack of thread-safety in BackendUtil
Raphael Isemann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 31 04:34:29 PDT 2021
teemperor created this revision.
Herald added subscribers: dexonsmith, hiraditya.
teemperor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Do not merge, this is just a demo patch.
https://reviews.llvm.org/D99650
Files:
lldb/unittests/Symbol/TestTypeSystemClang.cpp
llvm/lib/Support/CommandLine.cpp
llvm/utils/unittest/UnitTestMain/TestMain.cpp
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];
Index: llvm/lib/Support/CommandLine.cpp
===================================================================
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -44,6 +44,7 @@
#include <cstdlib>
#include <map>
#include <string>
+#include <unistd.h>
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: 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<llvm::raw_null_ostream>();
+ 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();
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99650.334407.patch
Type: text/x-patch
Size: 3464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210331/8ef3206f/attachment.bin>
More information about the llvm-commits
mailing list