This is an archive of the discontinued LLVM Phabricator instance.

[clang] Check AuxTarget exists when creating target in CompilerInstance.
ClosedPublic

Authored by oToToT on Apr 7 2021, 12:52 AM.

Details

Summary

D97493 separate target creation out to a single function CompilerInstance::createTarget. However, it would overwrite AuxTarget even if it has been set.
As @kadircet recommended in D98128, this patch check the existence of AuxTarget and not overwrite it when it has been set.

Diff Detail

Event Timeline

oToToT requested review of this revision.Apr 7 2021, 12:52 AM
oToToT created this revision.
kadircet accepted this revision.Apr 7 2021, 3:40 AM

thanks, lgtm!

clang/lib/Frontend/CompilerInstance.cpp
109

can we just do !getAuxTarget() and not introduce hasAuxTarget() ? i don't think the new api in the interface provides much value.

This revision is now accepted and ready to land.Apr 7 2021, 3:40 AM
oToToT added inline comments.Apr 7 2021, 3:53 AM
clang/lib/Frontend/CompilerInstance.cpp
109

After some thinking, I’m wondering might it be more flexible if we add an option to let the user determine whether overwrite AuxTarget by themselves?

Like changing the prototype to
bool CompilerInstance::createTarget(bool OverwriteAuxTarget = true);
and simply check if (OverwriteAuxTarget && ... here.

kadircet added inline comments.Apr 7 2021, 4:11 AM
clang/lib/Frontend/CompilerInstance.cpp
109

i think it is better to let the clients clear the target before hand via setAuxTarget(nullptr) (or not set it at all), then confuse them with (defaulted) extra options when calling some function.

oToToT updated this revision to Diff 335778.Apr 7 2021, 4:28 AM

Simply use !getAuxTarget() to check the existence of AuxTarget.

oToToT marked 2 inline comments as done.Apr 7 2021, 4:28 AM