about summary refs log tree commit diff
path: root/src/test/codegen/function-arguments.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-27 10:21:11 +0000
committerbors <bors@rust-lang.org>2015-05-27 10:21:11 +0000
commitf56782ab9c8d0f64b9a714cc24d925a81ac3211b (patch)
tree4a37d4c5cb459873a50f61325b9f135c40c9932d /src/test/codegen/function-arguments.rs
parenteb16ad6e71172eabb71acb73758675f25df91649 (diff)
parent677367599e8383c355b8e8261cafe3ce44c9c6de (diff)
downloadrust-f56782ab9c8d0f64b9a714cc24d925a81ac3211b.tar.gz
rust-f56782ab9c8d0f64b9a714cc24d925a81ac3211b.zip
Auto merge of #25762 - dotdash:codegen_test, r=alexcrichton
The current codegen tests only compare IR line counts between similar
rust and C programs, the latter getting compiled with clang. That looked
like a good idea back then, but actually things like lifetime intrinsics
mean that less IR isn't always better, so the metric isn't really
helpful.

Instead, we can start doing tests that check specific aspects of the
generated IR, like attributes or metadata. To do that, we can use LLVM's
FileCheck tool which has a number of useful features for such tests.

To start off, I created some tests for a few things that were recently
added and/or broken.
Diffstat (limited to 'src/test/codegen/function-arguments.rs')
-rw-r--r--src/test/codegen/function-arguments.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs
new file mode 100644
index 00000000000..f11e769ca6c
--- /dev/null
+++ b/src/test/codegen/function-arguments.rs
@@ -0,0 +1,95 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -C no-prepopulate-passes
+
+#![feature(allocator)]
+
+pub struct S {
+  _field: [i64; 4],
+}
+
+pub struct UnsafeInner {
+  _field: std::cell::UnsafeCell<i16>,
+}
+
+// CHECK: zeroext i1 @boolean(i1 zeroext)
+#[no_mangle]
+pub fn boolean(x: bool) -> bool {
+  x
+}
+
+// CHECK: @readonly_borrow(i32* noalias readonly dereferenceable(4))
+// FIXME #25759 This should also have `nocapture`
+#[no_mangle]
+pub fn readonly_borrow(_: &i32) {
+}
+
+// CHECK: @static_borrow(i32* noalias readonly dereferenceable(4))
+// static borrow may be captured
+#[no_mangle]
+pub fn static_borrow(_: &'static i32) {
+}
+
+// CHECK: @named_borrow(i32* noalias readonly dereferenceable(4))
+// borrow with named lifetime may be captured
+#[no_mangle]
+pub fn named_borrow<'r>(_: &'r i32) {
+}
+
+// CHECK: @unsafe_borrow(%UnsafeInner* dereferenceable(2))
+// unsafe interior means this isn't actually readonly and there may be aliases ...
+#[no_mangle]
+pub fn unsafe_borrow(_: &UnsafeInner) {
+}
+
+// CHECK: @mutable_unsafe_borrow(%UnsafeInner* noalias dereferenceable(2))
+// ... unless this is a mutable borrow, those never alias
+#[no_mangle]
+pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
+}
+
+// CHECK: @mutable_borrow(i32* noalias dereferenceable(4))
+// FIXME #25759 This should also have `nocapture`
+#[no_mangle]
+pub fn mutable_borrow(_: &mut i32) {
+}
+
+// CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32))
+#[no_mangle]
+pub fn indirect_struct(_: S) {
+}
+
+// CHECK: @borrowed_struct(%S* noalias readonly dereferenceable(32))
+// FIXME #25759 This should also have `nocapture`
+#[no_mangle]
+pub fn borrowed_struct(_: &S) {
+}
+
+// CHECK: noalias dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4))
+#[no_mangle]
+pub fn _box(x: Box<i32>) -> Box<i32> {
+  x
+}
+
+// CHECK: @struct_return(%S* noalias nocapture sret dereferenceable(32))
+#[no_mangle]
+pub fn struct_return() -> S {
+  S {
+    _field: [0, 0, 0, 0]
+  }
+}
+
+// CHECK: noalias i8* @allocator()
+#[no_mangle]
+#[allocator]
+pub fn allocator() -> *const i8 {
+  std::ptr::null()
+}