Skip to content

Commit

Permalink
[clang-tools-extra] Migrate llvm::make_unique to std::make_unique
Browse files Browse the repository at this point in the history
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

Differential revision: https://reviews.llvm.org/D66259

llvm-svn: 368944
  • Loading branch information
JDevlieghere committed Aug 14, 2019
1 parent 2b3d49b commit 1c705d9
Show file tree
Hide file tree
Showing 99 changed files with 344 additions and 344 deletions.
Expand Up @@ -109,7 +109,7 @@ getLexerStartingFromLoc(SourceLocation Loc, const SourceManager &SM,

const char *TokBegin = File.data() + LocInfo.second;
// Lex from the start of the given location.
return llvm::make_unique<Lexer>(SM.getLocForStartOfFile(LocInfo.first),
return std::make_unique<Lexer>(SM.getLocForStartOfFile(LocInfo.first),
LangOpts, File.begin(), TokBegin, File.end());
}

Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-doc/BitcodeReader.cpp
Expand Up @@ -329,7 +329,7 @@ template <> llvm::Expected<CommentInfo *> getCommentInfo(EnumInfo *I) {
}

template <> llvm::Expected<CommentInfo *> getCommentInfo(CommentInfo *I) {
I->Children.emplace_back(llvm::make_unique<CommentInfo>());
I->Children.emplace_back(std::make_unique<CommentInfo>());
return I->Children.back().get();
}

Expand Down Expand Up @@ -690,7 +690,7 @@ llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
template <typename T>
llvm::Expected<std::unique_ptr<Info>>
ClangDocBitcodeReader::createInfo(unsigned ID) {
std::unique_ptr<Info> I = llvm::make_unique<T>();
std::unique_ptr<Info> I = std::make_unique<T>();
if (auto Err = readBlock(ID, static_cast<T *>(I.get())))
return std::move(Err);
return std::unique_ptr<Info>{std::move(I)};
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-doc/ClangDoc.cpp
Expand Up @@ -43,7 +43,7 @@ clang::FrontendAction *MapperActionFactory::create() {
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &Compiler,
llvm::StringRef InFile) override {
return llvm::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx);
return std::make_unique<MapASTVisitor>(&Compiler.getASTContext(), CDCtx);
}

private:
Expand All @@ -54,7 +54,7 @@ clang::FrontendAction *MapperActionFactory::create() {

std::unique_ptr<tooling::FrontendActionFactory>
newMapperActionFactory(ClangDocContext CDCtx) {
return llvm::make_unique<MapperActionFactory>(CDCtx);
return std::make_unique<MapperActionFactory>(CDCtx);
}

} // namespace doc
Expand Down
102 changes: 51 additions & 51 deletions clang-tools-extra/clang-doc/HTMLGenerator.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clang-tools-extra/clang-doc/Representation.cpp
Expand Up @@ -36,7 +36,7 @@ reduce(std::vector<std::unique_ptr<Info>> &Values) {
if (Values.empty())
return llvm::make_error<llvm::StringError>(" No values to reduce.\n",
llvm::inconvertibleErrorCode());
std::unique_ptr<Info> Merged = llvm::make_unique<T>(Values[0]->USR);
std::unique_ptr<Info> Merged = std::make_unique<T>(Values[0]->USR);
T *Tmp = static_cast<T *>(Merged.get());
for (auto &I : Values)
Tmp->merge(std::move(*static_cast<T *>(I.get())));
Expand Down
24 changes: 12 additions & 12 deletions clang-tools-extra/clang-doc/Serialize.cpp
Expand Up @@ -90,7 +90,7 @@ void ClangDocCommentVisitor::parseComment(const comments::Comment *C) {
ConstCommentVisitor<ClangDocCommentVisitor>::visit(C);
for (comments::Comment *Child :
llvm::make_range(C->child_begin(), C->child_end())) {
CurrentCI.Children.emplace_back(llvm::make_unique<CommentInfo>());
CurrentCI.Children.emplace_back(std::make_unique<CommentInfo>());
ClangDocCommentVisitor Visitor(*CurrentCI.Children.back());
Visitor.parseComment(Child);
}
Expand Down Expand Up @@ -379,7 +379,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D,
std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const NamespaceDecl *D, const FullComment *FC, int LineNumber,
llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
auto I = llvm::make_unique<NamespaceInfo>();
auto I = std::make_unique<NamespaceInfo>();
bool IsInAnonymousNamespace = false;
populateInfo(*I, D, FC, IsInAnonymousNamespace);
if (PublicOnly && ((IsInAnonymousNamespace || D->isAnonymousNamespace()) ||
Expand All @@ -392,7 +392,7 @@ emitInfo(const NamespaceDecl *D, const FullComment *FC, int LineNumber,
if (I->Namespace.empty() && I->USR == SymbolID())
return {std::unique_ptr<Info>{std::move(I)}, nullptr};

auto ParentI = llvm::make_unique<NamespaceInfo>();
auto ParentI = std::make_unique<NamespaceInfo>();
ParentI->USR = I->Namespace.empty() ? SymbolID() : I->Namespace[0].USR;
ParentI->ChildNamespaces.emplace_back(I->USR, I->Name, InfoType::IT_namespace,
getInfoRelativePath(I->Namespace));
Expand All @@ -405,7 +405,7 @@ emitInfo(const NamespaceDecl *D, const FullComment *FC, int LineNumber,
std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber,
llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
auto I = llvm::make_unique<RecordInfo>();
auto I = std::make_unique<RecordInfo>();
bool IsInAnonymousNamespace = false;
populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
IsInAnonymousNamespace);
Expand All @@ -425,7 +425,7 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber,
I->Path = getInfoRelativePath(I->Namespace);

if (I->Namespace.empty()) {
auto ParentI = llvm::make_unique<NamespaceInfo>();
auto ParentI = std::make_unique<NamespaceInfo>();
ParentI->USR = SymbolID();
ParentI->ChildRecords.emplace_back(I->USR, I->Name, InfoType::IT_record,
getInfoRelativePath(I->Namespace));
Expand All @@ -436,15 +436,15 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber,

switch (I->Namespace[0].RefType) {
case InfoType::IT_namespace: {
auto ParentI = llvm::make_unique<NamespaceInfo>();
auto ParentI = std::make_unique<NamespaceInfo>();
ParentI->USR = I->Namespace[0].USR;
ParentI->ChildRecords.emplace_back(I->USR, I->Name, InfoType::IT_record,
getInfoRelativePath(I->Namespace));
return {std::unique_ptr<Info>{std::move(I)},
std::unique_ptr<Info>{std::move(ParentI)}};
}
case InfoType::IT_record: {
auto ParentI = llvm::make_unique<RecordInfo>();
auto ParentI = std::make_unique<RecordInfo>();
ParentI->USR = I->Namespace[0].USR;
ParentI->ChildRecords.emplace_back(I->USR, I->Name, InfoType::IT_record,
getInfoRelativePath(I->Namespace));
Expand All @@ -470,7 +470,7 @@ emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
Func.Access = clang::AccessSpecifier::AS_none;

// Wrap in enclosing scope
auto ParentI = llvm::make_unique<NamespaceInfo>();
auto ParentI = std::make_unique<NamespaceInfo>();
if (!Func.Namespace.empty())
ParentI->USR = Func.Namespace[0].USR;
else
Expand Down Expand Up @@ -508,7 +508,7 @@ emitInfo(const CXXMethodDecl *D, const FullComment *FC, int LineNumber,
Func.Access = D->getAccess();

// Wrap in enclosing scope
auto ParentI = llvm::make_unique<RecordInfo>();
auto ParentI = std::make_unique<RecordInfo>();
ParentI->USR = ParentUSR;
if (Func.Namespace.empty())
ParentI->Path = getInfoRelativePath(ParentI->Namespace);
Expand All @@ -533,7 +533,7 @@ emitInfo(const EnumDecl *D, const FullComment *FC, int LineNumber,

// Put in global namespace
if (Enum.Namespace.empty()) {
auto ParentI = llvm::make_unique<NamespaceInfo>();
auto ParentI = std::make_unique<NamespaceInfo>();
ParentI->USR = SymbolID();
ParentI->ChildEnums.emplace_back(std::move(Enum));
ParentI->Path = getInfoRelativePath(ParentI->Namespace);
Expand All @@ -545,15 +545,15 @@ emitInfo(const EnumDecl *D, const FullComment *FC, int LineNumber,
// Wrap in enclosing scope
switch (Enum.Namespace[0].RefType) {
case InfoType::IT_namespace: {
auto ParentI = llvm::make_unique<NamespaceInfo>();
auto ParentI = std::make_unique<NamespaceInfo>();
ParentI->USR = Enum.Namespace[0].USR;
ParentI->ChildEnums.emplace_back(std::move(Enum));
// Info is wrapped in its parent scope so it's returned in the second
// position
return {nullptr, std::unique_ptr<Info>{std::move(ParentI)}};
}
case InfoType::IT_record: {
auto ParentI = llvm::make_unique<RecordInfo>();
auto ParentI = std::make_unique<RecordInfo>();
ParentI->USR = Enum.Namespace[0].USR;
ParentI->ChildEnums.emplace_back(std::move(Enum));
// Info is wrapped in its parent scope so it's returned in the second
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-include-fixer/FuzzySymbolIndex.cpp
Expand Up @@ -134,7 +134,7 @@ FuzzySymbolIndex::createFromYAML(StringRef FilePath) {
auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
if (!Buffer)
return llvm::errorCodeToError(Buffer.getError());
return llvm::make_unique<MemSymbolIndex>(
return std::make_unique<MemSymbolIndex>(
find_all_symbols::ReadSymbolInfosFromYAML(Buffer.get()->getBuffer()));
}

Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
Expand Up @@ -34,7 +34,7 @@ class Action : public clang::ASTFrontendAction {
CreateASTConsumer(clang::CompilerInstance &Compiler,
StringRef InFile) override {
SemaSource.setFilePath(InFile);
return llvm::make_unique<clang::ASTConsumer>();
return std::make_unique<clang::ASTConsumer>();
}

void ExecuteAction() override {
Expand Down Expand Up @@ -104,7 +104,7 @@ bool IncludeFixerActionFactory::runInvocation(

// Run the parser, gather missing includes.
auto ScopedToolAction =
llvm::make_unique<Action>(SymbolIndexMgr, MinimizeIncludePaths);
std::make_unique<Action>(SymbolIndexMgr, MinimizeIncludePaths);
Compiler.ExecuteAction(*ScopedToolAction);

Contexts.push_back(ScopedToolAction->getIncludeFixerContext(
Expand Down
Expand Up @@ -27,7 +27,7 @@ std::unique_ptr<ASTConsumer>
FindAllSymbolsAction::CreateASTConsumer(CompilerInstance &Compiler,
StringRef InFile) {
Compiler.getPreprocessor().addCommentHandler(&Handler);
Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>(
Compiler.getPreprocessor().addPPCallbacks(std::make_unique<FindAllMacros>(
Reporter, &Compiler.getSourceManager(), &Collector));
return MatchFinder.newASTConsumer();
}
Expand Down
Expand Up @@ -145,7 +145,7 @@ int main(int argc, const char **argv) {
clang::find_all_symbols::YamlReporter Reporter;

auto Factory =
llvm::make_unique<clang::find_all_symbols::FindAllSymbolsActionFactory>(
std::make_unique<clang::find_all_symbols::FindAllSymbolsActionFactory>(
&Reporter, clang::find_all_symbols::getSTLPostfixHeaderMap());
return Tool.run(Factory.get());
}
Expand Up @@ -41,7 +41,7 @@ class ClangIncludeFixerPluginAction : public PluginASTAction {
CI.setExternalSemaSource(SemaSource);
SemaSource->setFilePath(InFile);
SemaSource->setCompilerInstance(&CI);
return llvm::make_unique<ASTConsumerManagerWrapper>(SymbolIndexMgr);
return std::make_unique<ASTConsumerManagerWrapper>(SymbolIndexMgr);
}

void ExecuteAction() override {} // Do nothing.
Expand Down
Expand Up @@ -161,7 +161,7 @@ std::unique_ptr<include_fixer::SymbolIndexManager>
createSymbolIndexManager(StringRef FilePath) {
using find_all_symbols::SymbolInfo;

auto SymbolIndexMgr = llvm::make_unique<include_fixer::SymbolIndexManager>();
auto SymbolIndexMgr = std::make_unique<include_fixer::SymbolIndexManager>();
switch (DatabaseFormat) {
case fixed: {
// Parse input and fill the database with it.
Expand All @@ -185,7 +185,7 @@ createSymbolIndexManager(StringRef FilePath) {
/*Used=*/0)});
}
SymbolIndexMgr->addSymbolIndex([=]() {
return llvm::make_unique<include_fixer::InMemorySymbolIndex>(Symbols);
return std::make_unique<include_fixer::InMemorySymbolIndex>(Symbols);
});
break;
}
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
Expand Up @@ -59,7 +59,7 @@ CallGraphNode *HelperDeclRefGraph::getOrInsertNode(Decl *F) {
if (Node)
return Node.get();

Node = llvm::make_unique<CallGraphNode>(F);
Node = std::make_unique<CallGraphNode>(F);
return Node.get();
}

Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clang-move/Move.cpp
Expand Up @@ -476,7 +476,7 @@ getUsedDecls(const HelperDeclRefGraph *RG,
std::unique_ptr<ASTConsumer>
ClangMoveAction::CreateASTConsumer(CompilerInstance &Compiler,
StringRef /*InFile*/) {
Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllIncludes>(
Compiler.getPreprocessor().addPPCallbacks(std::make_unique<FindAllIncludes>(
&Compiler.getSourceManager(), &MoveTool));
return MatchFinder.newASTConsumer();
}
Expand Down Expand Up @@ -610,7 +610,7 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
// Matchers for old files, including old.h/old.cc
//============================================================================
// Create a MatchCallback for class declarations.
MatchCallbacks.push_back(llvm::make_unique<ClassDeclarationMatch>(this));
MatchCallbacks.push_back(std::make_unique<ClassDeclarationMatch>(this));
// Match moved class declarations.
auto MovedClass = cxxRecordDecl(InOldFiles, *HasAnySymbolNames,
isDefinition(), TopLevelDecl)
Expand All @@ -629,19 +629,19 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
.bind("class_static_var_decl"),
MatchCallbacks.back().get());

MatchCallbacks.push_back(llvm::make_unique<FunctionDeclarationMatch>(this));
MatchCallbacks.push_back(std::make_unique<FunctionDeclarationMatch>(this));
Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl)
.bind("function"),
MatchCallbacks.back().get());

MatchCallbacks.push_back(llvm::make_unique<VarDeclarationMatch>(this));
MatchCallbacks.push_back(std::make_unique<VarDeclarationMatch>(this));
Finder->addMatcher(
varDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl).bind("var"),
MatchCallbacks.back().get());

// Match enum definition in old.h. Enum helpers (which are defined in old.cc)
// will not be moved for now no matter whether they are used or not.
MatchCallbacks.push_back(llvm::make_unique<EnumDeclarationMatch>(this));
MatchCallbacks.push_back(std::make_unique<EnumDeclarationMatch>(this));
Finder->addMatcher(
enumDecl(InOldHeader, *HasAnySymbolNames, isDefinition(), TopLevelDecl)
.bind("enum"),
Expand All @@ -650,7 +650,7 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
// Match type alias in old.h, this includes "typedef" and "using" type alias
// declarations. Type alias helpers (which are defined in old.cc) will not be
// moved for now no matter whether they are used or not.
MatchCallbacks.push_back(llvm::make_unique<TypeAliasMatch>(this));
MatchCallbacks.push_back(std::make_unique<TypeAliasMatch>(this));
Finder->addMatcher(namedDecl(anyOf(typedefDecl().bind("typedef"),
typeAliasDecl().bind("type_alias")),
InOldHeader, *HasAnySymbolNames, TopLevelDecl),
Expand Down
Expand Up @@ -302,7 +302,7 @@ class ReorderingConsumer : public ASTConsumer {
} // end anonymous namespace

std::unique_ptr<ASTConsumer> ReorderFieldsAction::newASTConsumer() {
return llvm::make_unique<ReorderingConsumer>(RecordName, DesiredFieldsOrder,
return std::make_unique<ReorderingConsumer>(RecordName, DesiredFieldsOrder,
Replacements);
}

Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Expand Up @@ -390,7 +390,7 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(

std::unique_ptr<ClangTidyProfiling> Profiling;
if (Context.getEnableProfiling()) {
Profiling = llvm::make_unique<ClangTidyProfiling>(
Profiling = std::make_unique<ClangTidyProfiling>(
Context.getProfileStorageParams());
FinderOptions.CheckProfiling.emplace(Profiling->Records);
}
Expand All @@ -402,7 +402,7 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
Preprocessor *ModuleExpanderPP = PP;

if (Context.getLangOpts().Modules && OverlayFS != nullptr) {
auto ModuleExpander = llvm::make_unique<ExpandModularHeadersPPCallbacks>(
auto ModuleExpander = std::make_unique<ExpandModularHeadersPPCallbacks>(
&Compiler, OverlayFS);
ModuleExpanderPP = ModuleExpander->getPreprocessor();
PP->addPPCallbacks(std::move(ModuleExpander));
Expand Down Expand Up @@ -434,7 +434,7 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
Consumers.push_back(std::move(AnalysisConsumer));
}
#endif // CLANG_ENABLE_STATIC_ANALYZER
return llvm::make_unique<ClangTidyASTConsumer>(
return std::make_unique<ClangTidyASTConsumer>(
std::move(Consumers), std::move(Profiling), std::move(Finder),
std::move(Checks));
}
Expand Down Expand Up @@ -469,7 +469,7 @@ std::vector<std::string>
getCheckNames(const ClangTidyOptions &Options,
bool AllowEnablingAnalyzerAlphaCheckers) {
clang::tidy::ClangTidyContext Context(
llvm::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
Options),
AllowEnablingAnalyzerAlphaCheckers);
ClangTidyASTConsumerFactory Factory(Context);
Expand All @@ -480,7 +480,7 @@ ClangTidyOptions::OptionMap
getCheckOptions(const ClangTidyOptions &Options,
bool AllowEnablingAnalyzerAlphaCheckers) {
clang::tidy::ClangTidyContext Context(
llvm::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
Options),
AllowEnablingAnalyzerAlphaCheckers);
ClangTidyASTConsumerFactory Factory(Context);
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Expand Up @@ -213,9 +213,9 @@ void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) {
void ClangTidyContext::setCurrentFile(StringRef File) {
CurrentFile = File;
CurrentOptions = getOptionsForFile(CurrentFile);
CheckFilter = llvm::make_unique<CachedGlobList>(*getOptions().Checks);
CheckFilter = std::make_unique<CachedGlobList>(*getOptions().Checks);
WarningAsErrorFilter =
llvm::make_unique<CachedGlobList>(*getOptions().WarningsAsErrors);
std::make_unique<CachedGlobList>(*getOptions().WarningsAsErrors);
}

void ClangTidyContext::setASTContext(ASTContext *Context) {
Expand Down Expand Up @@ -604,7 +604,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() {
if (!HeaderFilter)
HeaderFilter =
llvm::make_unique<llvm::Regex>(*Context.getOptions().HeaderFilterRegex);
std::make_unique<llvm::Regex>(*Context.getOptions().HeaderFilterRegex);
return HeaderFilter.get();
}

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/ClangTidyOptions.h
Expand Up @@ -199,7 +199,7 @@ class FileOptionsProvider : public DefaultOptionsProvider {
/// FileOptionsProvider::ConfigFileHandlers ConfigHandlers;
/// ConfigHandlers.emplace_back(".my-tidy-config", parseMyConfigFormat);
/// ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
/// return llvm::make_unique<FileOptionsProvider>(
/// return std::make_unique<FileOptionsProvider>(
/// GlobalOptions, DefaultOptions, OverrideOptions, ConfigHandlers);
/// \endcode
///
Expand Down

0 comments on commit 1c705d9

Please sign in to comment.