From c8f07081316a64ea806d20a6aea38689a27eda71 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 29 Feb 2024 23:09:52 +0530 Subject: [PATCH 1/2] TEST: Ported integration_tests/structs_01.py from LPython --- integration_tests/struct_05.cpp | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 integration_tests/struct_05.cpp diff --git a/integration_tests/struct_05.cpp b/integration_tests/struct_05.cpp new file mode 100644 index 0000000..b946d0e --- /dev/null +++ b/integration_tests/struct_05.cpp @@ -0,0 +1,48 @@ +#include + +struct A_t { + float y; + int32_t x; + + constexpr A_t(float y_, int32_t x_): y(y_), x(x_) {} +}; + +void assert(bool condition) { + if( !condition ) { + exit(2); + } +} + +void f(const A_t& a) { + std::cout << a.x << std::endl; + std::cout << a.y << std::endl; +} + +void change_struct(A_t& a) { + a.x = a.x + 1; + a.y = a.y + float(1); +} + +void g() { + A_t x = A_t(float(3.25), 3); + f(x); + assert( x.x == 3 ); + assert( double(x.y) == 3.25 ); + + x.x = 5; + x.y = float(5.5); + f(x); + assert( x.x == 5 ); + assert( double(x.y) == 5.5 ); + change_struct(x); + assert( x.x == 6 ); + assert( double(x.y) == 6.5 ); +} + +int main() { + +g(); + +return 0; + +} From 1d69d52f71e76fd59f2b470b66594e88089c3fdf Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 29 Feb 2024 23:10:08 +0530 Subject: [PATCH 2/2] TEST: Register struct_05.cpp --- integration_tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index ee610a8..8320dbc 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -213,6 +213,7 @@ RUN(NAME struct_01.cpp LABELS gcc llvm NOFAST) RUN(NAME struct_02.cpp LABELS gcc llvm NOFAST) RUN(NAME struct_03.cpp LABELS gcc llvm NOFAST) RUN(NAME struct_04.cpp LABELS gcc llvm NOFAST) +RUN(NAME struct_05.cpp LABELS gcc llvm NOFAST) RUN(NAME pointer_01.cpp LABELS gcc) RUN(NAME pointer_02.cpp LABELS gcc)