aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2024-11-01 10:02:30 +0100
committerThomas Koenig <tkoenig@gcc.gnu.org>2024-11-01 16:13:08 +0100
commit9646a4cdc6266ab403ceeb6a40b93e72b0166941 (patch)
tree89f9232db9555653b8c77030e1ddd69cb2d380ca /gcc
parent7fdb66f0db6275118986ed8d77c94d6cfe5155c2 (diff)
downloadgcc-9646a4cdc6266ab403ceeb6a40b93e72b0166941.zip
gcc-9646a4cdc6266ab403ceeb6a40b93e72b0166941.tar.gz
gcc-9646a4cdc6266ab403ceeb6a40b93e72b0166941.tar.bz2
Fix -mod(unsigned, unsigned).
gcc/fortran/ChangeLog: * resolve.cc (resolve_operator): Also handle BT_UNSIGNED. gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_38.f90: Add -pedantic and adjust error message. * gfortran.dg/unsigned_40.f90: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/resolve.cc3
-rw-r--r--gcc/testsuite/gfortran.dg/unsigned_38.f904
-rw-r--r--gcc/testsuite/gfortran.dg/unsigned_40.f9019
3 files changed, 23 insertions, 3 deletions
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index b14d3e7..51e0af4 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -4253,7 +4253,8 @@ resolve_operator (gfc_expr *e)
case INTRINSIC_UMINUS:
if (op1->ts.type == BT_INTEGER
|| op1->ts.type == BT_REAL
- || op1->ts.type == BT_COMPLEX)
+ || op1->ts.type == BT_COMPLEX
+ || op1->ts.type == BT_UNSIGNED)
{
e->ts = op1->ts;
break;
diff --git a/gcc/testsuite/gfortran.dg/unsigned_38.f90 b/gcc/testsuite/gfortran.dg/unsigned_38.f90
index d549483..ac1cfb3 100644
--- a/gcc/testsuite/gfortran.dg/unsigned_38.f90
+++ b/gcc/testsuite/gfortran.dg/unsigned_38.f90
@@ -1,6 +1,6 @@
! { dg-do compile }
-! { dg-options "-funsigned" }
+! { dg-options "-funsigned -pedantic" }
program main
unsigned, parameter :: u = 7u
- print *,mod(-(u+1u),u) ! { dg-error "Operand of unary numeric operator" }
+ print *,mod(-(u+1u),u) ! { dg-error "Negation of unsigned expression" }
end program main
diff --git a/gcc/testsuite/gfortran.dg/unsigned_40.f90 b/gcc/testsuite/gfortran.dg/unsigned_40.f90
new file mode 100644
index 0000000..129fc88
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unsigned_40.f90
@@ -0,0 +1,19 @@
+! { dg-do run }
+! { dg-options "-funsigned" }
+program memain
+ use iso_fortran_env, only : uint8
+ call test1
+ call test2
+contains
+ subroutine test1
+ unsigned(uint8) :: nface, nmax
+ nface = 12u_1
+ nmax = - mod(-nface+1u,nface)
+ if (nmax /= 251u_1) error stop 1
+ end subroutine test1
+ subroutine test2
+ unsigned(uint8), parameter :: nface = 12u_1
+ unsigned(uint8), parameter :: nmax = - mod(-nface+1u,nface)
+ if (nmax /= 251u_1) error stop 11
+ end subroutine test2
+end program memain