Skip to content

Commit 05d379f

Browse files
authored
Merge pull request #600 from czgdp1807/test_c_interop_04
Enabling ``c`` backend for ``test_c_interop_04.py``
2 parents 84bcf1c + 01209f5 commit 05d379f

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,4 @@ integration_tests/test_c_interop_01
170170
integration_tests/test_c_interop_03
171171
integration_tests/test_c_interop_03.c
172172
integration_tests/test_c_interop_04
173+
integration_tests/test_c_interop_04.c

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ RUN(NAME test_c_interop_02 LABELS cpython llvm c
156156
EXTRAFILES test_c_interop_02b.c)
157157
RUN(NAME test_c_interop_03 LABELS llvm c
158158
EXTRAFILES test_c_interop_03b.c)
159-
RUN(NAME test_c_interop_04 LABELS llvm
159+
RUN(NAME test_c_interop_04 LABELS llvm c
160160
EXTRAFILES test_c_interop_04b.c)
161161
RUN(NAME test_c_interop_05 LABELS llvm
162162
EXTRAFILES test_c_interop_05b.c)

src/libasr/codegen/asr_to_c.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ std::string format_type_c(const std::string &dims, const std::string &type,
4444
const std::string &name, bool use_ref, bool /*dummy*/)
4545
{
4646
std::string fmt;
47-
std::string ref = "", ptr = "";
48-
if (dims.size() > 0) ptr = "*";
47+
std::string ref = "";
4948
if (use_ref) ref = "&";
50-
fmt = type + " " + ptr + ref + name;
49+
if( dims == "*" ) {
50+
fmt = type + " " + dims + ref + name;
51+
} else {
52+
fmt = type + " " + ref + name + dims;
53+
}
5154
return fmt;
5255
}
5356

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,11 @@ R"(#include <stdio.h>
711711
void visit_GetPointer(const ASR::GetPointer_t& x) {
712712
self().visit_expr(*x.m_arg);
713713
std::string arg_src = std::move(src);
714-
src = "&" + arg_src;
714+
std::string addr_prefix = "&";
715+
if( ASRUtils::is_array(ASRUtils::expr_type(x.m_arg)) ) {
716+
addr_prefix.clear();
717+
}
718+
src = addr_prefix + arg_src;
715719
}
716720

717721
void visit_PointerToCPtr(const ASR::PointerToCPtr_t& x) {

0 commit comments

Comments
 (0)