[PATCH] D16864: ELF: Make Out<ELFT> initialization less error-prone.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 15:04:33 PST 2016


On 4 February 2016 at 17:59, Rui Ueyama <ruiu at google.com> wrote:
> ruiu added a comment.
>
> OK to commit?
>
>
> ================
> Comment at: ELF/Writer.cpp:120
> @@ +119,3 @@
> +
> +  std::unique_ptr<GnuHashTableSection<ELFT>> GnuHashTab;
> +  std::unique_ptr<GotPltSection<ELFT>> GotPlt;
> ----------------
> rafael wrote:
>> Why do these need to be std::uinque_ptr?
> Because we want to release the object at end of this function. (Does this answer to your question?)


What I meant was why use

std::unique_ptr<GnuHashTableSection<ELFT>> GnuHashTab;
...
 if (Config->GnuHash)
    GnuHashTab.reset(new GnuHashTableSection<ELFT>);
...
Out<ELFT>::GnuHashTab = GnuHashTab.get();

instead of

GnuHashTableSection<ELFT> GnuHashTab;
...
Out<ELFT>::GnuHashTab = Config->GnuHash ? &GnuHashTab : nullptr;

Making sure we always use a ? should solve the issue of Out not being reset.

Cheers,
Rafael


More information about the llvm-commits mailing list