Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a min-max bug #1418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Liuyunlong0336
Copy link

@Liuyunlong0336 Liuyunlong0336 commented Sep 6, 2023

This patch solves two problems:

  1. According to the fortran 2008 standard, add syntax check for MAX/MIN intrinsic, as follows:

    The arguments shall all be of the same type which shall be integer, real, or character and they shall all have the same kind type parameter.

  2. The final type of argument with MIN/MAX intrinsic is determined by the type of highest precision argument, not the first argument.

Copy link
Collaborator

@bryanpkc bryanpkc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code doesn't compile. Did you push an incomplete patch?

if (dtypecompare == TY_DWORD) dtypecompare = TY_INT8;
if (dtypecompare > maxtype) {
maxtype = dtypecompare;
dtype1 = argdtype;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why the argument type checks and promotion cannot be done for I_MAX and I_MIN in the intrinsic_error block? It semes that that block of code was designed to handle these two intrinsics.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in this function is relatively complex.

For intrinsic_error ,these situations will occur:

The first scenario is as follows:

program test
  implicit none
  integer :: a, b, c
  a = 1
  b = 2
  c = max(a)
end program test

The second scenario is as follows:

program test
  implicit none
  integer :: a, b, c
  a = 1
  b = 2
  c = max()
end program test

I understand that when there is an obvious error in the arguments, there are no arguments or the arguments number is wrong, in this case intrinsic_error will be called.

And For logic in the intrinsic_error block, it is prepared for generic situations:
As follows:

/* Need to add a check for min and max first */
if (STYPEG(sptre) == ST_GENERIC && (intrin == I_MAX || intrin == I_MIN)) {

So I don’t dare to modify this logic.

And For our case, for example, argument type program will not trigger intrinsic_error.
For example:

program test
  implicit none
  integer :: a, c
  real :: b
  a = 1
  b = 2
  c = max(a, b)
end program test

In this case, the compilation can still pass, but the native version of the compiler will occur a warning.

F90-W-0093-Type conversion of expression performed

This is what a general check of this logic reports,chktyp(sp, argtyp, TRUE); in this logic will be checked, and this check is for many kinds of intrinsics.

             if (((intrin == I_BGE) || (intrin == I_BGT) ||
                  (intrin == I_BLE) || (intrin == I_BLT)) &&
                 (SST_IDG(sp) == S_CONST || SST_IDG(sp) == S_IDENT)) {
               mkexpr1(sp);
             } else
               chktyp(sp, argtyp, TRUE);

So I haven’t found a perfect method yet. For type judgment and type selection, I chose to add judgment and type update logic in front like this PR.

This patch solves two problems:

1.According to the fortran 2008 standard, add syntax check for
MAX/MIN intrinsic, as follows:
The arguments shall all be of the same type which shall be integer,
real, or character and they shall all have the same kind type
parameter.

2.The final type of argument with MIN/MAX intrinsic is determined
by the type of highest precision atgument, not the first argument.
Copy link
Collaborator

@pawosm-arm pawosm-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a small typo in the commit message: precision atgument vs. precision argument

@pawosm-arm
Copy link
Collaborator

Anything happens here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants