-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8332632: Redundant assert "compiler should always document failure: %s" with possible UB #19395
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
Conversation
👋 Welcome back eastigeevich! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@eastig Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
…s" with possible UB
@eastig Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is typo. This code wants to check and print in these asserts task->_failure_reason
which should be set when !task->is_success()
.
We do miss public accessors to CompileTask::_failure_reason
which have to be added.
And may be we should pass the failure to ciEnv too in this code instead of "compile failed".
@eastig This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@eastig This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
JDK-8303951 added the following code: https://github.com/openjdk/jdk/pull/13038/files#diff-2e74481e557cbe87170a56a6e592eea33bb59019926e1c32bebcfaf5b571bb53R2280
The second assert is redundant because
ci_env.failure_reason() != nullptr
is alwaysfalse
. It also has possible UB.A compiler sees if-statement checking
!ci_env.failing()
which, if it is true, impliesci_env.failure_reason()
isnullptr
.Based on this information the compiler can optimize
assert(ci_env.failure_reason() != nullptr, "expect failure reason");
toassert(false, "expect failure reason");
.The compiler can optimize
assert(false, "compiler should always document failure: %s", ci_env.failure_reason());
toassert(false, "compiler should always document failure: %s", nullptr);
.So the original code would be like the following:
We have an expression where a format string is used. Format strings usually have undefined behavior if
nullptr
is passed for the character string format specifier. Seestd::printf
for example.Even the second assert is never executed, it makes the IF-block to have UB. The C++ standard says: correct C++ programs are free of undefined behavior. See https://en.cppreference.com/w/cpp/language/ub and https://en.cppreference.com/w/cpp/language/as_if
Choosing between readability and correctness, I choose correctness.
I think the one assert
assert(ci_env.failure_reason() != nullptr, "compiler should always document failure");
meets being self-documented and correct.Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19395/head:pull/19395
$ git checkout pull/19395
Update a local copy of the PR:
$ git checkout pull/19395
$ git pull https://git.openjdk.org/jdk.git pull/19395/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19395
View PR using the GUI difftool:
$ git pr show -t 19395
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19395.diff
Webrev
Link to Webrev Comment