From 1553ea23165fc795b8c7e8188d2782c39c94b922 Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Sat, 4 Aug 2018 01:49:36 -0400 Subject: [PATCH 1/6] Changed `Rc::inc_{weak,strong}` to better hint optimization to LLVM --- src/liballoc/rc.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index be049eb6e5e..aec60bc18f9 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1359,7 +1359,14 @@ trait RcBoxPtr { #[inline] fn inc_strong(&self) { - self.inner().strong.set(self.strong().checked_add(1).unwrap_or_else(|| unsafe { abort() })); + // We want to abort on overflow instead of dropping the value. + // The reference count will never be zero when this is called; + // nevertheless, we insert an abort here to hint LLVM at + // an otherwise missied optimization. + if self.strong() == 0 || self.strong() == usize::max_value() { + unsafe { abort(); } + } + self.inner().strong.set(self.strong() + 1); } #[inline] @@ -1374,7 +1381,14 @@ trait RcBoxPtr { #[inline] fn inc_weak(&self) { - self.inner().weak.set(self.weak().checked_add(1).unwrap_or_else(|| unsafe { abort() })); + // We want to abort on overflow instead of dropping the value. + // The reference count will never be zero when this is called; + // nevertheless, we insert an abort here to hint LLVM at + // an otherwise missied optimization. + if self.weak() == 0 || self.weak() == usize::max_value() { + unsafe { abort(); } + } + self.inner().weak.set(self.weak() + 1); } #[inline] From 4e17fbde0b02b0b818b9a6c6fcf2d18eb02622d8 Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Sun, 5 Aug 2018 02:41:14 -0400 Subject: [PATCH 2/6] Fixed typo --- src/liballoc/rc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index aec60bc18f9..82e1c92359c 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1362,7 +1362,7 @@ trait RcBoxPtr { // We want to abort on overflow instead of dropping the value. // The reference count will never be zero when this is called; // nevertheless, we insert an abort here to hint LLVM at - // an otherwise missied optimization. + // an otherwise missed optimization. if self.strong() == 0 || self.strong() == usize::max_value() { unsafe { abort(); } } @@ -1384,7 +1384,7 @@ trait RcBoxPtr { // We want to abort on overflow instead of dropping the value. // The reference count will never be zero when this is called; // nevertheless, we insert an abort here to hint LLVM at - // an otherwise missied optimization. + // an otherwise missed optimization. if self.weak() == 0 || self.weak() == usize::max_value() { unsafe { abort(); } } From 85b92c1df1b8c1003ea6f6544b21b028e50881f7 Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Sun, 19 Aug 2018 06:07:04 -0400 Subject: [PATCH 3/6] Added test --- src/test/codegen/issue-53080.rs | 19 +++++++++++++++++++ src/tools/lld | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/test/codegen/issue-53080.rs diff --git a/src/test/codegen/issue-53080.rs b/src/test/codegen/issue-53080.rs new file mode 100644 index 00000000000..9289fb3b295 --- /dev/null +++ b/src/test/codegen/issue-53080.rs @@ -0,0 +1,19 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// A drop([...].clone()) sequence on an Rc should be a no-op +// In particular, no call to __rust_dealloc should be emitted +#![crate_type = "lib"] +use std::rc::Rc; + +pub fn foo(t: &Rc>) { +// CHECK-NOT: __rust_dealloc + drop(t.clone()); +} diff --git a/src/tools/lld b/src/tools/lld index 8214ccf861d..f76ea3ca16e 160000 --- a/src/tools/lld +++ b/src/tools/lld @@ -1 +1 @@ -Subproject commit 8214ccf861d538671b0a1436dbf4538dc4a64d09 +Subproject commit f76ea3ca16ed22dde8ef929db74a4b4df6f2f899 From 0b839146130e43c557425fc04537e7d0033cdc6b Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Mon, 20 Aug 2018 02:19:28 -0400 Subject: [PATCH 4/6] Renamed test to match actual issue number --- src/test/codegen/{issue-53080.rs => issue-13018.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/test/codegen/{issue-53080.rs => issue-13018.rs} (100%) diff --git a/src/test/codegen/issue-53080.rs b/src/test/codegen/issue-13018.rs similarity index 100% rename from src/test/codegen/issue-53080.rs rename to src/test/codegen/issue-13018.rs From 0dd10af5ade3b4c43407b43605038b180ab2290d Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Mon, 20 Aug 2018 07:45:11 -0400 Subject: [PATCH 5/6] Revert accidental submodule change --- src/tools/lld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/lld b/src/tools/lld index f76ea3ca16e..8214ccf861d 160000 --- a/src/tools/lld +++ b/src/tools/lld @@ -1 +1 @@ -Subproject commit f76ea3ca16ed22dde8ef929db74a4b4df6f2f899 +Subproject commit 8214ccf861d538671b0a1436dbf4538dc4a64d09 From 79a905ef305b1c3048ad2535887951721ab65f5c Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Mon, 20 Aug 2018 11:13:45 -0400 Subject: [PATCH 6/6] Added explicit optimization flag to test --- src/test/codegen/issue-13018.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/codegen/issue-13018.rs b/src/test/codegen/issue-13018.rs index 9289fb3b295..702b9545794 100644 --- a/src/test/codegen/issue-13018.rs +++ b/src/test/codegen/issue-13018.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: -O + // A drop([...].clone()) sequence on an Rc should be a no-op // In particular, no call to __rust_dealloc should be emitted #![crate_type = "lib"]