Skip to content

Commit 697efdc

Browse files
reland interface nested into subroutine causes symbol undefined, fix #1013 #1179
add test and remove init_use_tree add empty line in test file cosmetic fixes add empty line at the end of test file add spaces correct the coding style add declaration
1 parent ef38cc9 commit 697efdc

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
!
2+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
! See https://llvm.org/LICENSE.txt for license information.
4+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
! RUN: %flang -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
7+
!
8+
! CHECK-LABEL: define void @MAIN_()
9+
module base
10+
implicit none
11+
integer, public :: a = 10
12+
end module
13+
14+
module intermediate
15+
use base, only: a
16+
implicit none
17+
private
18+
end module
19+
20+
program x
21+
use base
22+
implicit none
23+
24+
interface
25+
subroutine sub2
26+
use intermediate
27+
implicit none
28+
end subroutine sub2
29+
end interface
30+
31+
call sub
32+
33+
contains
34+
35+
subroutine sub
36+
use intermediate
37+
implicit none
38+
print *, a
39+
end subroutine
40+
41+
end program

tools/flang1/flang1exe/interf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,21 @@ init_use_tree(void)
515515
use_tree = use_tree_end = 0;
516516
}
517517

518+
void remove_from_use_tree(char *module)
519+
{
520+
USES_LIST *prev = use_tree;
521+
for (USES_LIST *n = use_tree; n; n = n->next) {
522+
if (strcmp(n->use_module->modulename, module) == 0) {
523+
if (n == use_tree) {
524+
use_tree = use_tree->next;
525+
} else {
526+
prev->next = n->next;
527+
}
528+
}
529+
prev = n;
530+
}
531+
}
532+
518533
static TOBE_IMPORTED_LIST *
519534
already_to_be_used(char *modulename, int public, int except)
520535
{

tools/flang1/flang1exe/interf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ void import_host(FILE *, const char *, int, int, int, int, int, int, int);
8686
void import_module_end(void);
8787
int imported_directly(char *name, int except);
8888
void init_use_tree(void);
89+
void remove_from_use_tree(char *module);
8990
int aliased_sym_visible(int sptralias);
9091
void interf_init(void);
9192
void ipa_import_open(char *import_file, BIGUINT offset);

tools/flang1/flang1exe/module.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef struct {
6767
LOGICAL submodule; /* use of module by submodule */
6868
RENAME *rename;
6969
char *fullname; /* full path name of the module file */
70+
unsigned int scope; /* scope of the module */
7071
} USED;
7172

7273
struct {
@@ -371,7 +372,11 @@ apply_use_stmts(void)
371372
save_lineno = gbl.lineno;
372373

373374
if (!gbl.currmod && gbl.internal <= 1) {
374-
init_use_tree();
375+
for (m_id = FIRST_USER_MODULE; m_id < usedb.avl; m_id++) {
376+
if (usedb.base[m_id].scope > sem.scope_level) {
377+
remove_from_use_tree(SYMNAME(usedb.base[m_id].module));
378+
}
379+
}
375380
}
376381
if (usedb.base[ISO_C_MOD].module) {
377382
if (usedb.base[ISO_C_MOD].module == ancestor_mod)
@@ -914,6 +919,7 @@ open_module(SPTR use)
914919
usedb.base[module_id].submodule = FALSE;
915920
usedb.base[module_id].rename = NULL;
916921
usedb.base[module_id].fullname = fullname;
922+
usedb.base[module_id].scope = sem.scope_level;
917923

918924
if (module_id == ISO_C_MOD) {
919925
int i;

0 commit comments

Comments
 (0)