Skip to content

Commit

Permalink
add codegen test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Jan 17, 2024
1 parent d0dfd3c commit 63ce0c8
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/codegen/vecdeque-drain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Check that draining at the front or back doesn't copy memory.

// compile-flags: -O
// ignore-debug: the debug assertions get in the way

#![crate_type = "lib"]

use std::collections::VecDeque;

// CHECK-LABEL: @clear
// CHECK-NOT: call
// CHECK-NOT: br
// CHECK: getelementptr inbounds
// CHECK-NEXT: call void @llvm.memset
// CHECK-NEXT: ret void
#[no_mangle]
pub fn clear(v: &mut VecDeque<i32>) {
v.drain(..);
}

// CHECK-LABEL: @truncate
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK-NOT: br
// CHECK: ret void
#[no_mangle]
pub fn truncate(v: &mut VecDeque<i32>, n: usize) {
if n < v.len() {
v.drain(n..);
}
}

// CHECK-LABEL: @advance
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK: br
// CHECK-NOT: call
// CHECK-NOT: br
// CHECK: ret void
#[no_mangle]
pub fn advance(v: &mut VecDeque<i32>, n: usize) {
if n < v.len() {
v.drain(..n);
} else {
v.clear();
}
}

// CHECK-LABEL: @remove
// CHECK: call
#[no_mangle]
pub fn remove(v: &mut VecDeque<i32>, a: usize, b: usize) {
v.drain(a..b);
}

0 comments on commit 63ce0c8

Please sign in to comment.