public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: HAO CHEN GUI <guihaoc@linux.ibm.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	fortran <fortran@gcc.gnu.org>
Cc: Segher Boessenkool <segher@kernel.crashing.org>,
	David <dje.gcc@gmail.com>, Kewen.Lin <linkw@linux.ibm.com>,
	Peter Bergner <bergner@linux.ibm.com>
Subject: Re: [PATCHv2, gfortran] Escalate failure when Hollerith constant to real conversion fails [PR103628]
Date: Fri, 3 Mar 2023 10:29:52 +0100	[thread overview]
Message-ID: <5049d46a-5edb-42c1-798a-b21410f6bdc0@codesourcery.com> (raw)
In-Reply-To: <a59a7554-9f0a-e0ff-5666-629c66174e9a@linux.ibm.com>

Hi Haochen,

thanks for fixing 'gcc/fortran/target-memory.cc'.

But could you also include the 'gcc/fortran/intrinsic.cc' change
proposed in
https://gcc.gnu.org/pipermail/gcc-patches/2023-March/613030.html (and
acknowledged by Steve)?

This will replace "Unclassifiable statement" by "Cannot simplify
expression" which is a bit more helpful.

(After doing so, at least the dg-error in your testcase needs to be
updated; I assume that it won't affect other testcases, but that needs
to be checked. – And you should update the comment in the testcase as
well - and in text you will put in the commit log, if applicable.)

Additionally, Kewen suggested:
> Since this test case is powerpc only, I think it can be moved to gcc/testsuite/gcc.target/powerpc/ppc-fortran.

Which sounds reasonable.


Otherwise it looks good to me.

On 03.03.23 10:12, HAO CHEN GUI wrote:
> Hi,
>    The patch escalates the failure when Hollerith constant to real conversion
> fails in native_interpret_expr. It finally reports an "Unclassifiable
> statement" error.
>
>    The patch of pr95450 added a verification for decoding/encoding checking
> in native_interpret_expr. native_interpret_expr may fail on real type
> conversion and returns a NULL tree then. But upper layer calls don't handle
> the failure so that an ICE is reported when the verification fails.
>
>    IBM long double is an example. It doesn't have a unique memory presentation
> for some real values. So it may not pass the verification. The new test
> case shows the problem.
>
>    Compared to last version, this version moves the mpfr_init after NULL tree
> test and fixes the format problem according to Tobias's advice. Thanks a lot.

(The format issue was actually spotted by Bernhard.)

Thanks for working on this!

Tobias

PS: One can also discuss Steve's suggestion about deprecating Holleriths / guarding
the support behind some flag. But I think that's unrelated to this bug fix patch and
should be discussed/done separately.


> ChangeLog
> 2023-03-01  Haochen Gui <guihaoc@linux.ibm.com>
>
> gcc/
>       PR target/103628
>       * fortran/target-memory.cc (gfc_interpret_float): Return FAIL when
>       native_interpret_expr gets a NULL tree.
>       * fortran/arith.cc (gfc_hollerith2real): Return NULL when
>       gfc_interpret_float fails.
>
> gcc/testsuite/
>       PR target/103628
>       * gfortran.dg/pr103628.f90: New.
>
> patch.diff
> diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
> index c0d12cfad9d..d3d38c7eb6a 100644
> --- a/gcc/fortran/arith.cc
> +++ b/gcc/fortran/arith.cc
> @@ -2752,10 +2752,12 @@ gfc_hollerith2real (gfc_expr *src, int kind)
>     result = gfc_get_constant_expr (BT_REAL, kind, &src->where);
>
>     hollerith2representation (result, src);
> -  gfc_interpret_float (kind, (unsigned char *) result->representation.string,
> -                    result->representation.length, result->value.real);
> -
> -  return result;
> +  if (gfc_interpret_float (kind,
> +                        (unsigned char *) result->representation.string,
> +                        result->representation.length, result->value.real))
> +    return result;
> +  else
> +    return NULL;
>   }
>
>   /* Convert character to real.  The constant will be padded or truncated.  */
> diff --git a/gcc/fortran/target-memory.cc b/gcc/fortran/target-memory.cc
> index 7ce7d736629..0c47aa6b842 100644
> --- a/gcc/fortran/target-memory.cc
> +++ b/gcc/fortran/target-memory.cc
> @@ -416,11 +416,14 @@ gfc_interpret_float (int kind, unsigned char *buffer, size_t buffer_size,
>                    mpfr_t real)
>   {
>     gfc_set_model_kind (kind);
> -  mpfr_init (real);
> -  gfc_conv_tree_to_mpfr (real,
> -                      native_interpret_expr (gfc_get_real_type (kind),
> -                                             buffer, buffer_size));
>
> +  tree source = native_interpret_expr (gfc_get_real_type (kind), buffer,
> +                                    buffer_size);
> +  if (!source)
> +    return 0;
> +
> +  mpfr_init (real);
> +  gfc_conv_tree_to_mpfr (real, source);
>     return size_float (kind);
>   }
>
> diff --git a/gcc/testsuite/gfortran.dg/pr103628.f90 b/gcc/testsuite/gfortran.dg/pr103628.f90
> new file mode 100644
> index 00000000000..e49aefc18fd
> --- /dev/null
> +++ b/gcc/testsuite/gfortran.dg/pr103628.f90
> @@ -0,0 +1,14 @@
> +! { dg-do compile { target powerpc*-*-* } }
> +! { dg-options "-O2 -mabi=ibmlongdouble" }
> +
> +! Test to ensure that it reports an "Unclassifiable statement" error
> +! instead of throwing an ICE when the memory represent of the HOLLERITH
> +! string is not unique with ibm long double encoding.
> +
> +program main
> +  integer, parameter :: k = 16
> +  real(kind = k):: b = 4h1234
> +end program main
> +
> +! { dg-warning "Conversion from HOLLERITH" "warning" { target powerpc*-*-* } 10 }
> +! { dg-error "Unclassifiable statement" "error" { target powerpc*-*-* } 10 }
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

  parent reply	other threads:[~2023-03-03  9:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-03  9:12 HAO CHEN GUI
2023-03-03  9:16 ` HAO CHEN GUI
2023-03-03  9:29 ` Tobias Burnus [this message]
2023-03-03  9:56   ` HAO CHEN GUI
2023-03-03 12:54     ` Tobias Burnus
2023-03-06  9:35       ` Kewen.Lin

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=5049d46a-5edb-42c1-798a-b21410f6bdc0@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=guihaoc@linux.ibm.com \
    --cc=linkw@linux.ibm.com \
    --cc=segher@kernel.crashing.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).