Skip to content

Commit 93465e6

Browse files
committed
Mark condition/carry bit as clobbered in C-SKY inline assembly
1 parent fdd1a3b commit 93465e6

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
286286
InlineAsmArch::M68k => {
287287
constraints.push("~{ccr}".to_string());
288288
}
289-
InlineAsmArch::CSKY => {}
289+
InlineAsmArch::CSKY => {
290+
constraints.push("~{psr}".to_string());
291+
}
290292
}
291293
}
292294
if !options.contains(InlineAsmOptions::NOMEM) {

src/doc/unstable-book/src/language-features/asm-experimental-arch.md

+2
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,5 @@ These flags registers must be restored upon exiting the asm block if the `preser
199199
- SPARC
200200
- Integer condition codes (`icc` and `xcc`)
201201
- Floating-point condition codes (`fcc[0-3]`)
202+
- CSKY
203+
- Condition/carry bit (C) in `PSR`.

tests/codegen/asm/csky-clobbers.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --target csky-unknown-linux-gnuabiv2
3+
//@ needs-llvm-components: csky
4+
5+
#![crate_type = "rlib"]
6+
#![feature(no_core, asm_experimental_arch)]
7+
#![no_core]
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
// CHECK-LABEL: @flags_clobber
13+
// CHECK: call void asm sideeffect "", "~{psr}"()
14+
#[no_mangle]
15+
pub unsafe fn flags_clobber() {
16+
asm!("", options(nostack, nomem));
17+
}
18+
19+
// CHECK-LABEL: @no_clobber
20+
// CHECK: call void asm sideeffect "", ""()
21+
#[no_mangle]
22+
pub unsafe fn no_clobber() {
23+
asm!("", options(nostack, nomem, preserves_flags));
24+
}

0 commit comments

Comments
 (0)