-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Miscompile when comparing function pointers #54696
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This emits an |
Looks like promotion is promoting the equality comparison, which then causes a const-eval error because the comparison is not actually valid in constants. Minified: fn main() {
&(main as fn() == main as fn());
} |
This is not as easy as I thought... we can probably easily rule out promoting comparing things of function type (though somehow my first attempt does not work), but when comparing arbitrary types that may contain a function, things get much harder. |
Fix submitted at #54702 |
We don't need to do anything special about aggregates, as their comparisons won't get promoted since they depend on trait impls and aren't builtin. |
Ah, great. I entirely forgot that this is pre-desugaring so we are seeing binary operators that will become method calls... |
do not promote comparing function pointers This *could* break existing code that relied on fn ptr comparison getting promoted to `'static` lifetime. Fixes rust-lang#54696
do not promote comparing function pointers This *could* break existing code that relied on fn ptr comparison getting promoted to `'static` lifetime. Fixes rust-lang#54696
From rustc 1.4.0 through 1.25.0, the following code compiles and prints
true
. This is the way I would expect it to work.On 1.26.0 and 1.27.0, compilation emits a warning and we get a segfault at runtime.
Segmentation fault (core dumped)
On 1.28.0 the code fails to compile.
On 1.29.0 through rustc 1.30.0-nightly (bb0896a 2018-09-29) the code compiles but is not correct.
Illegal instruction (core dumped)
Mentioning @oli-obk because your name is on this line so you may know what's up:
rust/src/librustc_mir/interpret/const_eval.rs
Line 377 in 1393176
The text was updated successfully, but these errors were encountered: