Skip to content

Commit 63615ea

Browse files
authored
Merge pull request #817 from ThePortlandGroup/nv_stage
Pull 2019-10-22T14-00 Recent NVIDIA Changes
2 parents d07daf3 + 528c3ea commit 63615ea

File tree

30 files changed

+464
-116
lines changed

30 files changed

+464
-116
lines changed

runtime/flang/dist.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1995-2018, NVIDIA CORPORATION. All rights reserved.
2+
* Copyright (c) 1995-2019, NVIDIA CORPORATION. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -2863,8 +2863,9 @@ ENTFTN(SIZE, size)(__INT_T *dim, F90_Desc *pd)
28632863
{
28642864
__INT_T size;
28652865

2866-
if (F90_TAG_G(pd) != __DESC)
2867-
__fort_abort("SIZE: arg not associated with array");
2866+
if (F90_TAG_G(pd) != __DESC) {
2867+
return 1;
2868+
}
28682869
if (!ISPRESENT(dim))
28692870
size = F90_GSIZE_G(pd);
28702871
else if (*dim < 1 || *dim > F90_RANK_G(pd))

runtime/flang/type.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ void ENTF90(DEALLOC_POLY_MBR03A,
830830
if (!g1 && !I8(__fort_allocated)(cb)) {
831831
continue;
832832
}
833+
if (ld->tag == 'T') {
834+
/* Need to deallocate allocatable component */
835+
ENTF90(DEALLOC_MBR03, dealloc_mbr03)
836+
(stat, cb, firsttime, CADR(errmsg), CLEN(errmsg));
837+
}
833838
}
834839
}
835840
ENTF90(DEALLOC_MBR03, dealloc_mbr03)
@@ -1085,7 +1090,7 @@ get_source_and_dest_sizes(F90_Desc *ad, F90_Desc *bd,
10851090
*src_sz = 0;
10861091
}
10871092
} else if (bd && !flag && ISSCALAR(bd) && bd->tag != __POLY &&
1088-
bd->tag < __NTYPES) {
1093+
bd->tag != __STR && bd->tag < __NTYPES) {
10891094
#if defined(WINNT)
10901095
*src_sz = __get_fort_size_of(bd->tag);
10911096
#else
@@ -1103,9 +1108,10 @@ get_source_and_dest_sizes(F90_Desc *ad, F90_Desc *bd,
11031108
dest_td->obj.tag == __POLY && ad->len > 0 && !ad->lsize &&
11041109
!ad->gsize && ad->kind > 0 && ad->kind < __NTYPES) {
11051110
*dest_sz = (size_t)dest_td->obj.size * ad->len;
1106-
} else if (!*src_sz || ((flag == 1 || (ad && ad->tag == __DESC)) &&
1111+
} else if (!*src_sz || ((flag == 1 || (ad && ad->tag == __DESC)) &&
11071112
dest_td->obj.tag == __POLY)) {
1108-
*dest_sz = (size_t)dest_td->obj.size;
1113+
*dest_sz = dest_td != I8(__f03_ty_to_id)[__STR] ?
1114+
(size_t)dest_td->obj.size : ad->len;
11091115
} else {
11101116
*dest_sz = 0;
11111117
}

test/f90_correct/inc/en01.mk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
#
17+
########## Make rule for test en01 ########
18+
19+
20+
en01: run
21+
22+
23+
build: $(SRC)/en01.f90
24+
-$(RM) en01.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
25+
@echo ------------------------------------ building test $@
26+
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/en01.f90 -o en01.$(OBJX)
27+
-$(FC) $(FFLAGS) $(LDFLAGS) en01.$(OBJX) $(LIBS) -o en01.$(EXESUFFIX)
28+
29+
30+
run:
31+
@echo ------------------------------------ executing test en01
32+
en01.$(EXESUFFIX)
33+
34+
verify: ;
35+

test/f90_correct/lit/en01.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Shared lit script for each tests. Run bash commands that run tests with make.
17+
18+
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
19+
# RUN: cat %t | FileCheck %S/runmake

test/f90_correct/src/en01.f90

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
! Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
2+
!
3+
! Licensed under the Apache License, Version 2.0 (the "License");
4+
! you may not use this file except in compliance with the License.
5+
! You may obtain a copy of the License at
6+
!
7+
! http://www.apache.org/licenses/LICENSE-2.0
8+
!
9+
! Unless required by applicable law or agreed to in writing, software
10+
! distributed under the License is distributed on an "AS IS" BASIS,
11+
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
! See the License for the specific language governing permissions and
13+
! limitations under the License.
14+
!
15+
16+
subroutine foo()
17+
print *, 'PASS'
18+
end subroutine foo
19+
20+
subroutine bar(msg, func)
21+
character(len=1) msg
22+
external func
23+
return
24+
entry alt_bar(func)
25+
call func()
26+
return
27+
end subroutine bar
28+
29+
interface
30+
subroutine foo()
31+
end subroutine foo
32+
end interface
33+
34+
call alt_bar(foo)
35+
end program
36+

tools/flang1/flang1exe/dtypeutl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,10 @@ getdtype(DTYPE dtype, char *ptr)
25432543
strcpy(p, " assumedshape");
25442544
p += strlen(p);
25452545
}
2546+
if (AD_ASSUMRANK(ad) == 1) {
2547+
strcpy(p, " assumedrank");
2548+
p += strlen(p);
2549+
}
25462550
if (AD_ASSUMSHP(ad) == 2) {
25472551
strcpy(p, " wasassumedshape");
25482552
p += strlen(p);
@@ -2776,6 +2780,7 @@ _dmp_dent(DTYPE dtypeind, FILE *outfile)
27762780
numdim, AD_DEFER(ad), AD_ADJARR(ad), AD_ASSUMSZ(ad),
27772781
AD_NOBOUNDS(ad));
27782782
fprintf(outfile, " assumshp:%d\n", AD_ASSUMSHP(ad));
2783+
fprintf(outfile, " assumrank:%d\n", AD_ASSUMRANK(ad));
27792784
fprintf(outfile, " zbase: %d numelm: %d\n", AD_ZBASE(ad),
27802785
AD_NUMELM(ad));
27812786
if (numdim < 1 || numdim > 7)

tools/flang1/flang1exe/dump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,6 +2825,8 @@ dsym(int sptr)
28252825
ASSUMLENP(0, 0);
28262826
putbit("assumshp", ASSUMSHPG(0));
28272827
ASSUMSHPP(0, 0);
2828+
putbit("assumrank", ASSUMRANKG(0));
2829+
ASSUMRANKP(0, 0);
28282830
putbit("asumsz", ASUMSZG(0));
28292831
ASUMSZP(0, 0);
28302832
putbit("ccsym", CCSYMG(0));
@@ -4296,6 +4298,7 @@ dumpdt(int dt)
42964298
putbit("adjarr", ADD_ADJARR(dt));
42974299
putbit("assumedsize", ADD_ASSUMSZ(dt));
42984300
putbit("assumedshape", ADD_ASSUMSHP(dt));
4301+
putbit("assumedrank", ADD_ASSUMRANK(dt));
42994302
putbit("defer", ADD_DEFER(dt));
43004303
putbit("nobounds", ADD_NOBOUNDS(dt));
43014304
putast("zbase", ADD_ZBASE(dt));

tools/flang1/flang1exe/func.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3986,7 +3986,23 @@ rewrite_calls(void)
39863986
is_or_has_poly(sptr_lhs) ||
39873987
has_length_type_parameter_use(DTYPEG(sptr_lhs)) ||
39883988
(sptr2 && !ALLOCATTRG(sptr_lhs) && has_poly_mbr(sptr_lhs, 1))) {
3989+
int alloc_source;
3990+
DTYPE source_dtype;
39893991
check_alloc_ptr_type(sptr_lhs, std, a, 1, 1, A_SRCG(ast), astmem);
3992+
alloc_source = A_STARTG(ast);
3993+
source_dtype = DTYPEG(sptr2);
3994+
if (alloc_source > 0 && (DTY(DDTG(source_dtype)) == TY_CHAR ||
3995+
DTY(DDTG(source_dtype)) == TY_NCHAR)) {
3996+
/* This is a sourced allocation with a character source argument.
3997+
* Need to make sure we assign the character object's length to
3998+
* the receiver's descriptor.
3999+
*/
4000+
int len = ast_intr(I_LEN, astb.bnd.dtype, 1,
4001+
A_TYPEG(alloc_source) == A_SUBSCR ?
4002+
A_LOPG(alloc_source) : alloc_source);
4003+
len = gen_set_len_ast(A_SRCG(ast), SDSCG(sptr_lhs), len);
4004+
add_stmt_after(len, std);
4005+
}
39904006
}
39914007
}
39924008
}

tools/flang1/flang1exe/outconv.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ _simple_replacements(int ast, int *pany)
11061106
int newast;
11071107
char *fname;
11081108
int in_device_code;
1109+
SPTR sptr;
11091110
fname = SYMNAME(fsptr);
11101111
newast = ast;
11111112
in_device_code = 0;
@@ -1116,6 +1117,10 @@ _simple_replacements(int ast, int *pany)
11161117
} else if (strcmp(fname, mkRteRtnNm(RTE_extent)) == 0) {
11171118
newast = _pghpf_size(0, ast);
11181119
} else if (strcmp(fname, mkRteRtnNm(RTE_sizeDsc)) == 0) {
1120+
newast = ARGT_ARG(A_ARGSG(ast), 1);
1121+
if (A_TYPEG(newast) == A_ID && ASSUMRANKG(A_SPTRG(newast))) {
1122+
return;
1123+
}
11191124
newast = _pghpf_size(1, ast);
11201125
} else if (strcmp(fname, mkRteRtnNm(RTE_size)) == 0) {
11211126
newast = _RTE_size(ast);
@@ -2204,6 +2209,36 @@ _sd_member(int subscript, int sdx, int sdtype)
22042209
return mk_subscr(sdx, subscr, 1, sdtype);
22052210
} /* _sd_member */
22062211

2212+
/** \brief This routine assigns a size to a descriptor's length field.
2213+
*
2214+
* \param ast is the expression that has the descriptor
2215+
* (e.g., an A_ID, A_MEM, etc.).
2216+
* \param ddesc is the symbol table pointer of the descriptor.
2217+
* \param sz is the AST representing the size.
2218+
*
2219+
* \return the resulting assignment AST.
2220+
*/
2221+
int
2222+
gen_set_len_ast(int ast, SPTR ddesc, int sz)
2223+
{
2224+
2225+
DTYPE dtype;
2226+
int ast2;
2227+
2228+
dtype = astb.bnd.dtype;
2229+
2230+
ast2 = mk_id(ddesc);
2231+
ast2 = _sd_member(DESC_HDR_BYTE_LEN, ast2, dtype);
2232+
A_DTYPEP(ast2, dtype);
2233+
2234+
ast2 = check_member(ast, ast2);
2235+
2236+
return mk_assn_stmt(ast2, sz, dtype);
2237+
2238+
}
2239+
2240+
2241+
22072242
LOGICAL
22082243
inline_RTE_set_type(int ddesc, int sdesc, int stmt, int after,
22092244
DTYPE src_dtype, int astmem)

tools/flang1/flang1exe/rest.c

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,50 @@ transform_call(int std, int ast)
19621962
ARGT_ARG(newargt, newj) = pghpf_type(ty);
19631963
++newj;
19641964
} else if (SDSCG(sptr)) {
1965-
1965+
/*
1966+
* If the array descriptor comes from the parent subprogram (Fortran
1967+
* term, host subprogram), the INTERNREF flag of array descriptor must
1968+
* be set. The missing case here is when the array is a static member
1969+
* of derived type var and the derived type var is defined in parent
1970+
* routine, the array descriptor is not set. The following code is to
1971+
* detect such case.
1972+
*/
1973+
1974+
SPTR sdsdsptr = SDSCG(sptr);
1975+
1976+
/* Condition gbl.internal > 1 is to make sure that the current
1977+
* function is a contained subprogram.
1978+
* gbl.internal = 0, there is no contained subprogram.
1979+
* gbl.internal = 1, the current routine at least has a contain
1980+
* statement.
1981+
* gbl.internal > 1, the current routine is contained subprogram.
1982+
* A_TYPEG(ele) == A_MEM && needdescr && gbl.internal > 1
1983+
* is to make sure that the descriptor is for an array
1984+
* member in a derived-type variable if it is not an array variable
1985+
* member in the derived-type, the INTERNREF flag of its descriptor
1986+
* should be set in routine set_internref_flag in semsym.c.
1987+
*
1988+
* SCOPEG(sdsdsptr) && STYPEG(SCOPEG(sdsdsptr)) != ST_MODULE &&
1989+
* SCOPEG(sdsdsptr) == SCOPEG(gbl.currsub) is to make sure that the
1990+
* sdsc is a reference from the parent routine.
1991+
*
1992+
* Note that the fortran can only contain one-level depth of
1993+
* subprogram. The contained subprogram cannot contain any
1994+
* subprograms.
1995+
*/
1996+
if (gbl.internal > 1 && A_TYPEG(ele) == A_MEM && needdescr &&
1997+
SCOPEG(sdsdsptr) && STYPEG(SCOPEG(sdsdsptr)) != ST_MODULE &&
1998+
SCOPEG(sdsdsptr) == SCOPEG(gbl.currsub)) {
1999+
/* Pointer to the section descriptor created by the front-end
2000+
* (or any phase before transform()). If the field is non-zero,
2001+
* the transformer uses the descriptor located by this field;
2002+
* the actual symbol located by this field is a based/allocatable
2003+
* array.
2004+
*/
2005+
if (SECDSCG(sdsdsptr))
2006+
sdsdsptr = SECDSCG(sdsdsptr);
2007+
INTERNREFP(sdsdsptr, TRUE);
2008+
}
19662009
ARGT_ARG(newargt, newj) = check_member(ele, mk_id(SDSCG(sptr)));
19672010
DESCUSEDP(sptr, 1);
19682011
NODESCP(sptr, 0);
@@ -2007,6 +2050,20 @@ transform_call(int std, int ast)
20072050
handle_seq_section(entry, ele, i, std, &retval, &descr, 1,
20082051
inface_arg);
20092052
} else {
2053+
SPTR descr_sptr = DESCRG(sptr);
2054+
/* Set the INTERNREF flag of array descriptor to make sure host
2055+
subroutines' array descriptor is accessible for contained
2056+
subroutines.
2057+
*/
2058+
if (gbl.internal > 1 && A_TYPEG(ele) == A_MEM && needdescr &&
2059+
descr_sptr > NOSYM && SCOPEG(descr_sptr) &&
2060+
STYPEG(SCOPEG(descr_sptr)) != ST_MODULE &&
2061+
SCOPEG(descr_sptr) == SCOPEG(gbl.currsub)) {
2062+
if (SECDSCG(descr_sptr))
2063+
descr_sptr = SECDSCG(descr_sptr);
2064+
2065+
INTERNREFP(descr_sptr, TRUE);
2066+
}
20102067
retval = ele;
20112068
descr = check_member(retval, mk_id(DESCRG(sptr)));
20122069
}
@@ -3690,7 +3747,8 @@ is_desc_needed(int entry, int arr_ast, int loc)
36903747
/* only user procedure may not need descr */
36913748
if (iface && HCCSYMG(iface))
36923749
return TRUE;
3693-
if (iface && STYPEG(entry) != ST_PROC && STYPEG(entry) != ST_ENTRY)
3750+
if (iface && STYPEG(entry) != ST_PROC && STYPEG(entry) != ST_ENTRY
3751+
&& (STYPEG(entry) != ST_MEMBER || !VTABLEG(entry)) && !is_procedure_ptr(entry))
36943752
return TRUE;
36953753
/* for F90, F77, C, need descriptor if copy-in is needed */
36963754
if (!dscptr)

0 commit comments

Comments
 (0)