This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add more diagnostic for MAX/MIN intrinsic
ClosedPublic

Authored by kkwli0 on Nov 9 2022, 2:23 PM.

Diff Detail

Event Timeline

kkwli0 created this revision.Nov 9 2022, 2:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 2:23 PM
Herald added a subscriber: jdoerfert. · View Herald Transcript
kkwli0 requested review of this revision.Nov 9 2022, 2:23 PM
kkwli0 edited the summary of this revision. (Show Details)Nov 9 2022, 8:36 PM
clementval added inline comments.
flang/lib/Evaluate/intrinsics.cpp
1465

Why not combining this with CheckMaxMinArgument?

1639

Is there a good reason to use a hard-coded parameter and not directly put it in the string?

1641

Same here.

1644

Same here.

You need to run clang-format on flang/lib/Evaluate/intrinsics.cpp. Pre-commit is failing now.

clementval requested changes to this revision.Nov 10 2022, 8:59 AM
This revision now requires changes to proceed.Nov 10 2022, 8:59 AM

Thanks for looking into the bugs here and submitting this patch for review. I hope that my comments make sense; please let me know if they don't.

flang/lib/Evaluate/intrinsics.cpp
1470

In the bits of f18 that run before lowering, we consistently use a more modern and strict coding convention that includes braced initialization on declarations for increased safety against inadvertent conversions.

1473

I think that you probably need to test arguments.size() before indexing into it. I'd recommend using .at(0) rather than [0] for extra saftely.

It may be the case that you can elicit these error messages from the general-case code by allowing MAX and MIN to use a two-element actualForDummy array to track A1= and A2= rather than bypassing its use altogether, which is what I think happens now.

1558

Consider putting this code after the loop, before the call to your new function; it confused me a bit on the first reading by being in the loop here. It might also need to handle the case of zero actual arguments, which it won't see here.

1636

Is this special case code for isMaxMin really needed here? Maybe the original general case code can be made to work.

flang/test/Semantics/call23.f90
29

maybe also test A0=, A03= (which would sort before A1), and ABAD=.

kkwli0 marked 7 inline comments as done.Nov 14 2022, 8:54 AM
kkwli0 added inline comments.
flang/lib/Evaluate/intrinsics.cpp
1465

As far as I understand CheckMaxMinArgument, it is a per-argument check. For the case of max/min, we need to determine the position of the actual argument in the argument list. If keyword argument is used in the first two actual argument, we need to check all the other arguments till the end (i.e. for the worse case scenario - max(..., a1=x, a2=y)) in order to determine if any error situation is encountered. In my opinion, it is better to wait till all the keyword is collected and then do the check.

1473

Yes, I need to check arguments.size(). I will change [0] to .at(0).

It may be the case that you can elicit these error messages from the general-case code by allowing MAX and MIN to use a two-element actualForDummy array to track A1= and A2= rather than bypassing its use altogether, which is what I think happens now.

As far as I understand, the existing code makes max/min a special case because it can have infinite arguments. The logic for the general case relies on the keywords but max/min does not have in the table if the argument list is larger than 3. I may have missed something here.

1558

Sure. I will move it after the loop for clarity. However, the zero actual arguments case is a different issue (https://github.com/llvm/llvm-project/issues/58921).

1639

Will use dummy[1].keyword instead.

1641

Will use dummy[0].keyword instead.

1644

Will use dummy[0].keyword and dummy[1].keyword instead.

flang/test/Semantics/call23.f90
29

Good point. I will add the variations.

kkwli0 updated this revision to Diff 475168.EditedNov 14 2022, 8:56 AM
kkwli0 marked 6 inline comments as done.

Address review comments and rebase.

Thanks for the updates. I'll let @klausler make the final approval.

The debian build has failed; please resolve that failure.

flang/lib/Evaluate/intrinsics.cpp
1605

I think that this would be more clear as a while loop.

1641

You can just say "missing mandatory A2= argument" without needing the string expansion; it would be more clear.

kkwli0 marked 2 inline comments as done.Nov 16 2022, 7:37 PM
kkwli0 added inline comments.
flang/lib/Evaluate/intrinsics.cpp
1605

Will do

1641

Will do.

kkwli0 updated this revision to Diff 475992.Nov 16 2022, 7:44 PM
kkwli0 marked 2 inline comments as done.

Address review comment.

The debian build has failed; please resolve that failure.

@klausler May I know what the debian build error is? I am trying to find a debian system to reproduce the problem.

The debian build has failed; please resolve that failure.

@klausler May I know what the debian build error is? I am trying to find a debian system to reproduce the problem.

@kkwli0, you may follow the links above in the Diff Detail section. There was a build failure for Diff 2, so if you go to https://reviews.llvm.org/D137742?id=475168, you will see x64 debian failed - and if you click on it you will get to https://buildkite.com/llvm-project/premerge-checks/builds/121619#01847714-2b4a-422f-8da3-f3efd92756d5

Long story short, there was a clang-format issue in flang/lib/Evaluate/intrinsics.cpp and Valentin pointed this out in https://reviews.llvm.org/D137742#3918803 :)

kkwli0 updated this revision to Diff 476002.Nov 16 2022, 9:24 PM

Fix format.

Thanks @vzakhari

klausler accepted this revision.Nov 17 2022, 9:02 AM
kkwli0 marked an inline comment as done.Nov 18 2022, 9:20 AM

@clementval Do you have more comments? I don't know how to change from the "Needs Review" to "Accepted" state. Thanks.

This revision is now accepted and ready to land.Nov 18 2022, 9:35 AM
This revision was automatically updated to reflect the committed changes.