Skip to content

Function merging paradox #119160

Closed
Closed
@tmiasko

Description

@tmiasko
use std::hint::black_box;

static F: fn() -> bool = f as fn() -> bool;
static G: fn() -> bool = g as fn() -> bool;

pub fn f() -> bool {
    F == G
}

pub fn g() -> bool {
    F != G
}

fn main() {
    assert_ne!(
        black_box(f as fn() -> bool)(),
        black_box(g as fn() -> bool)(),
        "(F == G) != (F != G)",
    );
}
$ rustc a.rs -O && ./a
thread 'main' panicked at a.rs:15:5:
assertion `left != right` failed: (F == G) != (F != G)
  left: true
 right: true

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (f704f3b93 2023-12-19)
binary: rustc
commit-hash: f704f3b93b1543cf504ecca0052f9f8531b1f61f
commit-date: 2023-12-19
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.6

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions