aboutsummaryrefslogtreecommitdiff
path: root/libunwind
diff options
context:
space:
mode:
authorKito Cheng <kito.cheng@sifive.com>2023-03-15 17:23:42 +0800
committerKito Cheng <kito.cheng@sifive.com>2023-03-15 17:30:16 +0800
commit9b488ace17e6be64e61bf20f8ddc3eb563848bde (patch)
tree3bc1742ae0a81d0f5c499aaa0c606b645bda2027 /libunwind
parentcf40b8a4dd3db7370f4cde8415a05eed07ba711a (diff)
downloadllvm-9b488ace17e6be64e61bf20f8ddc3eb563848bde.zip
llvm-9b488ace17e6be64e61bf20f8ddc3eb563848bde.tar.gz
llvm-9b488ace17e6be64e61bf20f8ddc3eb563848bde.tar.bz2
[libunwind][RISC-V] Rewrite testcase with C as possible.
Fix #60472 The testcase is writen in all inline asm but it seems not well maintained for the CFI directive, of cause we can fix that, but this patch also contain another issue is it use s0 and s1 without store/restore. This patch proposed another way to testing that, use inline asm to generate dummy def and use, so compiler will generate store/restore for the vector register, and then generate the CFI directives. Also check __riscv_vector as the testcase guard, because the testcase will read vlenb which is only available when V or zve* extensions is present. Reviewed By: MaskRay, asb, #libunwind Differential Revision: https://reviews.llvm.org/D145225
Diffstat (limited to 'libunwind')
-rw-r--r--libunwind/test/unwind_scalable_vectors.pass.cpp38
1 files changed, 14 insertions, 24 deletions
diff --git a/libunwind/test/unwind_scalable_vectors.pass.cpp b/libunwind/test/unwind_scalable_vectors.pass.cpp
index 250e2c8..a5c5947 100644
--- a/libunwind/test/unwind_scalable_vectors.pass.cpp
+++ b/libunwind/test/unwind_scalable_vectors.pass.cpp
@@ -13,30 +13,8 @@
#include <assert.h>
#include <libunwind.h>
-// Check correct unwinding of frame with VLENB-sized objects (vector registers):
-// 1. Save return address (ra) in temporary register.
-// 2. Load VLENB (vector length in bytes) and substract it from current stack
-// pointer (sp) - equivalent to one vector register on stack frame.
-// 3. Set DWARF cannonical frame address (CFA) to "sp + vlenb" expresssion so it
-// can be correctly unwinded.
-// 4. Call stepper() function and check that 2 unwind steps are successful -
-// from stepper() into foo() and from foo() into main().
-// 5. Restore stack pointer and return address.
-__attribute__((naked)) static void foo() {
- __asm__(".cfi_startproc\n"
- "mv s0, ra\n"
- "csrr s1, vlenb\n"
- "sub sp, sp, s1\n"
- "# .cfi_def_cfa_expression sp + vlenb\n"
- ".cfi_escape 0x0f, 0x07, 0x72, 0x00, 0x92, 0xa2, 0x38, 0x00, 0x22\n"
- "call stepper\n"
- "add sp, sp, s1\n"
- "mv ra, s0\n"
- "ret\n"
- ".cfi_endproc\n");
-}
-
-extern "C" void stepper() {
+#ifdef __riscv_vector
+__attribute__((noinline)) extern "C" void stepper() {
unw_cursor_t cursor;
unw_context_t uc;
unw_getcontext(&uc);
@@ -47,4 +25,16 @@ extern "C" void stepper() {
assert(unw_step(&cursor) > 0);
}
+// Check correct unwinding of frame with VLENB-sized objects (vector registers).
+__attribute__((noinline)) static void foo() {
+ __rvv_int32m1_t v;
+ asm volatile("" : "=vr"(v)); // Dummy inline asm to def v.
+ stepper(); // def-use of v has cross the function, so that
+ // will triger spill/reload to/from the stack.
+ asm volatile("" ::"vr"(v)); // Dummy inline asm to use v.
+}
+
int main() { foo(); }
+#else
+int main() { return 0; }
+#endif