about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTaiki Endo <te316e89@gmail.com>2025-01-29 06:46:05 +0900
committerTaiki Endo <te316e89@gmail.com>2025-01-29 06:46:05 +0900
commit93465e6c3106043b8db7089ff7a1a4d610d8f79f (patch)
tree2da40315bd0435474c19cda59a127ad5edc81c79
parentfdd1a3b02687817cea41f6bacae3d5fbed2b2cd0 (diff)
downloadrust-93465e6c3106043b8db7089ff7a1a4d610d8f79f.tar.gz
rust-93465e6c3106043b8db7089ff7a1a4d610d8f79f.zip
Mark condition/carry bit as clobbered in C-SKY inline assembly
-rw-r--r--compiler/rustc_codegen_llvm/src/asm.rs4
-rw-r--r--src/doc/unstable-book/src/language-features/asm-experimental-arch.md2
-rw-r--r--tests/codegen/asm/csky-clobbers.rs24
3 files changed, 29 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs
index 3722d4350a2..be5673eddf9 100644
--- a/compiler/rustc_codegen_llvm/src/asm.rs
+++ b/compiler/rustc_codegen_llvm/src/asm.rs
@@ -286,7 +286,9 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
                 InlineAsmArch::M68k => {
                     constraints.push("~{ccr}".to_string());
                 }
-                InlineAsmArch::CSKY => {}
+                InlineAsmArch::CSKY => {
+                    constraints.push("~{psr}".to_string());
+                }
             }
         }
         if !options.contains(InlineAsmOptions::NOMEM) {
diff --git a/src/doc/unstable-book/src/language-features/asm-experimental-arch.md b/src/doc/unstable-book/src/language-features/asm-experimental-arch.md
index c2f4170d7d2..d9566c9f55c 100644
--- a/src/doc/unstable-book/src/language-features/asm-experimental-arch.md
+++ b/src/doc/unstable-book/src/language-features/asm-experimental-arch.md
@@ -199,3 +199,5 @@ These flags registers must be restored upon exiting the asm block if the `preser
 - SPARC
   - Integer condition codes (`icc` and `xcc`)
   - Floating-point condition codes (`fcc[0-3]`)
+- CSKY
+  - Condition/carry bit (C) in `PSR`.
diff --git a/tests/codegen/asm/csky-clobbers.rs b/tests/codegen/asm/csky-clobbers.rs
new file mode 100644
index 00000000000..4986d0fe56d
--- /dev/null
+++ b/tests/codegen/asm/csky-clobbers.rs
@@ -0,0 +1,24 @@
+//@ add-core-stubs
+//@ compile-flags: --target csky-unknown-linux-gnuabiv2
+//@ needs-llvm-components: csky
+
+#![crate_type = "rlib"]
+#![feature(no_core, asm_experimental_arch)]
+#![no_core]
+
+extern crate minicore;
+use minicore::*;
+
+// CHECK-LABEL: @flags_clobber
+// CHECK: call void asm sideeffect "", "~{psr}"()
+#[no_mangle]
+pub unsafe fn flags_clobber() {
+    asm!("", options(nostack, nomem));
+}
+
+// CHECK-LABEL: @no_clobber
+// CHECK: call void asm sideeffect "", ""()
+#[no_mangle]
+pub unsafe fn no_clobber() {
+    asm!("", options(nostack, nomem, preserves_flags));
+}