-
Notifications
You must be signed in to change notification settings - Fork 138
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
base: master
Are you sure you want to change the base?
Fix a min-max bug #1418
Conversation
There was a problem hiding this 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?
ba25bbb
to
178894a
Compare
178894a
to
7e03751
Compare
if (dtypecompare == TY_DWORD) dtypecompare = TY_INT8; | ||
if (dtypecompare > maxtype) { | ||
maxtype = dtypecompare; | ||
dtype1 = argdtype; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
98d9141
to
4f3651b
Compare
There was a problem hiding this 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
Anything happens here? |
This patch solves two problems:
According to the fortran 2008 standard, add syntax check for MAX/MIN intrinsic, as follows:
The final type of argument with MIN/MAX intrinsic is determined by the type of highest precision argument, not the first argument.