Skip to content

Commit

Permalink
Merge pull request #80 from czgdp1807/struct_03
Browse files Browse the repository at this point in the history
Ported ``integration_tests/derived_types_13.f90`` from LFortran and improve LC to compile it
  • Loading branch information
czgdp1807 authored Feb 1, 2024
2 parents fdb4d3c + db74424 commit 560a111
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,6 @@ RUN(NAME array_23.cpp LABELS gcc llvm NOFAST)

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 function_01.cpp LABELS gcc llvm NOFAST)
11 changes: 11 additions & 0 deletions integration_tests/struct_03.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>
#include "struct_03_m_01.h"

int main() {
struct t x;
x = new_value();
std::cout << x.i << std::endl;
if (x.i != 123) {
exit(2);
}
}
14 changes: 14 additions & 0 deletions integration_tests/struct_03_m_01.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef INTEGRATION_TESTS_STRUCT_03_M_01_H
#define INTEGRATION_TESTS_STRUCT_03_M_01_H

struct t {
int i;
};

struct t new_value() {
struct t p;
p.i = 123;
return p;
}

#endif
4 changes: 3 additions & 1 deletion src/lc/clang_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,9 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
is_stmt_created = true;
}
assignment_target = nullptr;
} else if( ASRUtils::is_complex(*ASRUtils::expr_type(obj)) ) {
} else if( ASRUtils::is_complex(*ASRUtils::expr_type(obj)) ||
ASR::is_a<ASR::Struct_t>(*ASRUtils::extract_type(
ASRUtils::expr_type(obj))) ) {
TraverseStmt(args[1]);
if( !is_stmt_created ) {
ASR::expr_t* value = ASRUtils::EXPR(tmp.get());
Expand Down

0 comments on commit 560a111

Please sign in to comment.