Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logging] Mark LogFatal::~LogFatal as [[noreturn]] #13542

Merged
merged 1 commit into from
Dec 4, 2022

Conversation

Lunderberg
Copy link
Contributor

Using LOG(FATAL) << "some error message"; throws an exception when the internal LogFatal object is constructed. However, the gcc warning "control reaches end of non-void function" resulted in a common pattern where a LOG(FATAL) statement was immediately followed by return of a default value, in order to suppress the warning.

This commit marks the LogFatal::~LogFatal destructor with the C++11 attribute [[noreturn]], indicating that calls into it will not resume the normal control flow. This suppresses the warning without requiring the extra return statement after LOG(FATAL), as the compiler knows that control flow will not resume after LOG(FATAL).

Using `LOG(FATAL) << "some error message";` throws an exception when
the internal `LogFatal` object is constructed.  However, the gcc warning
"control reaches end of non-void function" resulted in a common
pattern where a `LOG(FATAL)` statement was immediately followed by
return of a default value, in order to suppress the warning.

This commit marks the `LogFatal::~LogFatal` destructor with the C++11
attribute `[[noreturn]]`, indicating that calls into it will not
resume the normal control flow.  This suppresses the warning without
requiring the extra `return` statement after `LOG(FATAL)`, as the
compiler knows that control flow will not resume after `LOG(FATAL)`.
@tvm-bot
Copy link
Collaborator

tvm-bot commented Dec 2, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: logging, [noreturn See #10317 for details
  • Built docs for commit 11805dc can be found here.

Generated by tvm-bot

@Lunderberg
Copy link
Contributor Author

After conversation with @kparzysz-quic , it looks like whether [[noreturn]] was previously applied. #11310 also added [[noreturn]], but only when the TVM_LOG_CUSTOMIZE macro is defined. This PR applies [[noreturn]] to the other branch as well.

Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It can be beneficial to the dev experience.

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! That helps a lot!

@junrushao junrushao merged commit 7bc41ec into apache:main Dec 4, 2022
@Lunderberg Lunderberg deleted the log_fatal_noreturn branch December 5, 2022 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants