From 7e5c7cf8e32d43b1c7fca06effbc7739634c31a0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 19 Jul 2020 20:57:49 +0200 Subject: Emit == null instead of <= null When the niche maximum is zero, emit a "== zero" check instead of a "<= zero" check. In particular, this avoid the awkward case of "<= null". While LLVM does canonicalize this to "!= null", this appently doesn't happen for constant expressions, leading to the issue in #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 #74425. --- src/test/codegen/some-global-nonnull.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/codegen/some-global-nonnull.rs (limited to 'src/test/codegen') diff --git a/src/test/codegen/some-global-nonnull.rs b/src/test/codegen/some-global-nonnull.rs new file mode 100644 index 00000000000..59c47de4129 --- /dev/null +++ b/src/test/codegen/some-global-nonnull.rs @@ -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) { + if let Some(f) = f_maybe { + f(); + } +} + +fn inner0() { + unsafe { ext_fn0() }; +} + +extern "C" { + fn ext_fn0(); +} -- cgit 1.4.1-3-g733a5