forked from rust-lang/rust
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#74533 - nikic:issue-74425, r=eddyb
Emit == null instead of <= null for niche check When the niche maximum is zero, emit a "== zero" check instead of a "<= zero" check. In particular, this avoids the awkward case of "<= null". While LLVM does canonicalize this to "== null", this apparently doesn't happen for constant expressions, leading to the issue in rust-lang#74425. While that can be addressed on the LLVM side, it still seems prudent to emit sensible IR here, because this will allow null checks to be optimized earlier in the pipeline. Fixes rust-lang#74425.
- Loading branch information
Showing
2 changed files
with
32 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
// CHECK-LABEL: @test | ||
// CHECK-NEXT: start: | ||
// CHECK-NEXT: tail call void @ext_fn0() | ||
#[no_mangle] | ||
pub fn test() { | ||
test_inner(Some(inner0)); | ||
} | ||
|
||
fn test_inner(f_maybe: Option<fn()>) { | ||
if let Some(f) = f_maybe { | ||
f(); | ||
} | ||
} | ||
|
||
fn inner0() { | ||
unsafe { ext_fn0() }; | ||
} | ||
|
||
extern "C" { | ||
fn ext_fn0(); | ||
} |