Skip to content

Commit 343f257

Browse files
committed
Fix issue with reading large, unformatted big-endian records
Make f90_old_huge_rec_fmt() visible for Flang.
1 parent 93855d9 commit 343f257

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

runtime/flang/error.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ win_set_binary(FIO_FCB *f)
847847
/* *** FORTRANOPT settings *****/
848848
static int check_format = 1; /* format checking enabled */
849849
static int crlf = 0; /* crlf does not denote end-of-line */
850+
static int legacy_large_rec_fmt = 0; /* are legacy large unf records used */
850851
static int no_minus_zero = 0; /* -0 allowed in formatted 0 */
851852
static int new_fp_formatter = TRUE;
852853

@@ -1023,6 +1024,9 @@ __fortio_init(void)
10231024
if (strstr(envar_fortranopt, "crlf")) {
10241025
crlf = 1;
10251026
}
1027+
if (strstr(envar_fortranopt, "pgi_legacy_large_rec_fmt")) {
1028+
legacy_large_rec_fmt = 1;
1029+
}
10261030
if (strstr(envar_fortranopt, "no_minus_zero")) {
10271031
no_minus_zero = 1;
10281032
}
@@ -1047,6 +1051,12 @@ __fortio_eor_crlf(void)
10471051
return crlf;
10481052
}
10491053

1054+
int
1055+
f90_old_huge_rec_fmt(void)
1056+
{
1057+
return legacy_large_rec_fmt;
1058+
}
1059+
10501060
int
10511061
__fortio_no_minus_zero(void)
10521062
{

runtime/flang/global.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,7 @@ extern VOID __fortio_errinit03(__INT_T unit, __INT_T bitv, __INT_T *iostat,
365365
char *str);
366366
extern VOID __fortio_errend(void);
367367
extern VOID __fortio_errend03(void);
368-
#ifndef PGLANG
369-
extern int __fortio_old_huge_rec_fmt(void);
370-
#endif
368+
extern int f90_old_huge_rec_fmt(void);
371369
extern int __fortio_error(int);
372370
extern int __fortio_eoferr(int);
373371
extern int __fortio_eorerr(int);

runtime/flang/unf.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,11 @@ __unf_init(bool read, bool byte_swap)
380380
}
381381
if (byte_swap)
382382
__fortio_swap_bytes((char *)&rec_len, __INT, 1);
383-
{
383+
if (!f90_old_huge_rec_fmt()) {
384+
continued = (rec_len < 0);
385+
if (continued)
386+
rec_len = -rec_len;
387+
} else {
384388
continued = ((rec_len & CONT_FLAG) != 0);
385389
rec_len &= ~CONT_FLAG;
386390
}
@@ -1197,7 +1201,10 @@ __unf_end(bool to_be_continued)
11971201
while (continued) {
11981202
if (__io_fread(&rec_len, 4, 1, Fcb->fp) != 1)
11991203
UNF_ERR(__io_errno());
1200-
{
1204+
if (!f90_old_huge_rec_fmt()) {
1205+
if (__io_fseek(Fcb->fp, -rec_len + 4, SEEK_CUR))
1206+
continued = (rec_len < 0);
1207+
} else {
12011208
if (__io_fseek(Fcb->fp, (rec_len &= ~CONT_FLAG) + 4, SEEK_CUR))
12021209
continued = (rec_len & CONT_FLAG);
12031210
}
@@ -1256,7 +1263,9 @@ __unf_end(bool to_be_continued)
12561263
/* If this record's data is to be continued in the next record,
12571264
set the continuation bit in this record's leading length word. */
12581265
if (to_be_continued) {
1259-
{
1266+
if (!f90_old_huge_rec_fmt()) {
1267+
unf_rec.u.s.bytecnt = -unf_rec.u.s.bytecnt;
1268+
} else {
12601269
unf_rec.u.s.bytecnt |= CONT_FLAG;
12611270
}
12621271
}
@@ -1273,7 +1282,9 @@ __unf_end(bool to_be_continued)
12731282
/* If this record is a continuation of the previous record, set the
12741283
continuation bit in this record's trailing length word. */
12751284
if (continued) {
1276-
{
1285+
if (!f90_old_huge_rec_fmt()) {
1286+
unf_rec.u.s.bytecnt = -unf_rec.u.s.bytecnt;
1287+
} else {
12771288
unf_rec.u.s.bytecnt |= CONT_FLAG;
12781289
}
12791290
}
@@ -2033,7 +2044,12 @@ __usw_end(bool to_be_continued)
20332044
if (__io_fread(&rec_len, 4, 1, Fcb->fp) != 1)
20342045
UNF_ERR(__io_errno());
20352046
__fortio_swap_bytes((char *)&rec_len, __INT, 1);
2036-
{
2047+
if (!f90_old_huge_rec_fmt()) {
2048+
if (__io_fseek(Fcb->fp, -rec_len + 4, SEEK_CUR)) {
2049+
UNF_ERR(__io_errno());
2050+
}
2051+
continued = (rec_len < 0);
2052+
} else {
20372053
if (__io_fseek(Fcb->fp, (rec_len &= ~CONT_FLAG) + 4, SEEK_CUR)) {
20382054
UNF_ERR(__io_errno());
20392055
}
@@ -2101,9 +2117,14 @@ __usw_end(bool to_be_continued)
21012117
UNF_ERR(__io_errno());
21022118
if (__io_fseek(Fcb->fp, (seekoffx_t)unf_rec.u.s.bytecnt, SEEK_CUR) != 0)
21032119
UNF_ERR(__io_errno());
2120+
if (to_be_continued && !continued) {
2121+
bs_tmp = f90_old_huge_rec_fmt() ? -bs_tmp : bs_tmp & ~CONT_FLAG_SW;
2122+
}
21042123
}
21052124
/* If this record is a continuation of the previous record, set the
21062125
continuation bit in this record's trailing length word. */
2126+
if (continued)
2127+
bs_tmp = f90_old_huge_rec_fmt() ? bs_tmp : (bs_tmp | CONT_FLAG_SW);
21072128
continued = to_be_continued;
21082129
/* write record length at end of record */
21092130
if ((FWRITE(&bs_tmp, RCWSZ, 1, Fcb->fp)) != 1)

0 commit comments

Comments
 (0)