Skip to content

Enabling c backend for test_c_interop_04.py #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/libasr/codegen/asr_to_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,11 @@ R"(#include <stdio.h>
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) {
Expand Down