about summary refs log tree commit diff
path: root/tests/codegen-llvm/asm/readonly-not-pure.rs
blob: a3c0e276c7f5e7edd93fbd567cba94a484a9cd75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//@ add-core-stubs
//@ compile-flags: -Copt-level=3 --target x86_64-unknown-linux-gnu
//@ needs-llvm-components: x86

#![crate_type = "rlib"]
#![feature(no_core)]
#![no_core]

// Test that when an inline assembly block specifies `readonly` but not `pure`, a detailed
// `MemoryEffects` is provided to LLVM: this assembly block is not allowed to perform writes,
// but it may have side-effects.

extern crate minicore;
use minicore::*;

pub static mut VAR: i32 = 0;

// CHECK-LABEL: @no_options
// CHECK: call i32 asm
#[no_mangle]
pub unsafe fn no_options() -> i32 {
    VAR = 1;
    let _ignored: i32;
    asm!("mov {0}, 1", out(reg) _ignored);
    VAR
}

// CHECK-LABEL: @readonly_pure
// CHECK-NOT: call i32 asm
#[no_mangle]
pub unsafe fn readonly_pure() -> i32 {
    VAR = 1;
    let _ignored: i32;
    asm!("mov {0}, 1", out(reg) _ignored, options(pure, readonly));
    VAR
}

// CHECK-LABEL: @readonly_not_pure
// CHECK: call i32 asm {{.*}} #[[ATTR:[0-9]+]]
#[no_mangle]
pub unsafe fn readonly_not_pure() -> i32 {
    VAR = 1;
    let _ignored: i32;
    asm!("mov {0}, 1", out(reg) _ignored, options(readonly));
    VAR
}

// CHECK: attributes #[[ATTR]] = { nounwind memory(read, inaccessiblemem: readwrite) }