diff --git a/lldb/test/API/riscv/expressions/Makefile b/lldb/test/API/riscv/expressions/Makefile new file mode 100644 index 00000000000000..99998b20bcb050 --- /dev/null +++ b/lldb/test/API/riscv/expressions/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/riscv/expressions/TestExpressions.py b/lldb/test/API/riscv/expressions/TestExpressions.py new file mode 100644 index 00000000000000..32d007a926d2ac --- /dev/null +++ b/lldb/test/API/riscv/expressions/TestExpressions.py @@ -0,0 +1,94 @@ +""" +Test RISC-V expressions evaluation. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestExpressions(TestBase): + def common_setup(self): + self.build() + lldbutil.run_to_source_breakpoint( + self, "// break here", lldb.SBFileSpec("main.cpp") + ) + + @skipIf(archs=no_match(["rv64gc"])) + def test_int_arg(self): + self.common_setup() + self.expect_expr("foo(foo(5), foo())", result_type="int", result_value="8") + + @skipIf(archs=no_match(["rv64gc"])) + def test_double_arg(self): + self.common_setup() + self.expect( + "expr func_with_double_arg(1, 6.5)", + error=True, + substrs=["Architecture passes failure on function $__lldb_expr"], + ) + + @skipIf(archs=no_match(["rv64gc"])) + def test_ptr_arg(self): + self.common_setup() + self.expect_expr("func_with_ptr_arg(\"message\")", result_type="int", result_value="2") + + @skipIf(archs=no_match(["rv64gc"])) + def test_ptr_ret_val(self): + self.common_setup() + self.expect("expr func_with_ptr_return()", substrs=["global"]) + + @skipIf(archs=no_match(["rv64gc"])) + def test_ptr(self): + self.common_setup() + self.expect( + "expr func_with_ptr(\"message\")", + substrs=["message"], + ) + + @skipIf(archs=no_match(["rv64gc"])) + def test_global_ptr(self): + self.common_setup() + self.expect( + "expr func_with_ptr(g_str)", + substrs=["global"], + ) + + @skipIf(archs=no_match(["rv64gc"])) + def test_struct_arg(self): + self.common_setup() + self.expect_expr("func_with_struct_arg(s)", result_type="int", result_value="3") + + @skipIf(archs=no_match(["rv64gc"])) + def test_unsupported_struct_arg(self): + self.common_setup() + self.expect( + "expr func_with_unsupported_struct_arg(u)", + error=True, + substrs=["Architecture passes failure on function $__lldb_expr"], + ) + + @skipIf(archs=no_match(["rv64gc"])) + def test_double_ret_val(self): + self.common_setup() + + self.expect( + "expr func_with_double_return()", + error=True, + substrs=["Architecture passes failure on function $__lldb_expr"], + ) + + @skipIf(archs=no_match(["rv64gc"])) + def test_struct_return(self): + self.common_setup() + self.expect_expr("func_with_struct_return()", result_type="S") + + @skipIf(archs=no_match(["rv64gc"])) + def test_ptr_ret_val(self): + self.common_setup() + self.expect( + "expr func_with_unsupported_struct_return()", + error=True, + substrs=["Architecture passes failure on function $__lldb_expr"], + ) diff --git a/lldb/test/API/riscv/expressions/main.cpp b/lldb/test/API/riscv/expressions/main.cpp new file mode 100644 index 00000000000000..bdf9e28ef3d566 --- /dev/null +++ b/lldb/test/API/riscv/expressions/main.cpp @@ -0,0 +1,54 @@ +struct S { + int a; + int b; +}; + +struct U { + int a; + double d; +}; + +int g; + +char *g_str = "global"; + +int func_with_double_arg(int a, double b) { return 1; } + +int func_with_ptr_arg(char *msg) { return 2; } +char *func_with_ptr_return() { return g_str; } +char *func_with_ptr(char *msg) { return msg; } + +int func_with_struct_arg(struct S s) { return 3; } + +int func_with_unsupported_struct_arg(struct U u) { return 4; } + +double func_with_double_return() { return 42.0; } + +struct S func_with_struct_return() { + struct S s = {3, 4}; + return s; +} + +struct U func_with_unsupported_struct_return() { + struct U u = {3, 42.0}; + return u; +} + +int foo() { return 3; } + +int foo(int a) { return a; } + +int foo(int a, int b) { return a + b; } + +int main() { + struct S s = {1, 2}; + struct U u = {1, 1.0}; + double d = func_with_double_arg(1, 1.0) + func_with_struct_arg(s) + + func_with_ptr_arg("msg") + func_with_double_return() + + func_with_unsupported_struct_arg(u) + foo() + foo(1) + foo(1, 2); + char *msg = func_with_ptr("msg"); + char *ptr = func_with_ptr_return(); + s = func_with_struct_return(); + u = func_with_unsupported_struct_return(); + return 0; // break here +}