This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Fix error reporting when a file passed to libLTO is invalid or non-existent
ClosedPublic

Authored by petpav01 on Jan 12 2016, 1:50 AM.

Details

Summary

This patch addresses bug https://llvm.org/bugs/show_bug.cgi?id=26060 where lto_module_create() could return nullptr but lto_get_error_message() returned an empty string. Unfortunately, I could not find any place where lto_module_*() functions would be tested so I am not sure where to add a test for this problem.

Note that this patch would also fix the same problem that commit r257395 fixed yesterday in llvm-lto because the diagnostic handler in llvm-lto exits the program on error.

Diff Detail

Event Timeline

petpav01 updated this revision to Diff 44611.Jan 12 2016, 1:50 AM
petpav01 retitled this revision from to [LTO] Fix error reporting when a file passed to libLTO is invalid or non-existent.
petpav01 updated this object.
petpav01 added a reviewer: rafael.
petpav01 added a subscriber: llvm-commits.
rafael edited edge metadata.Jan 14 2016, 8:53 AM

To test this you should be able to delete the call to error in

ErrorOr<std::unique_ptr<LTOModule>> ModuleOrErr =
     LTOModule::createFromFile(Context, InputFilenames[i].c_str(), Options);
 error(ModuleOrErr, "error " + CurrentActivity);

in llvm-lto.cpp since now the error will be received via the diagnostic handler.

tools/lto/lto.cpp
84

Is this related?

Thank you for looking at this patch. I will update the patch to delete the error() call after LTOModule::createFromFile() from llvm-lto.

tools/lto/lto.cpp
84

It is related because before r254721 function lto_get_error_message() would return "The file was not recognized as a valid object file" after calling lto_module_create() on an empty file. If only the emitError() calls are added then the returned error is "The file was not recognized as a valid object file\n" (i.e. it includes the newline character). This is problematic if someone had printf("LTO error: %s\n", lto_get_error_message()); in their code as it will now print an empty line after the error.

petpav01 updated this revision to Diff 44967.Jan 15 2016, 1:39 AM
petpav01 edited edge metadata.

Updated patch deletes the error() call after LTOModule::createFromFile() from llvm-lto because any error from this function should go through the diagnostic handler in llvm-lto which will exit the program.

rafael accepted this revision.Jan 19 2016, 11:10 AM
rafael edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jan 19 2016, 11:10 AM
This revision was automatically updated to reflect the committed changes.