diff options
author | Rui Ueyama <ruiu@google.com> | 2016-11-01 22:53:18 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2016-11-01 22:53:18 +0000 |
commit | d52adb3917397a70b2e0e3d98e719d1b4f263690 (patch) | |
tree | 0a50da8da348e5173be9c5b33586f82a0e1ede57 | |
parent | 05c03845e7655656ec0f4d3338b722db74120998 (diff) | |
download | bcm5719-llvm-d52adb3917397a70b2e0e3d98e719d1b4f263690.tar.gz bcm5719-llvm-d52adb3917397a70b2e0e3d98e719d1b4f263690.zip |
Provide a convenient function to allocate and initialize objects.
You can now write make<T>(Args) instead of new (alloc<T>()) T(Args).
llvm-svn: 285760
-rw-r--r-- | lld/ELF/Driver.cpp | 6 | ||||
-rw-r--r-- | lld/ELF/InputFiles.cpp | 19 | ||||
-rw-r--r-- | lld/ELF/Memory.h | 4 |
3 files changed, 13 insertions, 16 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 11710876c07..e2e515b29b3 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -131,7 +131,7 @@ void LinkerDriver::addFile(StringRef Path) { MemoryBufferRef MBRef = *Buffer; if (InBinary) { - Files.push_back(new (alloc<BinaryFile>()) BinaryFile(MBRef)); + Files.push_back(make<BinaryFile>(MBRef)); return; } @@ -145,7 +145,7 @@ void LinkerDriver::addFile(StringRef Path) { Files.push_back(createObjectFile(MB, Path)); return; } - Files.push_back(new (alloc<ArchiveFile>()) ArchiveFile(MBRef)); + Files.push_back(make<ArchiveFile>(MBRef)); return; case file_magic::elf_shared_object: if (Config->Relocatable) { @@ -156,7 +156,7 @@ void LinkerDriver::addFile(StringRef Path) { return; default: if (InLib) - Files.push_back(new (alloc<LazyObjectFile>()) LazyObjectFile(MBRef)); + Files.push_back(make<LazyObjectFile>(MBRef)); else Files.push_back(createObjectFile(MBRef)); } diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index ec8958b898d..6900f8f325d 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -407,8 +407,7 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec, // If -r is given, we do not interpret or apply relocation // but just copy relocation sections to output. if (Config->Relocatable) - return new (alloc<InputSection<ELFT>>()) - InputSection<ELFT>(this, &Sec, Name); + return make<InputSection<ELFT>>(this, &Sec, Name); // Find the relocation target section and associate this // section with it. @@ -450,13 +449,11 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec, // .eh_frame_hdr section for runtime. So we handle them with a special // class. For relocatable outputs, they are just passed through. if (Name == ".eh_frame" && !Config->Relocatable) - return new (alloc<EhInputSection<ELFT>>()) - EhInputSection<ELFT>(this, &Sec, Name); + return make<EhInputSection<ELFT>>(this, &Sec, Name); if (shouldMerge(Sec)) - return new (alloc<MergeInputSection<ELFT>>()) - MergeInputSection<ELFT>(this, &Sec, Name); - return new (alloc<InputSection<ELFT>>()) InputSection<ELFT>(this, &Sec, Name); + return make<MergeInputSection<ELFT>>(this, &Sec, Name); + return make<InputSection<ELFT>>(this, &Sec, Name); } template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() { @@ -825,13 +822,13 @@ static InputFile *createELFFile(MemoryBufferRef MB) { InputFile *Obj; if (Size == ELFCLASS32 && Endian == ELFDATA2LSB) - Obj = new (alloc<T<ELF32LE>>()) T<ELF32LE>(MB); + Obj = make<T<ELF32LE>>(MB); else if (Size == ELFCLASS32 && Endian == ELFDATA2MSB) - Obj = new (alloc<T<ELF32BE>>()) T<ELF32BE>(MB); + Obj = make<T<ELF32BE>>(MB); else if (Size == ELFCLASS64 && Endian == ELFDATA2LSB) - Obj = new (alloc<T<ELF64LE>>()) T<ELF64LE>(MB); + Obj = make<T<ELF64LE>>(MB); else if (Size == ELFCLASS64 && Endian == ELFDATA2MSB) - Obj = new (alloc<T<ELF64BE>>()) T<ELF64BE>(MB); + Obj = make<T<ELF64BE>>(MB); else fatal("invalid file class: " + MB.getBufferIdentifier()); diff --git a/lld/ELF/Memory.h b/lld/ELF/Memory.h index b7cf18be7d6..6ea6022992c 100644 --- a/lld/ELF/Memory.h +++ b/lld/ELF/Memory.h @@ -49,9 +49,9 @@ template <class T> struct SpecificAlloc : public SpecificAllocBase { // Use this arean if your object have a destructor. // Your destructor will be invoked from freeArena(). -template <class T> static T *alloc() { +template <typename T, typename... U> static T *make(U &&... Args) { static SpecificAlloc<T> Alloc; - return Alloc.Alloc.Allocate(); + return new (Alloc.Alloc.Allocate()) T(std::forward<U>(Args)...); } void freeArena(); |