]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Add tests for constraints "i" and "s"
authorFangrui Song <maskray@gcc.gnu.org>
Wed, 31 Jan 2024 04:41:12 +0000 (20:41 -0800)
committerFangrui Song <maskray@gcc.gnu.org>
Thu, 22 Feb 2024 01:20:33 +0000 (17:20 -0800)
The constraints "i" and "s" can be used with a symbol that binds
externally, e.g.
```
namespace ns { extern int var, a[4]; }
void foo() {
  asm(".pushsection .xxx,\"aw\"; .dc.a %0; .popsection" :: "s"(&ns::var));
  asm(".reloc ., BFD_RELOC_NONE, %0" :: "s"(&ns::a[3]));
}
```

gcc/testsuite/ChangeLog:

* gcc.target/riscv/asm-raw-symbol.c: New test.

gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c b/gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c
new file mode 100644 (file)
index 0000000..28305a8
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-fpic" } */
+
+extern int var, arr[2][2];
+
+void
+test (void)
+{
+  __asm__ ("@ %0" : : "i"(&var));
+  __asm__ ("@ %0 %1 %2" : : "s"(&var), "s"(&arr[1][1]), "s"(test));
+}
+
+/* { dg-final { scan-assembler "@ var arr\\+12 test" } } */
+/* { dg-final { scan-assembler "@ var" } } */