From 8ae988df59acb6c1eb8f5bbed273b5e93cd17963 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Tue, 14 Jun 2022 14:05:58 +0530 Subject: [PATCH 1/2] Use dimensions correctly in declaring variables in C backend --- src/libasr/codegen/asr_to_c.cpp | 9 ++++++--- src/libasr/codegen/asr_to_c_cpp.h | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libasr/codegen/asr_to_c.cpp b/src/libasr/codegen/asr_to_c.cpp index b6308f6174..23cf10d711 100644 --- a/src/libasr/codegen/asr_to_c.cpp +++ b/src/libasr/codegen/asr_to_c.cpp @@ -44,10 +44,13 @@ std::string format_type_c(const std::string &dims, const std::string &type, const std::string &name, bool use_ref, bool /*dummy*/) { std::string fmt; - std::string ref = "", ptr = ""; - if (dims.size() > 0) ptr = "*"; + std::string ref = ""; if (use_ref) ref = "&"; - fmt = type + " " + ptr + ref + name; + if( dims == "*" ) { + fmt = type + " " + dims + ref + name; + } else { + fmt = type + " " + ref + name + dims; + } return fmt; } diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index 8575f1b2da..f0fa6dacc3 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -711,7 +711,11 @@ R"(#include void visit_GetPointer(const ASR::GetPointer_t& x) { self().visit_expr(*x.m_arg); std::string arg_src = std::move(src); - src = "&" + arg_src; + std::string addr_prefix = "&"; + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_arg)) ) { + addr_prefix.clear(); + } + src = addr_prefix + arg_src; } void visit_PointerToCPtr(const ASR::PointerToCPtr_t& x) { From 01209f5fe01d7b48b8c8040a338b45baeaeacfb5 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Tue, 14 Jun 2022 14:06:10 +0530 Subject: [PATCH 2/2] Updated reference tests --- .gitignore | 1 + integration_tests/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d1515a304b..8dc78227ec 100644 --- a/.gitignore +++ b/.gitignore @@ -170,3 +170,4 @@ integration_tests/test_c_interop_01 integration_tests/test_c_interop_03 integration_tests/test_c_interop_03.c integration_tests/test_c_interop_04 +integration_tests/test_c_interop_04.c diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index fea2b23007..049bb27d63 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -156,7 +156,7 @@ RUN(NAME test_c_interop_02 LABELS cpython llvm c EXTRAFILES test_c_interop_02b.c) RUN(NAME test_c_interop_03 LABELS llvm c EXTRAFILES test_c_interop_03b.c) -RUN(NAME test_c_interop_04 LABELS llvm +RUN(NAME test_c_interop_04 LABELS llvm c EXTRAFILES test_c_interop_04b.c) RUN(NAME test_c_interop_05 LABELS llvm EXTRAFILES test_c_interop_05b.c)