diff options
author | Reid Kleckner <rnk@google.com> | 2016-04-13 23:37:17 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-04-13 23:37:17 +0000 |
commit | 9305fd1f8617a92dd0157b6b068f899cd1688af3 (patch) | |
tree | dfd8b7568ae232351f9eed433300fb764b278e70 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | cae581d13fc75ed22b83b0684d6a0a874f1929d5 (diff) | |
download | llvm-9305fd1f8617a92dd0157b6b068f899cd1688af3.zip llvm-9305fd1f8617a92dd0157b6b068f899cd1688af3.tar.gz llvm-9305fd1f8617a92dd0157b6b068f899cd1688af3.tar.bz2 |
[CodeGen] Avoid ctor/dtor boilerplate with some C++11
Non-owning pointers that cache LLVM types and constants can use
'nullptr' default member initializers so that we don't need to mention
them in the constructor initializer list.
Owning pointers should use std::unique_ptr so that we don't need to
manually delete them in the destructor. They also don't need to be
mentioned in the constructor at that point.
NFC
llvm-svn: 266263
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e4ae5bb..64fe365 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -87,17 +87,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO, : Context(C), LangOpts(C.getLangOpts()), HeaderSearchOpts(HSO), PreprocessorOpts(PPO), CodeGenOpts(CGO), TheModule(M), Diags(diags), Target(C.getTargetInfo()), ABI(createCXXABI(*this)), - VMContext(M.getContext()), TBAA(nullptr), TheTargetCodeGenInfo(nullptr), - Types(*this), VTables(*this), ObjCRuntime(nullptr), - OpenCLRuntime(nullptr), OpenMPRuntime(nullptr), CUDARuntime(nullptr), - DebugInfo(nullptr), ObjCData(nullptr), - NoObjCARCExceptionsMetadata(nullptr), PGOReader(nullptr), - CFConstantStringClassRef(nullptr), ConstantStringClassRef(nullptr), - NSConstantStringType(nullptr), NSConcreteGlobalBlock(nullptr), - NSConcreteStackBlock(nullptr), BlockObjectAssign(nullptr), - BlockObjectDispose(nullptr), BlockDescriptorType(nullptr), - GenericBlockLiteralType(nullptr), LifetimeStartFn(nullptr), - LifetimeEndFn(nullptr), SanitizerMD(new SanitizerMetadata(*this)), + VMContext(M.getContext()), Types(*this), VTables(*this), + SanitizerMD(new SanitizerMetadata(*this)), WholeProgramVTablesBlacklist(CGO.WholeProgramVTablesBlacklistFiles, C.getSourceManager()) { @@ -135,19 +126,19 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO, // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0. if (LangOpts.Sanitize.has(SanitizerKind::Thread) || (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)) - TBAA = new CodeGenTBAA(Context, VMContext, CodeGenOpts, getLangOpts(), - getCXXABI().getMangleContext()); + TBAA.reset(new CodeGenTBAA(Context, VMContext, CodeGenOpts, getLangOpts(), + getCXXABI().getMangleContext())); // If debug info or coverage generation is enabled, create the CGDebugInfo // object. if (CodeGenOpts.getDebugInfo() != codegenoptions::NoDebugInfo || CodeGenOpts.EmitGcovArcs || CodeGenOpts.EmitGcovNotes) - DebugInfo = new CGDebugInfo(*this); + DebugInfo.reset(new CGDebugInfo(*this)); Block.GlobalUniqueCount = 0; if (C.getLangOpts().ObjC1) - ObjCData = new ObjCEntrypoints(); + ObjCData.reset(new ObjCEntrypoints()); if (CodeGenOpts.hasProfileClangUse()) { auto ReaderOrErr = llvm::IndexedInstrProfReader::create( @@ -167,16 +158,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO, CoverageMapping.reset(new CoverageMappingModuleGen(*this, *CoverageInfo)); } -CodeGenModule::~CodeGenModule() { - delete ObjCRuntime; - delete OpenCLRuntime; - delete OpenMPRuntime; - delete CUDARuntime; - delete TheTargetCodeGenInfo; - delete TBAA; - delete DebugInfo; - delete ObjCData; -} +CodeGenModule::~CodeGenModule() {} void CodeGenModule::createObjCRuntime() { // This is just isGNUFamily(), but we want to force implementors of @@ -185,21 +167,21 @@ void CodeGenModule::createObjCRuntime() { case ObjCRuntime::GNUstep: case ObjCRuntime::GCC: case ObjCRuntime::ObjFW: - ObjCRuntime = CreateGNUObjCRuntime(*this); + ObjCRuntime.reset(CreateGNUObjCRuntime(*this)); return; case ObjCRuntime::FragileMacOSX: case ObjCRuntime::MacOSX: case ObjCRuntime::iOS: case ObjCRuntime::WatchOS: - ObjCRuntime = CreateMacObjCRuntime(*this); + ObjCRuntime.reset(CreateMacObjCRuntime(*this)); return; } llvm_unreachable("bad runtime kind"); } void CodeGenModule::createOpenCLRuntime() { - OpenCLRuntime = new CGOpenCLRuntime(*this); + OpenCLRuntime.reset(new CGOpenCLRuntime(*this)); } void CodeGenModule::createOpenMPRuntime() { @@ -211,16 +193,16 @@ void CodeGenModule::createOpenMPRuntime() { case llvm::Triple::nvptx64: assert(getLangOpts().OpenMPIsDevice && "OpenMP NVPTX is only prepared to deal with device code."); - OpenMPRuntime = new CGOpenMPRuntimeNVPTX(*this); + OpenMPRuntime.reset(new CGOpenMPRuntimeNVPTX(*this)); break; default: - OpenMPRuntime = new CGOpenMPRuntime(*this); + OpenMPRuntime.reset(new CGOpenMPRuntime(*this)); break; } } void CodeGenModule::createCUDARuntime() { - CUDARuntime = CreateNVCUDARuntime(*this); + CUDARuntime.reset(CreateNVCUDARuntime(*this)); } void CodeGenModule::addReplacement(StringRef Name, llvm::Constant *C) { |