[clang] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#139399)

This commit is contained in:
Kazu Hirata 2025-05-10 12:11:17 -07:00 committed by GitHub
parent a92de02ea3
commit f5f8ddc166
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 23 additions and 25 deletions

View File

@ -909,13 +909,13 @@ interp::Context &ASTContext::getInterpContext() {
if (!InterpContext) {
InterpContext.reset(new interp::Context(*this));
}
return *InterpContext.get();
return *InterpContext;
}
ParentMapContext &ASTContext::getParentMapContext() {
if (!ParentMapCtx)
ParentMapCtx.reset(new ParentMapContext(*this));
return *ParentMapCtx.get();
return *ParentMapCtx;
}
static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI,
@ -13066,7 +13066,7 @@ bool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const {
}
VTableContextBase *ASTContext::getVTableContext() {
if (!VTContext.get()) {
if (!VTContext) {
auto ABI = Target->getCXXABI();
if (ABI.isMicrosoft())
VTContext.reset(new MicrosoftVTableContext(*this));

View File

@ -105,7 +105,7 @@ public:
}
/// Returns the program. This is only needed for unittests.
Program &getProgram() const { return *P.get(); }
Program &getProgram() const { return *P; }
unsigned collectBaseOffset(const RecordDecl *BaseDecl,
const RecordDecl *DerivedDecl) const;

View File

@ -985,7 +985,7 @@ llvm::GlobalVariable *CodeGenVTables::GenerateConstructionVTable(
assert(!VTable->isDeclaration() && "Shouldn't set properties on declaration");
CGM.setGVProperties(VTable, RD);
CGM.EmitVTableTypeMetadata(RD, VTable, *VTLayout.get());
CGM.EmitVTableTypeMetadata(RD, VTable, *VTLayout);
if (UsingRelativeLayout) {
RemoveHwasanMetadata(VTable);

View File

@ -180,7 +180,7 @@ static void validateSpecialCaseListFormat(const Driver &D,
std::string BLError;
std::unique_ptr<llvm::SpecialCaseList> SCL(
llvm::SpecialCaseList::create(SCLFiles, D.getVFS(), BLError));
if (!SCL.get() && DiagnoseErrors)
if (!SCL && DiagnoseErrors)
D.Diag(MalformedSCLErrorDiagID) << BLError;
}

View File

@ -1248,7 +1248,7 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
llvm::CrashRecoveryContextCleanupRegistrar<TopLevelDeclTrackerAction>
ActCleanup(Act.get());
if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
if (!Act->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
return true;
if (SavedMainFileBuffer)
@ -1650,7 +1650,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
llvm::CrashRecoveryContextCleanupRegistrar<TopLevelDeclTrackerAction>
ActCleanup(TrackerAct.get());
if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
if (!Act->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
AST->transferASTDataFromCompilerInstance(*Clang);
if (OwnAST && ErrAST)
ErrAST->swap(OwnAST);
@ -2333,7 +2333,7 @@ void ASTUnit::CodeComplete(
if (!Act)
Act.reset(new SyntaxOnlyAction);
if (Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
if (Act->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
if (llvm::Error Err = Act->Execute()) {
consumeError(std::move(Err)); // FIXME this drops errors on the floor.
}

View File

@ -512,7 +512,7 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
std::move(Buffer),
/*WritePCHFile=*/Storage->getKind() == PCHStorage::Kind::TempFile,
Callbacks);
if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
if (!Act->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
return BuildPreambleError::BeginSourceFileFailed;
// Performed after BeginSourceFile to ensure Clang->Preprocessor can be

View File

@ -109,7 +109,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(S.get());
ParseAST(*S.get(), PrintStats, SkipFunctionBodies);
ParseAST(*S, PrintStats, SkipFunctionBodies);
}
void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
@ -131,7 +131,7 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
std::unique_ptr<Parser> ParseOP(
new Parser(S.getPreprocessor(), S, SkipFunctionBodies));
Parser &P = *ParseOP.get();
Parser &P = *ParseOP;
llvm::CrashRecoveryContextCleanupRegistrar<const void, ResetStackCleanup>
CleanupPrettyStack(llvm::SavePrettyStackState());

View File

@ -601,7 +601,7 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
std::unique_ptr<llvm::MCStreamer> Str(createNullStreamer(Ctx));
std::unique_ptr<llvm::MCAsmParser> Parser(
createMCAsmParser(TempSrcMgr, Ctx, *Str.get(), *MAI));
createMCAsmParser(TempSrcMgr, Ctx, *Str, *MAI));
std::unique_ptr<llvm::MCTargetAsmParser> TargetParser(
TheTarget->createMCAsmParser(*STI, *Parser, *MII, MCOptions));
@ -617,7 +617,7 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
// Change to the Intel dialect.
Parser->setAssemblerDialect(1);
Parser->setTargetParser(*TargetParser.get());
Parser->setTargetParser(*TargetParser);
Parser->setParsingMSInlineAsm(true);
TargetParser->setParsingMSInlineAsm(true);

View File

@ -577,7 +577,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
Triple T(Opts.Triple);
Str.reset(TheTarget->createMCObjectStreamer(
T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI));
Str.get()->initSections(Opts.NoExecStack, *STI);
Str->initSections(Opts.NoExecStack, *STI);
if (T.isOSBinFormatMachO() && T.isOSDarwin()) {
Triple *TVT = Opts.DarwinTargetVariantTriple
? &*Opts.DarwinTargetVariantTriple
@ -592,14 +592,14 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) {
MCSection *AsmLabel = Ctx.getMachOSection(
"__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly());
Str.get()->switchSection(AsmLabel);
Str.get()->emitZeros(1);
Str->switchSection(AsmLabel);
Str->emitZeros(1);
}
bool Failed = false;
std::unique_ptr<MCAsmParser> Parser(
createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI));
createMCAsmParser(SrcMgr, Ctx, *Str, *MAI));
// FIXME: init MCTargetOptions from sanitizer flags here.
std::unique_ptr<MCTargetAsmParser> TAP(
@ -619,7 +619,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
}
if (!Failed) {
Parser->setTargetParser(*TAP.get());
Parser->setTargetParser(*TAP);
Failed = Parser->Run(Opts.NoInitialTextSection);
}

View File

@ -4390,7 +4390,7 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename,
CXXIdx->getPCHContainerOperations(), Diags,
CXXIdx->getClangResourcesPath(), CXXIdx->getStorePreamblesInMemory(),
CXXIdx->getPreambleStoragePath(), CXXIdx->getOnlyLocalDecls(),
CaptureDiagnostics, *RemappedFiles.get(),
CaptureDiagnostics, *RemappedFiles,
/*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses,
TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion,
/*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
@ -4981,8 +4981,7 @@ clang_reparseTranslationUnit_Impl(CXTranslationUnit TU,
RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
}
if (!CXXUnit->Reparse(CXXIdx->getPCHContainerOperations(),
*RemappedFiles.get()))
if (!CXXUnit->Reparse(CXXIdx->getPCHContainerOperations(), *RemappedFiles))
return CXError_Success;
if (isASTReadError(CXXUnit))
return CXError_ASTReadError;

View File

@ -339,7 +339,7 @@ testing::AssertionResult matchAndVerifyResultConditionally(
SmallString<256> Buffer;
std::unique_ptr<ASTUnit> AST(buildASTFromCodeWithArgs(
Code.toStringRef(Buffer), CompileArgs, Filename));
if (!AST.get())
if (!AST)
return testing::AssertionFailure()
<< "Parsing error in \"" << Code << "\" while building AST";
Finder.matchAST(AST->getASTContext());

View File

@ -40,8 +40,7 @@ public:
FileEntryRef addFile(StringRef Name) {
FEs.emplace_back(new FileEntry());
return FileEntryRef(
*Files.insert({Name, FileEntryRef::MapValue(*FEs.back().get(), DR)})
.first);
*Files.insert({Name, FileEntryRef::MapValue(*FEs.back(), DR)}).first);
}
FileEntryRef addFileAlias(StringRef Name, FileEntryRef Base) {
return FileEntryRef(