This is an archive of the discontinued LLVM Phabricator instance.

Define InitLLVM to do common initialization all at once.
ClosedPublic

Authored by ruiu on Apr 12 2018, 4:34 PM.

Details

Summary

We have a few functions that virtually all command wants to run on
process startup/shutdown. This patch adds InitLLVM class to do them
all at once, so that we don't copy-n-paste boilerplate code to main()
function of each llvm utility command.

Event Timeline

ruiu created this revision.Apr 12 2018, 4:34 PM

There are several other tools that have similar initialization (but don't use GetArgumentVector). They should be updated also - and that will also fix their issue with UTF-8 on Windows.

llvm/tools/llvm-rc/llvm-rc.cpp
81

By doing this in this file, ExitOnErr (which is used later in the main function) no longer has the banner set. I suspect the same may be true in some of the other files too.

Perhaps InitLLVM could return an ExitOnError object which is already initialized with the correct banner?

ruiu updated this revision to Diff 142302.Apr 12 2018, 5:39 PM
  • set banners to ExitOnError objects
llvm/tools/llvm-rc/llvm-rc.cpp
81

Looks like ExitOnError can take a banner as its constructor argument.

ruiu updated this revision to Diff 142318.Apr 12 2018, 7:46 PM
  • convert more tools to use InitLLVM
llvm/tools/llvm-ar/llvm-ar.cpp
957 ↗(On Diff #142318)

Why not use ToolName? Or remove ToolName?

llvm/tools/llvm-rc/llvm-rc.cpp
81

I noticed that several of the files that you changed set the banner of ExitOnError after InitLLVM to argv[0] (which is also what InitLLVM does), while a couple set just the name of the tool. Could you change the ones that set just the name of the tool to also use argv[0] for consistency?

ruiu added inline comments.Apr 12 2018, 8:05 PM
llvm/tools/llvm-ar/llvm-ar.cpp
957 ↗(On Diff #142318)

No particular reason. Reverted.

llvm/tools/llvm-rc/llvm-rc.cpp
81

I don't want to do that at least in this patch as I want to keep this change as mechanical as possible.

ruiu updated this revision to Diff 142320.Apr 12 2018, 8:05 PM
  • address review comment
ruiu updated this revision to Diff 142322.Apr 12 2018, 8:12 PM
  • fix unsafe memory access issue
stella.stamenova accepted this revision.Apr 12 2018, 8:40 PM

The last comment would be nice to have, but not necessary. LGTM.

llvm/tools/llvm-rc/llvm-rc.cpp
81

Then in llvm-pdbutil.cpp and here, you should undo the change to the declaration of ExitOnError and bring back the setBanner statements in the main() functions.

This revision is now accepted and ready to land.Apr 12 2018, 8:40 PM
This revision was automatically updated to reflect the committed changes.