This is an archive of the discontinued LLVM Phabricator instance.

Switch lto codegen to using diagnostic handlers
ClosedPublic

Authored by ygao on Nov 11 2015, 6:55 PM.

Details

Summary

With r252791, the C api will install a default diagnostic handler to print to sLastErrorString, therefore
we no longer need to pass around this sLastErrorString to any the LTOCodeGenerator methods.

This patch removes the std::string& argument from a number of C++ LTO API calls and instead
makes them use the installed diagnostic handler. This would also improve consistency of diagnostic
handling infrastructure: if an LTO client used lto_codegen_set_diagnostic_handler() to install a
custom error handler, we do not want some error messages to go through the custom error handler,
and some other error messages to go into sLastErrorString.

The part that I am not entirely sure about is what should happen when there is no installed
diagnostic handler at all. In this patch, the fall-back is to print the message to stderr. For this case
to happen, if the client is using the C api, the client must have explicitly called
lto_codegen_set_diagnostic_handler(nullptr), and maybe the intention is to not print any error at all?
I am not sure.

Diff Detail

Event Timeline

ygao updated this revision to Diff 40000.Nov 11 2015, 6:55 PM
ygao retitled this revision from to Switch lto codegen to using diagnostic handlers.
ygao updated this object.
ygao added subscribers: rafael, dexonsmith, pcc and 2 others.

Can you upload your patch with context please? (git diff -U9999, or using arc diff)

rafael accepted this revision.Nov 12 2015, 6:27 AM
rafael added a reviewer: rafael.

This is awesome.

Please just wait for a second opinion from someone at Apple.

This revision is now accepted and ready to land.Nov 12 2015, 6:27 AM
ygao updated this revision to Diff 40346.Nov 16 2015, 2:44 PM
ygao edited edge metadata.

Addressing Duncan's comment: when no custom diagnostic handler is installed, use the default
diagnostic handler, which is LLVMContext.diagnose().
Addressing Mehdi's comment. Uploading the patch with more context.
Rebased the patch to trunk r253253.

mehdi_amini accepted this revision.Nov 16 2015, 6:32 PM
mehdi_amini added a reviewer: mehdi_amini.

Thanks for the cleanup!

ygao closed this revision.Nov 17 2015, 11:51 AM

Thanks for reviewing. Closed by r253367.