This is an archive of the discontinued LLVM Phabricator instance.

[mlir][NFC] Do not convert bool to int when returning from main
AbandonedPublic

Authored by kuhar on May 16 2022, 9:21 AM.

Details

Summary

Instead, use the asMainReturnCode utility function that uses EXIT_SUCCESS and EXIT_FAILURE.

Move asMainReturnCode to LogicalResult.h so that non-opt-based mlir tools can also use it.

Diff Detail

Event Timeline

kuhar created this revision.May 16 2022, 9:21 AM
Herald added a project: Restricted Project. · View Herald Transcript
kuhar requested review of this revision.May 16 2022, 9:21 AM

Can you clarify the motivation for this?

Can you clarify the motivation for this?

My motivation is twofold:

  1. The canonical return codes may not be 0 and 1 on some operating systems. While 0 is guaranteed to be a success value in C++, the value for unsuccessful termination (EXIT_FAILURE) is implementation-defined. I found some references about OpenVMS using different exit code values, but I'm not confident about that, nor I know if returning 1 can cause issues on platforms that LLVM actually supports.
  1. This is my stylistic preference. succeeded/failed/asMainReturnCode are one of the first functions that appear in MLIR examples and I was surprised this was not used uniformly. IMO, using asMainReturnCode is much more readable/direct than relying on failed and bool-to-int conversions.
kuhar abandoned this revision.Jun 4 2022, 7:31 PM