From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 866BA3858C50; Thu, 4 Apr 2024 05:03:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 866BA3858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712206985; bh=O0C7Q5X0Ozs6Zq42rSeNsiP6XwFzLRA0zE2EsioYY6A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e1/KDi7auQghXUTYJAoiCTOPW2aCmtxDqiHeL8hA00vXEhwxJnsI/+Rq8eElh2jFA 2hrbSHL2uY61fR8w71YuQP5MDWqBNnBhgU6NWi/L+QqyESiiNyL+vdjIisFmbfPAua jK9qs5l96jjiAdNxPkIFYfeBMc9/RqxD+Tuqymes= From: "kargls at comcast dot net" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kargls at comcast dot net X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113412 --- 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 exa= mple. >=20 > It does, but behaves weird for some other cases. Try: >=20 > program main > complex :: c =3D 1. > complex, parameter :: z =3D 1. > print *, atan(c,c) > print *, atan(z,z) > end >=20 > This gives now: >=20 > pr113412.f90:4:18: >=20 > 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: >=20 > 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. >=20 > I tried the following: >=20 > 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 =3D=3D NULL) > goto do_sort; >=20=20 > + if ((gfc_option.allow_std & GFC_STD_F2008) !=3D 0 > + && strcmp(name, "atan") =3D=3D 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: >=20 > program main > complex :: c =3D 1. > print *, atan (c,c) > print *, atan2(c,c) > end >=20 > pr113412.f90:3:17: >=20 > 3 | print *, atan (c,c) > | 1 > Error: 'x' argument of 'atan' intrinsic at (1) must be REAL > pr113412.f90:4:17: >=20 > 4 | print *, atan2(c,c) > | 1 > Error: 'y' argument of 'atan2' intrinsic at (1) must be REAL >=20 > 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 comple= x. gfc_check_atan is invoked for this check. For atan(y,x), x and y must be w= ith real, and the result is the same as atan2(y,x).=20=20 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.=