-
Notifications
You must be signed in to change notification settings - Fork 396
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
gtest: Do not reference temporaries past the expression that created them #4540
Conversation
This is an error in gtest, not in OMR. This same error is repeated in a few places, causing different types of bad behaviour on AIX, including breaking almost all logging and option processing. Rather than bind a const mytype& to a temporary result, copy the result into a local, which ensures it is safe to access the value later in the program. When a reference is bound to a temporary value, that reference is invalid when the value dies, at the end of the "full expression" that created it. Using this reference to a temporary in a later expression results in a kind of "use after destruction" error. Fixes: eclipse-omr#4537 Signed-off-by: Robert Young <rwy0717@gmail.com>
Is this a change that can or should be contributed back to gtest directly? |
It should be, I'm in the middle of going through the google CLA right now. I figure it will be at least a few days, though EDIT: Nevermind, already done 💃 ! |
Side note: I think this is actually an AIX compiler bug. My understanding is that this pattern should be fine due to lifetime extension
(emphasis mine) That fact that it -only- blows up on AIX is another argument in favour of that. |
Yes, I actually I meant to update this issue, I am beginning to suspect compiler bug as well. When I first started looking at this bug, I wasn't aware of the lifetime extension rule :). However, I have checked, and the rule is correctly applied by AIX in simple cases. I need to spend more time looking at the crash. As you said, the pattern of code should be valid. |
@genie-omr build aix |
1 similar comment
@genie-omr build aix |
This is a compiler bug in XLC 12.1, possibly older versions as well. The problem is not present in XLC 13.1, which we are using in OMR CI. The problematic code was introduced with gtest 1.8 all the way back in 2017. The two problem lines were:
I've tried to update every line that binds a reference to a temporary, just just to make sure there are no problems we don't know about yet. In this case, I'm willing to make a code change because it is such a minor patch, in tests only, for a toolchain we officially support. Since this is a bug in XLC, I'm not going to be contributing these changes upstream to gtest. Before we upgrade gtest again, we should look at finally dropping support for XLC 12.1. Without this patch, the gtest output looks like this:
Since this PR is just hacking around a toolchain bug, I can understand why someone wouldn't want this contributed, so if anyone opposes this PR, please comment or just thumbs down the issue. |
@genie-omr build all |
Travis testing has passed, although github's UI is not reflecting this (for me). Merging! |
This is an error in gtest, not in OMR.
This same error is repeated in a few places, causing different types of
bad behaviour on AIX, including breaking almost all logging and option
processing.
Rather than bind a const mytype& to a temporary result, copy the result
into a local, which ensures it is safe to access the value later in the
program.
When a reference is bound to a temporary value, that reference is
invalid when the value dies, at the end of the "full expression" that
created it. Using this reference to a temporary in a later expression
results in a kind of "use after destruction" error.
Fixes: #4537
Signed-off-by: Robert Young rwy0717@gmail.com