Skip to content

Commit

Permalink
Merge pull request lfortran#4462 from Pranavchiku/gh4441
Browse files Browse the repository at this point in the history
enh: handle explicit type handling in creation of external function.
  • Loading branch information
certik authored Jul 11, 2024
2 parents 6f1257a + b41beb4 commit 1685339
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 199 deletions.
2 changes: 1 addition & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ RUN(NAME implicit_interface_12 LABELS gfortran llvmImplicit)
RUN(NAME implicit_interface_13 LABELS gfortran llvmImplicit)
RUN(NAME implicit_interface_14 LABELS gfortran) # ! TODO: fix this test
RUN(NAME implicit_interface_15 LABELS gfortran llvm2 EXTRA_ARGS --implicit-interface EXTRAFILES implicit_interface_15b)

RUN(NAME implicit_interface_16 LABELS gfortran llvm2 EXTRA_ARGS --implicit-interface EXTRAFILES implicit_interface_16b)

RUN(NAME implicit_typing_01 LABELS gfortran llvmImplicit)
RUN(NAME implicit_typing_02 LABELS gfortran llvmImplicit)
Expand Down
13 changes: 13 additions & 0 deletions integration_tests/implicit_interface_16.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program implicit_interface_16

implicit none

real :: v(4)
logical, external :: sisnan

v = [1.0, 2.0, 3.0, 4.0]

print *, sisnan( v( 1 ) )
if( sisnan( v( 1 ) ) ) error stop

end program
6 changes: 6 additions & 0 deletions integration_tests/implicit_interface_16b.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
logical function sisnan( sin )
real, intent(in) :: sin

sisnan = (sin.ne.sin)
return
end
9 changes: 7 additions & 2 deletions src/lfortran/semantics/ast_common_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
}
}

void create_external_function(std::string sym, Location loc) {
void create_external_function(std::string sym, Location loc, ASR::ttype_t* determined_type = nullptr) {
if (compiler_options.implicit_interface) {
bool is_subroutine = false;
external_procedures.push_back(sym);
Expand All @@ -2016,6 +2016,9 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
if (!is_subroutine) {
type = ASRUtils::symbol_type(sym_);
}
} else if (determined_type) {
// if explicit type provided, give preference to it.
type = determined_type;
} else if (compiler_options.implicit_typing) {
type = implicit_dictionary[std::string(1,sym[0])];
if (!type) {
Expand Down Expand Up @@ -2566,6 +2569,7 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
AST::var_sym_t &s = x.m_syms[i];
std::string sym = to_lower(s.m_name);
bool is_external = check_is_external(sym);
bool is_attr_external = false;
ASR::accessType s_access = dflt_access;
ASR::presenceType s_presence = dflt_presence;
ASR::storage_typeType storage_type = dflt_storage;
Expand Down Expand Up @@ -2694,7 +2698,7 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
excluded_from_symtab.push_back(sym);
} else if(sa->m_attr == AST::simple_attributeType
::AttrExternal) {
create_external_function(sym, x.m_syms[i].loc);
is_attr_external = true;
assgnd_access[sym] = ASR::accessType::Public;
if (assgnd_access.count(sym)) {
s_access = assgnd_access[sym];
Expand Down Expand Up @@ -2757,6 +2761,7 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
ASR::ttype_t *type = determine_type(x.base.base.loc, sym, x.m_vartype, is_pointer,
is_allocatable, dims, type_declaration, s_abi,
(s_intent != ASRUtils::intent_local) || is_argument, is_dimension_star);
if ( is_attr_external ) create_external_function(sym, x.m_syms[i].loc, type);
current_variable_type_ = type;

ASR::expr_t* init_expr = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/asr-external_01-6754623.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "asr-external_01-6754623.stdout",
"stdout_hash": "70c4de75907cc99a508ddf4fe9a7203722cf43e8988c510983937ba7",
"stdout_hash": "c003e8a7f2798614252fa50c056219c97076f75f66fc1bc9d975452f",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
21 changes: 8 additions & 13 deletions tests/reference/asr-external_01-6754623.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
()
()
Default
(Real 4)
(Complex 4)
()
BindC
Public
Expand All @@ -80,7 +80,7 @@
f
(FunctionType
[(Complex 4)]
(Real 4)
(Complex 4)
BindC
Interface
()
Expand Down Expand Up @@ -108,7 +108,7 @@
(Complex 4)
(FunctionType
[]
(Real 4)
(Complex 4)
BindC
Interface
()
Expand Down Expand Up @@ -138,18 +138,13 @@
(Var 2 f)]
[(Assignment
(Var 2 a)
(Cast
(FunctionCall
2 f
()
[((Var 2 b))]
(Real 4)
()
()
)
RealToComplex
(FunctionCall
2 f
()
[((Var 2 b))]
(Complex 4)
()
()
)
()
)]
Expand Down
13 changes: 0 additions & 13 deletions tests/reference/asr-intrinsics_02-eb20326.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/reference/asr-intrinsics_02-eb20326.stderr

This file was deleted.

13 changes: 0 additions & 13 deletions tests/reference/asr-intrinsics_03-f6b3e89.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/reference/asr-intrinsics_03-f6b3e89.stderr

This file was deleted.

13 changes: 0 additions & 13 deletions tests/reference/asr-intrinsics_04-fbc7b3a.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/reference/asr-intrinsics_04-fbc7b3a.stderr

This file was deleted.

13 changes: 0 additions & 13 deletions tests/reference/asr-intrinsics_05-a2b71c6.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/reference/asr-intrinsics_05-a2b71c6.stderr

This file was deleted.

13 changes: 0 additions & 13 deletions tests/reference/asr-intrinsics_06-1ff7a26.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/reference/asr-intrinsics_06-1ff7a26.stderr

This file was deleted.

92 changes: 0 additions & 92 deletions tests/reference/asr-merge_bits_run-9579699.stdout

This file was deleted.

0 comments on commit 1685339

Please sign in to comment.