From patchwork Thu Nov 21 11:05:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Eggleston X-Patchwork-Id: 1198899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514290-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="q4ISzFE5"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JcDY1Qjjz9sPf for ; Thu, 21 Nov 2019 22:05:46 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=ilg1Ar1KCtCLpr4cWdmR/+pdZhyiYD7+A1jMNEgfDc6n2vCYkL w9BrrYljhcRwIwwz/EejciPiwbQaiNszC3WiHxYE2YXIldV5WOMhbAKhFuRjEXr7 8wh18r6+/c/jcKlW/o5q3xUK6uWm9lMCmh3IynLo53z/q91WQiY6QdiGM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=r94CsgdChJIYQVhTjd+Dygp7oPE=; b=q4ISzFE5JnHA7NL/GEW5 a/DWbyK/OLDFbBNzKMhNkbKfrElPWrNgjGZFv96ZntknKFVo86YvZ16zF1Mkob2D mTZI1E9P9hk0MXrEiljBnmxoLdzHOJPr25N+49jPz8NnoGYk+KPFpGZ9ritc1SCC QBVOLTNB5Rx2xc+hZbOchow= Received: (qmail 103729 invoked by alias); 21 Nov 2019 11:05:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 103710 invoked by uid 89); 21 Nov 2019 11:05:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=H*F:D*co.uk, UD:co.uk, 2110, holleriths X-HELO: imap1.codethink.co.uk Received: from imap1.codethink.co.uk (HELO imap1.codethink.co.uk) (176.9.8.82) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Nov 2019 11:05:30 +0000 Received: from [167.98.27.226] (helo=[10.35.5.172]) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1iXkH5-0003jn-5P; Thu, 21 Nov 2019 11:05:23 +0000 To: gcc-patches , fortran Cc: Steve Kargl , Jeff Law , toon@moene.org, Thomas Koenig From: Mark Eggleston Subject: [Patch, Fortran] dec comparisons - for approval Message-ID: <30913a8a-4605-f97e-d247-3d38ee98094c@codethink.co.uk> Date: Thu, 21 Nov 2019 11:05:22 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 Please find attached an updated version of the patch originally submitted on 15th November. The comparisons with Holleriths are no only possible when using -fdec. The test cases have been revised to check for errors when -fdec is not used. OK to commit in stage 3 or delay until stage 1 in the new year? Change logs: gcc/fortran     Mark Eggleston      Jim MacArthur      * gfortran.texi: Update Hollerith constants support for character types     and use in comparisons.     * invoke.texi: Tidy up list of options. Update description of     -fdec-char-conversions.     * resolve.c (is_character_based): New.     (Convert_hollerith_to_character): New.  (convert_to_numeric): New.     (resolve_operator): If both sides are character based and -fdec is     enabled convert Hollerith to character. If an operand is Hollerith, the     other is numeric and -fdec is enabled convert to numeric.     (resolve_ordinary_assign): Add check for -fdec-char-conversions for     assignment of character literals. gcc/testsuite     Mark Eggleston     Jim MacArthur     * gfortran.dg/dec-comparison-character_1.f90: New test.     * gfortran.dg/dec-comparison-character_2.f90: New test.     * gfortran.dg/dec-comparison-character_3.f90: New test.     * gfortran.dg/dec-comparison-complex_1.f90: New test.     * gfortran.dg/dec-comparison-complex_2.f90: New test.     * gfortran.dg/dec-comparison-complex_3.f90: New test.     * gfortran.dg/dec-comparison-int_1.f90: New test.     * gfortran.dg/dec-comparison-int_2.f90: New test.     * gfortran.dg/dec-comparison-int_3.f90: New test.     * gfortran.dg/dec-comparison-real_1.f90: New test.     * gfortran.dg/dec-comparison-real_2.f90: New test.     * gfortran.dg/dec-comparison-real_3.f90: New test.     * gfortran.dg/dec-comparison.f90: New test. From 2fc6d83614d7f58620a9a9662e9972b5d4018ed1 Mon Sep 17 00:00:00 2001 From: Mark Eggleston Date: Thu, 23 May 2019 09:42:26 +0100 Subject: [PATCH] dec comparisons Allow comparison of Hollerith constants with numeric and character expressions. Also allow comparison of character literalsa with numeric expressions. Enable using -fdec-comparisons or -fdec --- gcc/fortran/gfortran.texi | 32 +++++++++---- gcc/fortran/invoke.texi | 24 +++++----- gcc/fortran/resolve.c | 54 +++++++++++++++++++++- .../gfortran.dg/dec-comparison-character_1.f90 | 18 ++++++++ .../gfortran.dg/dec-comparison-character_2.f90 | 18 ++++++++ .../gfortran.dg/dec-comparison-character_3.f90 | 26 +++++++++++ .../gfortran.dg/dec-comparison-complex_1.f90 | 17 +++++++ .../gfortran.dg/dec-comparison-complex_2.f90 | 14 ++++++ .../gfortran.dg/dec-comparison-complex_3.f90 | 18 ++++++++ gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90 | 22 +++++++++ gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90 | 18 ++++++++ gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90 | 26 +++++++++++ .../gfortran.dg/dec-comparison-real_1.f90 | 22 +++++++++ .../gfortran.dg/dec-comparison-real_2.f90 | 18 ++++++++ .../gfortran.dg/dec-comparison-real_3.f90 | 26 +++++++++++ gcc/testsuite/gfortran.dg/dec-comparison.f90 | 41 ++++++++++++++++ 16 files changed, 371 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison.f90 diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index a34ac5aa1bf..96be58b992d 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -1916,14 +1916,14 @@ in I/O operations. @subsection Hollerith constants support @cindex Hollerith constants -GNU Fortran supports Hollerith constants in assignments, function -arguments, and @code{DATA} statements. A Hollerith constant is written -as a string of characters preceded by an integer constant indicating the -character count, and the letter @code{H} or @code{h}, and stored in -bytewise fashion in a numeric (@code{INTEGER}, @code{REAL}, or -@code{COMPLEX}) or @code{LOGICAL} variable. The constant will be padded -with spaces or truncated to fit the size of the variable in which it is -stored. +GNU Fortran supports Hollerith constants in assignments, @code{DATA} +statements, function and subroutine arguments. A Hollerith constant is +written as a string of characters preceded by an integer constant +indicating the character count, and the letter @code{H} or +@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER}, +@code{REAL}, or @code{COMPLEX}), @code{LOGICAL} or @code{CHARACTER} variable. +The constant will be padded with spaces or truncated to fit the size of +the variable in which it is stored. Examples of valid uses of Hollerith constants: @smallexample @@ -1951,10 +1951,22 @@ case where the intent is specifically to initialize a numeric variable with a given byte sequence. In these cases, the same result can be obtained by using the @code{TRANSFER} statement, as in this example. @smallexample - INTEGER(KIND=4) :: a - a = TRANSFER ("abcd", a) ! equivalent to: a = 4Habcd + integer(kind=4) :: a + a = transfer ("abcd", a) ! equivalent to: a = 4Habcd @end smallexample +The use of the @option{-fdec} option extends support of Hollerith constants +to comparisons: +@smallexample + integer*4 a + a = 4hABCD + if (a .ne. 4habcd) then + write(*,*) "no match" + end if +@end smallexample + +Supported types are numeric (@code{INTEGER}, @code{REAL}, or @code{COMPLEX}), +and @code{CHARACTER}. @node Character conversion @subsection Character conversion diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 46ee3c9241b..0bc054f01e5 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -117,17 +117,17 @@ by type. Explanations are in the following sections. @item Fortran Language Options @xref{Fortran Dialect Options,,Options controlling Fortran dialect}. @gccoptlist{-fall-intrinsics -fallow-argument-mismatch -fallow-invalid-boz @gol --fbackslash -fcray-pointer -fd-lines-as-code -fd-lines-as-comments -fdec @gol --fdec-char-conversions -fdec-structure -fdec-intrinsic-ints -fdec-static @gol --fdec-math -fdec-include -fdec-format-defaults -fdec-blank-format-item @gol --fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 -fdefault-real-10 @gol --fdefault-real-16 -fdollar-ok -ffixed-line-length-@var{n} @gol --ffixed-line-length-none -fpad-source -ffree-form @gol --ffree-line-length-@var{n} -ffree-line-length-none -fimplicit-none @gol --finteger-4-integer-8 -fmax-identifier-length -fmodule-private @gol --ffixed-form -fno-range-check -fopenacc -fopenmp -freal-4-real-10 @gol --freal-4-real-16 -freal-4-real-8 -freal-8-real-10 -freal-8-real-16 @gol --freal-8-real-4 -std=@var{std} -ftest-forall-temp +-fbackslash -fcray-pointer -fd-lines-as-code -fd-lines-as-comments @gol +-fdec -fdec-char-conversions -fdec-structure -fdec-intrinsic-ints @gol +-fdec-static -fdec-math -fdec-include -fdec-format-defaults @gol +-fdec-blank-format-item -fdefault-double-8 -fdefault-integer-8 @gol +-fdefault-real-8 -fdefault-real-10 -fdefault-real-16 -fdollar-ok @gol +-ffixed-line-length-@var{n} -ffixed-line-length-none -fpad-source @gol +-ffree-form -ffree-line-length-@var{n} -ffree-line-length-none @gol +-fimplicit-none -finteger-4-integer-8 -fmax-identifier-length @gol +-fmodule-private -ffixed-form -fno-range-check -fopenacc -fopenmp @gol +-freal-4-real-10 -freal-4-real-16 -freal-4-real-8 -freal-8-real-10 @gol +-freal-8-real-16 -freal-8-real-4 -std=@var{std} -ftest-forall-temp } @item Preprocessing Options @@ -283,7 +283,7 @@ If @option{-fd-lines-as-code}/@option{-fd-lines-as-comments} are unset, then @item -fdec-char-conversions @opindex @code{fdec-char-conversions} -Enable the use of character literals in assignments and data statements +Enable the use of character literals in assignments and @code{DATA} statements for non-character variables. @item -fdec-structure diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 2371a9e201f..278dad363fd 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -3900,6 +3900,42 @@ impure_function_callback (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED, return 0; } +/* Return true if TYPE is character based, false otherwise. */ + +static int +is_character_based (bt type) +{ + return type == BT_CHARACTER || type == BT_HOLLERITH; +} + + +/* If expression is a hollerith, convert it to character and issue a warning + for the conversion. */ + +static void +convert_hollerith_to_character (gfc_expr *e) +{ + if (e->ts.type == BT_HOLLERITH) + { + gfc_typespec t; + gfc_clear_ts (&t); + t.type = BT_CHARACTER; + t.kind = e->ts.kind; + gfc_convert_type_warn (e, &t, 2, 1); + } +} + +/* Convert to numeric and issue a warning for the conversion. */ + +static void +convert_to_numeric (gfc_expr *a, gfc_expr *b) +{ + gfc_typespec t; + gfc_clear_ts (&t); + t.type = b->ts.type; + t.kind = b->ts.kind; + gfc_convert_type_warn (a, &t, 2, 1); +} /* Resolve an operator expression node. This can involve replacing the operation with a user defined function call. */ @@ -4100,6 +4136,15 @@ resolve_operator (gfc_expr *e) case INTRINSIC_EQ_OS: case INTRINSIC_NE: case INTRINSIC_NE_OS: + + if (flag_dec + && is_character_based (op1->ts.type) + && is_character_based (op2->ts.type)) + { + convert_hollerith_to_character (op1); + convert_hollerith_to_character (op2); + } + if (op1->ts.type == BT_CHARACTER && op2->ts.type == BT_CHARACTER && op1->ts.kind == op2->ts.kind) { @@ -4137,6 +4182,13 @@ resolve_operator (gfc_expr *e) if (op1->ts.type == BT_REAL && !gfc_boz2real (op2, op1->ts.kind)) return false; } + if (flag_dec + && op1->ts.type == BT_HOLLERITH && gfc_numeric_ts (&op2->ts)) + convert_to_numeric (op1, op2); + + if (flag_dec + && gfc_numeric_ts (&op1->ts) && op2->ts.type == BT_HOLLERITH) + convert_to_numeric (op2, op1); if (gfc_numeric_ts (&op1->ts) && gfc_numeric_ts (&op2->ts)) { @@ -10693,7 +10745,7 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns) if ((gfc_numeric_ts (&lhs->ts) || lhs->ts.type == BT_LOGICAL) && rhs->ts.type == BT_CHARACTER - && rhs->expr_type != EXPR_CONSTANT) + && (rhs->expr_type != EXPR_CONSTANT || !flag_dec_char_conversions)) { /* Use of -fdec-char-conversions allows assignment of character data to non-character variables. This not permited for nonconstant diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90 new file mode 100644 index 00000000000..0e542e8354b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! { dg-options "-fdec" } +! +! Test case contributed by Mark Eggleston +! + +program convert + character(4) :: c = 4HJMAC + if (4HJMAC.ne.4HJMAC) stop 1 + if (4HJMAC.ne."JMAC") stop 2 + if (4HJMAC.eq."JMAN") stop 3 + if ("JMAC".eq.4HJMAN) stop 4 + if ("AAAA".eq.5HAAAAA) stop 5 + if ("BBBBB".eq.5HBBBB ) stop 6 + if (4HJMAC.ne.c) stop 7 + if (c.ne.4HJMAC) stop 8 +end program + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90 new file mode 100644 index 00000000000..d35eaad17e1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! { dg-options "-fdec -Wconversion" } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-character_1.f90" + +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 8 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 9 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 10 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 11 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 12 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 13 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 14 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 15 } +! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 16 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90 new file mode 100644 index 00000000000..adbb554bfbe --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-character_1.f90" + +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 8 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 9 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 10 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 11 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 12 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 13 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 14 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 15 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 16 } +! { dg-warning "Extension: Conversion from HOLLERITH to CHARACTER" " " { target *-*-* } 8 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 9 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 10 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 11 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 12 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 13 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 14 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 15 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 16 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90 new file mode 100644 index 00000000000..4bbb9a18b88 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90 @@ -0,0 +1,17 @@ +! { dg-do run } +! { dg-options "-fdec" } +! +! Test case contributed by Mark Eggleston +! + +program convert + complex(4) :: a + complex(4) :: b + a = 8HABCDABCD + b = transfer("ABCDABCD", b); + ! Hollerith constants + if (a.ne.8HABCDABCD) stop 1 + if (a.eq.8HABCEABCE) stop 2 + if (8HABCDABCD.ne.b) stop 3 + if (8HABCEABCE.eq.b) stop 4 +end program diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90 new file mode 100644 index 00000000000..82372095362 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90 @@ -0,0 +1,14 @@ +! { dg-do run } +! { dg-options "-fdec -Wconversion" } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-complex_1.f90" + +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 10 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 13 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 14 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 15 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 16 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90 new file mode 100644 index 00000000000..9af12d9f8a0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-complex_1.f90" + +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 10 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 13 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 14 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 15 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 16 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 10 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 13 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 14 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 15 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 16 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90 new file mode 100644 index 00000000000..257cc1ddef7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90 @@ -0,0 +1,22 @@ +! { dg-do run } +! { dg-options "-fdec" } +! +! Test case contributed by Mark Eggleston +! + +program convert + integer(4) :: a + integer(4) :: b + a = 4HABCD + b = transfer("ABCD", b) + ! Hollerith constants + if (a.ne.4HABCD) stop 1 + if (a.eq.4HABCE) stop 2 + if (4HABCD.ne.b) stop 3 + if (4HABCE.eq.b) stop 4 + if (4HABCE.lt.a) stop 5 + if (a.gt.4HABCE) stop 6 + if (4HABCE.le.a) stop 7 + if (a.ge.4HABCE) stop 8 +end program + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90 new file mode 100644 index 00000000000..10d00071f22 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! { dg-options "-fdec -Wconversion" } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-int_1.f90" + +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 10 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 13 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 14 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 15 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 16 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 17 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 18 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 19 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 20 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90 new file mode 100644 index 00000000000..bf17272676e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-int_1.f90" + +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 10 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 13 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 14 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 15 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 16 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 17 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 18 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 19 } +! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 20 } +! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 10 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 13 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 14 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 15 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 16 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 17 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 18 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 19 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 20 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90 new file mode 100644 index 00000000000..a8d08e952cb --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90 @@ -0,0 +1,22 @@ +! { dg-do run } +! { dg-options "-fdec" } +! +! Test case contributed by Mark Eggleston +! + +program convert + real(4) :: a + real(4) :: b + a = 4HABCD + b = transfer("ABCD", b) + ! Hollerith constants + if (a.ne.4HABCD) stop 1 + if (a.eq.4HABCE) stop 2 + if (4HABCD.ne.b) stop 3 + if (4HABCE.eq.b) stop 4 + if (4HABCE.lt.a) stop 5 + if (a.gt.4HABCE) stop 6 + if (4HABCE.le.a) stop 7 + if (a.ge.4HABCE) stop 8 +end program + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90 new file mode 100644 index 00000000000..9b65901b92f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! { dg-options "-fdec -Wconversion" } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-real_1.f90" + +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 10 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 13 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 14 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 15 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 16 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 17 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 18 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 19 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 20 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90 new file mode 100644 index 00000000000..1c2d496f9f0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! +! Test case contributed by Mark Eggleston +! + +include "dec-comparison-real_1.f90" + +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 10 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 13 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 14 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 15 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 16 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 17 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 18 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 19 } +! { dg-warning "Legacy Extension: Hollerith constant at" " " { target *-*-* } 20 } +! { dg-warning "Conversion from HOLLERITH" " " { target *-*-* } 10 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 13 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 14 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 15 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 16 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 17 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 18 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 19 } +! { dg-error "Operands of comparison operator" " " { target *-*-* } 20 } + diff --git a/gcc/testsuite/gfortran.dg/dec-comparison.f90 b/gcc/testsuite/gfortran.dg/dec-comparison.f90 new file mode 100644 index 00000000000..b0b28e55111 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec-comparison.f90 @@ -0,0 +1,41 @@ +! { dg-do run } +! { dg-options "-fdec" } +! +! Test case contributed by Mark Eggleston +! +! Hollerith constants and character literals are allowed in comparisons, +! check that character variables can not be compared with numeric variables. + +program convert + character(4) :: a = 4hJMAC + integer(4) :: b = "JMAC" + real(4) :: c = "JMAC" + complex(4) :: d = "JMACJMAC" + ! integers + if (a.ne.b) stop 1 ! { dg-error "Operands of comparison" } + if (b.eq.a) stop 2 ! { dg-error "Operands of comparison" } + if (a.ge.b) stop 3 ! { dg-error "Operands of comparison" } + if (b.ge.a) stop 4 ! { dg-error "Operands of comparison" } + if (a.gt.b) stop 5 ! { dg-error "Operands of comparison" } + if (b.gt.a) stop 6 ! { dg-error "Operands of comparison" } + if (a.le.b) stop 3 ! { dg-error "Operands of comparison" } + if (b.le.a) stop 4 ! { dg-error "Operands of comparison" } + if (a.lt.b) stop 5 ! { dg-error "Operands of comparison" } + if (b.lt.a) stop 6 ! { dg-error "Operands of comparison" } + ! reals + if (a.ne.c) stop 7 ! { dg-error "Operands of comparison" } + if (c.eq.a) stop 8 ! { dg-error "Operands of comparison" } + if (a.ge.c) stop 9 ! { dg-error "Operands of comparison" } + if (c.ge.a) stop 10 ! { dg-error "Operands of comparison" } + if (a.gt.c) stop 11 ! { dg-error "Operands of comparison" } + if (c.gt.a) stop 12 ! { dg-error "Operands of comparison" } + if (a.le.c) stop 13 ! { dg-error "Operands of comparison" } + if (c.le.a) stop 14 ! { dg-error "Operands of comparison" } + if (a.lt.c) stop 15 ! { dg-error "Operands of comparison" } + if (c.lt.a) stop 16 ! { dg-error "Operands of comparison" } + ! complexes + a = "JMACJMAC" + if (a.ne.d) stop 17 ! { dg-error "Operands of comparison" } + if (d.eq.a) stop 18 ! { dg-error "Operands of comparison" } +end program + -- 2.11.0