From patchwork Sat Nov 9 16:53:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 2009087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.a=rsa-sha256 header.s=nc1116a header.b=NKFxRXjE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xm23427Vlz1xyp for ; Sun, 10 Nov 2024 03:54:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 553E73858D26 for ; Sat, 9 Nov 2024 16:54:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout3.netcologne.de (cc-smtpout3.netcologne.de [89.1.8.213]) by sourceware.org (Postfix) with ESMTPS id C578F3858D20; Sat, 9 Nov 2024 16:53:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C578F3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=netcologne.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=netcologne.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C578F3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.1.8.213 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1731171221; cv=none; b=aFfwKDZtQKoL+Xc3GWnKUvDacmft24goC6wfuS+6wSegbBxFsF+Q7+NHDjvzlv0gVgCLytL+k0MNQ9CRx2fD0FJtqw9R3R8qOjVk2fhKXqYOwwGY+2xeMel/qS8fWKj4Mx390+9cG8Vr6pOHElYvas+XsqzgH71f9QcA4Dybt4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1731171221; c=relaxed/simple; bh=OwpX/aBL8KAHrFqCpSAODVsdjI7i70BZftqVpN9994E=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=rMuEYp2UcEuyvowEovq0ypQaBQdaloszgEt/ihmSU1MZfZqFi/yYlC9/78brpmbVdOJaDg2bu29rk8F+XMZrGm5/oiLYA5zSVJZF9xN/OEQHDhQdZWt2ckzWCTC3lC/Qa2c4ijKgigO6ZCeIHDBvybu607wcYenESJgHaNgzrN0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 64A561208A; Sat, 9 Nov 2024 17:53:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1731171217; bh=OwpX/aBL8KAHrFqCpSAODVsdjI7i70BZftqVpN9994E=; h=Message-ID:Date:To:From:Subject:From; b=NKFxRXjEXwQNL7xD4iTxXQciHs0M2+lTWvBSlIHheT8Qu0HIjjd5YfT0n66mfp20w h6WX0Ug9hD0bVSi6Xrwno1WE8QFwAFe8jPiiLE04sySno5jURscvHNFqnzAu70bTqd J/FjaHYcdlhezlFmGejZiZ9U1Zb7EO7EYrK1xrP+HtyaFfjQVjP2ZEI+AT+BpfBTPO 9bLfSHNgMgaBVrM7LzshBPMpbS4ThOArSW1TECz/bge7VJAvI5wynvotnTkomrGJk3 iBrW6jujpLcuCqk7CQd4S3xGb106qUi/tNEA0y6okh5EmyjwvNQZX9o6KD/OVb3LFS y0HNWdLGqydoQ== Received: from [IPV6:2001:4dd7:55bc:0:875f:2ceb:48cb:d807] (2001-4dd7-55bc-0-875f-2ceb-48cb-d807.ipv6dyn.netcologne.de [IPv6:2001:4dd7:55bc:0:875f:2ceb:48cb:d807]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA id 23B7211E22; Sat, 9 Nov 2024 17:53:35 +0100 (CET) Message-ID: Date: Sat, 9 Nov 2024 17:53:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US, de-DE To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, Fortran] Reject UNSIGNED for COMPLEX X-NetCologne-Spam: L X-Rspamd-Queue-Id: 23B7211E22 X-Spamd-Bar: / X-Rspamd-Action: no action X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hello world, the attached patch rejects UNSIGNED arguments for the COMPLEX function, which is an extension. It also documents CMPLX, INT and REAL as taking UNSIGNED arguments. Regression-tested. OK for trunk? Best regards Thomas gcc/fortran/ChangeLog: * check.cc (gfc_check_complex): Reject UNSIGNED. * gfortran.texi: Update example program. Note that CMPLX, INT and REAL also take unsigned arguments. * intrinsic.texi (CMPLX): Document UNSIGNED. (INT): Likewise. (REAL): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_41.f90: New test. diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc index 2d4af8e7df3..5c7fe342262 100644 --- a/gcc/fortran/check.cc +++ b/gcc/fortran/check.cc @@ -2606,6 +2606,23 @@ gfc_check_complex (gfc_expr *x, gfc_expr *y) if (!boz_args_check (x, y)) return false; + /* COMPLEX is an extension, we do not want UNSIGNED there. */ + if (x->ts.type == BT_UNSIGNED) + { + gfc_error ("%qs argument of %qs intrinsic at %L shall not be " + "UNSIGNED", gfc_current_intrinsic_arg[0]->name, + gfc_current_intrinsic, &x->where); + return false; + } + + if (y->ts.type == BT_UNSIGNED) + { + gfc_error ("%qs argument of %qs intrinsic at %L shall not be " + "UNSIGNED", gfc_current_intrinsic_arg[1]->name, + gfc_current_intrinsic, &y->where); + return false; + } + if (x->ts.type == BT_BOZ) { if (gfc_invalid_boz (G_("BOZ constant at %L cannot appear in the COMPLEX" diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 429d8461f8f..00276b5b45d 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -2750,8 +2750,9 @@ and @code{Z} descriptors, plus unformatted I/O. Here is a small, somewhat contrived example of their use: @smallexample program main - unsigned(kind=8) :: v - v = huge(v) - 32u_8 + use iso_fortran_env, only : uint64 + unsigned(kind=uint64) :: v + v = huge(v) - 32u_uint64 print *,v end program main @end smallexample @@ -2780,6 +2781,7 @@ The following intrinsics take unsigned arguments: @item @code{BLE}, @pxref{BLE} @item @code{BLT}, @pxref{BLT} @item @code{CSHIFT}, @pxref{CSHIFT} +@item @code{CMPLX}, @pxref{CMPLX} @item @code{DIGITS}, @pxref{DIGITS} @item @code{DOT_PRODUCT}, @pxref{DOT_PRODUCT} @item @code{DSHIFTL}, @pxref{DSHIFTL} @@ -2794,6 +2796,7 @@ The following intrinsics take unsigned arguments: @item @code{IBITS}, @pxref{IBITS} @item @code{IBSET}, @pxref{IBSET} @item @code{IEOR}, @pxref{IEOR} +@item @code{INT}, @pxref{INT} @item @code{IOR}, @pxref{IOR} @item @code{IPARITY}, @pxref{IPARITY} @item @code{ISHFT}, @pxref{ISHFT} @@ -2814,6 +2817,7 @@ The following intrinsics take unsigned arguments: @item @code{PRODUCT}, @pxref{PRODUCT} @item @code{RANDOM_NUMBER}, @pxref{RANDOM_NUMBER} @item @code{RANGE}, @pxref{RANGE} +@item @code{REAL}, @pxref{REAL} @item @code{SHIFTA}, @pxref{SHIFTA} @item @code{SHIFTL}, @pxref{SHIFTL} @item @code{SHIFTR}, @pxref{SHIFTR} diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index 9d0b752670b..d11d37761d9 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -3626,7 +3626,8 @@ component. If @var{Y} is not present then the imaginary component is set to 0.0. If @var{X} is complex then @var{Y} must not be present. @item @emph{Standard}: -Fortran 77 and later +Fortran 77 and later, extension for @code{UNSIGNED} (@pxref{Unsigned +integers}) @item @emph{Class}: Elemental function @@ -3637,9 +3638,9 @@ Elemental function @item @emph{Arguments}: @multitable @columnfractions .15 .70 @item @var{X} @tab The type may be @code{INTEGER}, @code{REAL}, -or @code{COMPLEX}. +@code{COMPLEX} or @code{UNSIGNED}. @item @var{Y} @tab (Optional; only allowed if @var{X} is not -@code{COMPLEX}.) May be @code{INTEGER} or @code{REAL}. +@code{COMPLEX}.) May be @code{INTEGER}, @code{REAL} or @code{UNSIGNED}. @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant expression indicating the kind parameter of the result. @end multitable @@ -8355,7 +8356,8 @@ Convert to integer type Fortran 77 and later, with boz-literal-constant Fortran 2008 and later. @item @emph{Class}: -Elemental function +Elemental function, extension for @code{UNSIGNED} (@pxref{Unsigned +integers}). @item @emph{Syntax}: @code{RESULT = INT(A [, KIND))} @@ -8386,7 +8388,6 @@ If @var{A} is of type @code{COMPLEX}, rule B is applied to the real part of @var If @var{A} is of type @code{UNSIGNED} and @math{0 \leq A \leq} @code{HUGE(A)}, @code{INT(A) = A}. Outside that range, the result is interpreted using two's complement. - @end table @item @emph{Example}: @@ -12287,7 +12288,10 @@ end program test_rank and its use is strongly discouraged. @item @emph{Standard}: -Fortran 77 and later, with @var{KIND} argument Fortran 90 and later, has GNU extensions +Fortran 77 and later, with @var{KIND} argument Fortran 90 and later, +has GNU extensions. Extension for @code{UNSIGNED} (@pxref{Unsigned +integers}). + @item @emph{Class}: Elemental function @@ -12300,8 +12304,8 @@ Elemental function @item @emph{Arguments}: @multitable @columnfractions .15 .70 -@item @var{A} @tab Shall be @code{INTEGER}, @code{REAL}, or -@code{COMPLEX}. +@item @var{A} @tab Shall be @code{INTEGER}, @code{REAL}, +@code{COMPLEX} or @code{UNSIGNED}. @item @var{KIND} @tab (Optional) A scalar @code{INTEGER} constant expression indicating the kind parameter of the result. @end multitable @@ -12313,14 +12317,14 @@ the following rules: @table @asis @item (A) @code{REAL(A)} is converted to a default real type if @var{A} is an -integer or real variable. +integer, real or unsigned variable. @item (B) @code{REAL(A)} is converted to a real type with the kind type parameter of @var{A} if @var{A} is a complex variable. @item (C) @code{REAL(A, KIND)} is converted to a real type with kind type -parameter @var{KIND} if @var{A} is a complex, integer, or real -variable. +parameter @var{KIND} if @var{A} is a complex, integer, real +or unsigned variable. @end table @item @emph{Example}: diff --git a/gcc/testsuite/gfortran.dg/unsigned_41.f90 b/gcc/testsuite/gfortran.dg/unsigned_41.f90 new file mode 100644 index 00000000000..11a5d7b175a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unsigned_41.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! { dg-options "-funsigned" } +program memain + unsigned :: a + a = 1u + print *,complex(1.0,a) ! { dg-error "shall not be UNSIGNED" } + print *,complex(a,1.0) ! { dg-error "shall not be UNSIGNED" } +end program memain