From d5ec9af09da9f6d96b350ee53fffdad58721d32e Mon Sep 17 00:00:00 2001 From: Arthur Lafrance Date: Thu, 21 Sep 2023 20:42:21 -0700 Subject: [PATCH] Add test to guard against VecDeque optimization regression --- tests/codegen/vecdeque-nonempty-get-no-panic.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/codegen/vecdeque-nonempty-get-no-panic.rs diff --git a/tests/codegen/vecdeque-nonempty-get-no-panic.rs b/tests/codegen/vecdeque-nonempty-get-no-panic.rs new file mode 100644 index 0000000000000..c2877d2d0ca90 --- /dev/null +++ b/tests/codegen/vecdeque-nonempty-get-no-panic.rs @@ -0,0 +1,17 @@ +// Guards against regression for optimization discussed in issue #80836 + +// compile-flags: -O +// ignore-debug: the debug assertions get in the way + +#![crate_type = "lib"] + +use std::collections::VecDeque; + +// CHECK-LABEL: @front +// CHECK: ret void +#[no_mangle] +pub fn front(v: VecDeque) { + if !v.is_empty() { + v.get(0).unwrap(); + } +}