Skip to content

Commit

Permalink
[flang1] Fix an MIN/MAX intrinsic bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyunlong16 committed Nov 18, 2023
1 parent 7e03751 commit 98d9141
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tools/flang1/flang1exe/semfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4164,41 +4164,44 @@ cmp_mod_scope(SPTR sptr)
* or character and they shall all have the same kind type parameter.
*/
void
check_max_min_argument(int argdtype, int *dtype_new, int *dtype_last) {
check_max_min_argument(int argdtype, int *dtype_last)
{
int dtype_new = DT_NONE_GENERAL;

switch (DTYG(argdtype)) {
case TY_BINT:
case TY_SINT:
case TY_INT:
case TY_INT8:
case TY_WORD:
case TY_DWORD:
*dtype_new = DT_INT_GENERAL;
dtype_new = DT_INT_GENERAL;
break;
case TY_HALF:
case TY_REAL:
case TY_DBLE:
case TY_QUAD:
*dtype_new = DT_REAL_GENERAL;
dtype_new = DT_REAL_GENERAL;
break;
case TY_CHAR:
case TY_NCHAR:
*dtype_new = DT_CHAR_GENERAL;
dtype_new = DT_CHAR_GENERAL;
break;
default:
*dtype_new = DT_NONE_GENERAL;
dtype_new = DT_NONE_GENERAL;
break;
}
if (*dtype_last == 0)
*dtype_last = *dtype_new;
*dtype_last = dtype_new;

if (*dtype_new == DT_NONE_GENERAL) {
if (dtype_new == DT_NONE_GENERAL) {
error(155, 3, gbl.lineno,
"Arguments must be INTEGER, REAL, or CHARACTER!", CNULL);
} else if (*dtype_new != *dtype_last) {
} else if (dtype_new != *dtype_last) {
error(155, 3, gbl.lineno,
"Arguments must have the same kind type parameter!", CNULL);
} else {
*dtype_last = *dtype_new;
*dtype_last = dtype_new;
}
}

Expand Down Expand Up @@ -4228,7 +4231,6 @@ ref_intrin(SST *stktop, ITEM *list)
int tmp, tmp_ast;
FtnRtlEnum rtlRtn;
int intrin; /* one of the I_* constants */
int dtype_new = 0;
int dtype_last = 0;
int maxtype = 0;

Expand Down Expand Up @@ -4319,7 +4321,7 @@ ref_intrin(SST *stktop, ITEM *list)
}

if (intrin == I_MAX || intrin == I_MIN) {
check_max_min_argument(argdtype, &dtype_new, &dtype_last);
check_max_min_argument(argdtype, &dtype_last);
}

if (!dtype1) {
Expand Down

0 comments on commit 98d9141

Please sign in to comment.