-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
In latest nightly observing a to-be returned variable changes its value. #84667
Copy link
Copy link
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Milestone
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Code
I have not been able to reproduce this with pure c code. I found this while working with cgo+rust, and managed to make a small-ish reproducible setup.
I tried this code:
lib.rs
toml file
positrs.h
c file
run
And you will see that this prints
00011110000111010100101001000110⏎This is (to me) clearly wrong since dividing a negative number with a positive number should be a negative number, and this is a positive number.
So I tried to print the variable in rust, see where it went wrong...
Uncomment the
printf!(...)line and run the following commandsand this luckely prints the exact same binary value....
oh.
somehow adding the print statement changes the return value of the function when exported to C.
The second one is correct, the first is not.
I also tried just observing x, without actually printing it, using the
ifstatement above theprint!and it had the same result as theprint!I expected to see this happen:
I expected the value to be the same no-matter what if the value is being observed, and this to be the correct value of
0b11100001111000101011010110111010Instead, this happened: explanation
Instead I got the wrong number after updating to the latest nightly.
Version it worked on
Currently I know for sure it works on
rustc 1.52.0-beta.6 (f97769a2b 2021-04-27)It also previously worked on nightly, but I dont think I can see the version history.
Version with regression
current broken nightly version:
rustc 1.53.0-nightly (42816d61e 2021-04-24)rustc --version --verbose:The compiler did not crash.