public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargls at comcast dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/113412] ATAN(Y,X) does not check arguments and generates wrong error message.
Date: Thu, 04 Apr 2024 05:03:04 +0000	[thread overview]
Message-ID: <bug-113412-4-p84i18yW87@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113412-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113412

--- Comment #7 from kargls at comcast dot net ---
(In reply to anlauf from comment #6)
> (In reply to kargls from comment #5)
> > The pointers to expr->symtree is NULL.  This new patch catches your example.
> 
> It does, but behaves weird for some other cases.  Try:
> 
> program main
>   complex :: c = 1.
>   complex, parameter :: z = 1.
>   print *, atan(c,c)
>   print *, atan(z,z)
> end
> 
> This gives now:
> 
> pr113412.f90:4:18:
> 
>     4 |   print *, atan(c,c)
>       |                  1
> Error: 'c' argument of 'atan' intrinsic at (1) must be the same type and
> kind as 'c'
> pr113412.f90:5:18:
> 
>     5 |   print *, atan(z,z)
>       |                  1
> Error: 'z' argument of 'atan' intrinsic at (1) must be the same type and
> kind as 'z'
>

Looks like I'll need to look at a more robust testcase and look
at (*ap)->expr and (*ap)->next->expr to catch the individual
issues.  I won't have time to work on this for at least 2 weeks.

> I wonder whether we can reuse existing checks for atan2 for the 2-argument
> version of atan.
> 
> I tried the following:
> 
> diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc
> index c35f2bdd183..261d4229139 100644
> --- a/gcc/fortran/intrinsic.cc
> +++ b/gcc/fortran/intrinsic.cc
> @@ -4370,6 +4370,11 @@ sort_actual (const char *name, gfc_actual_arglist
> **ap,
>    if (a == NULL)
>      goto do_sort;
>  
> +  if ((gfc_option.allow_std & GFC_STD_F2008) != 0
> +      && strcmp(name, "atan") == 0
> +      && !gfc_check_atan_2 (actual->expr, actual->next->expr))
> +    return false;
> +

I tried a similar patch in comment #2, but with (*ap)->expr
and (*ap)->next->expr.  I don't remember why this did not
work.  Perhaps, using actual->expr and actual->next->expr
sidesteps whatever I ran into.

> This is indeed sort of hackish and produces for testcase:
> 
> program main
>   complex :: c = 1.
>   print *, atan (c,c)
>   print *, atan2(c,c)
> end
> 
> pr113412.f90:3:17:
> 
>     3 |   print *, atan (c,c)
>       |                 1
> Error: 'x' argument of 'atan' intrinsic at (1) must be REAL
> pr113412.f90:4:17:
> 
>     4 |   print *, atan2(c,c)
>       |                 1
> Error: 'y' argument of 'atan2' intrinsic at (1) must be REAL
> 
> Note that the name of the formal argument is now wrong, probably because
> the association of actuals with formals is missing.

gfc_check_atan_2 reports errors with dummy argument names.  actual->expr
could be a literal-constant, a variable, or expression.  So a name may not
be available.

I need to look at the standard again.  For atan(x), x can be real or complex.
gfc_check_atan is invoked for this check.  For atan(y,x), x and y must be with
real, and the result is the same as atan2(y,x).  

If you want to put this aside until I can return to gfortran hacking, that
fine with me.  If you want to take a stab at refining the error messages in
sort_actual(), I'm fine with that too.

      parent reply	other threads:[~2024-04-04  5:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16  2:13 [Bug fortran/113412] New: " kargl at gcc dot gnu.org
2024-01-16  2:13 ` [Bug fortran/113412] " kargl at gcc dot gnu.org
2024-01-16 20:25 ` kargl at gcc dot gnu.org
2024-01-16 20:44 ` kargl at gcc dot gnu.org
2024-01-17  0:46 ` kargl at gcc dot gnu.org
2024-04-02 20:20 ` anlauf at gcc dot gnu.org
2024-04-02 22:15 ` kargls at comcast dot net
2024-04-03 20:12 ` anlauf at gcc dot gnu.org
2024-04-04  5:03 ` kargls at comcast dot net [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113412-4-p84i18yW87@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).