rust-lang / rust-lang/rust

Iterating all `char`s blocks dead code elimination

Open
#124,349 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM C-optimization I-slow
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This following code does nothing, however does not get optimized away.

pub fn dead_code_elim_failure() {
    for _ in '\0'..'\u{10ffff}' {}
}
example::dead_code_elim_failure::h8fb80fbacc62758b:
        xor     ecx, ecx
        mov     eax, 57344
.LBB0_1:
        cmp     ecx, 55295
        lea     edx, [rcx + 1]
        cmove   edx, eax
        mov     ecx, edx
        cmp     edx, 1114111
        jb      .LBB0_1
        ret
Meta

Tested on:

rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6
rustc 1.79.0-nightly (dbce3b43b 2024-04-20)
binary: rustc
commit-hash: dbce3b43b6cb34dd3ba12c3ec6f708fe68e9c3df
commit-date: 2024-04-20
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the reported Rust reproducer with optimization enabled and compare the generated assembly against the issue. Trace the compiler optimization path responsible for the loop and verify that the empty iteration is eliminated without changing observable behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.