public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: Richard Biener <richard.guenther@gmail.com>,
	Thomas Koenig <tkoenig@netcologne.de>,
	Toon Moene <toon@moene.org>
Cc: gcc mailing list <gcc@gcc.gnu.org>,
	gfortran <fortran@gcc.gnu.org>, Jeff Law <jeffreyalaw@gmail.com>
Subject: Re: Test with an lto-build of libgfortran.
Date: Thu, 28 Sep 2023 09:29:02 +0200	[thread overview]
Message-ID: <fe708d35-0bb3-4aeb-baac-aad2812ece5d@codesourcery.com> (raw)
In-Reply-To: <CAFiYyc3Av5-Tvoz7iZjV0FsOvbqBO-dYq7Ena-rR6Nst0MP_MA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]

Hi all,

the following works for me. I have only tried a normal build (where it
does silence the same warning) and not an LTO build and I just believed
the comment - see attached patch. Comments?

On 28.09.23 08:25, Richard Biener via Fortran wrote:

> This particular place in libgfortran has
>
>    /* write_z, which calls xtoa_big, is called from transfer.c,
>       formatted_transfer_scalar_write.  There it is passed the kind as
>       argument, which means a maximum of 16.  The buffer is large
>       enough, but the compiler does not know that, so shut up the
>       warning here.  */
> #pragma GCC diagnostic push
> #pragma GCC diagnostic ignored "-Wstringop-overflow"
>    *q = '\0';
> #pragma GCC diagnostic pop
>
> so obviously the #pragma doesn't survive through LTO.  Somehow I think
> this is a known bug, but maybe I misremember (I think we are not streaming
> any of the ad-hoc location parts).

I have replaced it now by the assert that "len <= 16", i.e.

+  if (len > 16)
+    __builtin_unreachable ();

Build + tested on x86-64-gnu-linux
Comment? OK for mainline?

Tobias
-----------------
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

[-- Attachment #2: xtoa_big-silence-warning.diff --]
[-- Type: text/x-patch, Size: 1583 bytes --]

libgfortran: Use __builtin_unreachable() not -Wno-stringop-overflow to silence warning

libgfortran/
	* io/write.c (xtoa_big): Change a 'GCC diagnostic ignored
	"-Wstringop-overflow"' to an assumption (via __builtin_unreachable).

 libgfortran/io/write.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 5d47a6d25f7..00c8fd2e288 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -1179,6 +1179,15 @@ xtoa_big (const char *s, char *buffer, int len, GFC_UINTEGER_LARGEST *n)
   uint8_t h, l;
   int i;
 
+  /* write_z, which calls xtoa_big, is called from transfer.c,
+     formatted_transfer_scalar_write.  There it is passed the kind as
+     'len' argument, which means a maximum of 16.  The buffer is large
+     enough, but the compiler does not know that, so shut up the
+     warning here.  */
+
+  if (len > 16)
+    __builtin_unreachable ();
+
   q = buffer;
 
   if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
@@ -1212,15 +1221,7 @@ xtoa_big (const char *s, char *buffer, int len, GFC_UINTEGER_LARGEST *n)
 	}
     }
 
-  /* write_z, which calls xtoa_big, is called from transfer.c,
-     formatted_transfer_scalar_write.  There it is passed the kind as
-     argument, which means a maximum of 16.  The buffer is large
-     enough, but the compiler does not know that, so shut up the
-     warning here.  */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wstringop-overflow"
   *q = '\0';
-#pragma GCC diagnostic pop
 
   if (*n == 0)
     return "0";

  parent reply	other threads:[~2023-09-28  7:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27 18:21 Toon Moene
2023-09-27 21:48 ` Jeff Law
2023-09-28  6:25   ` Richard Biener
2023-09-28  6:29     ` Andrew Pinski
2023-09-28  7:29     ` Tobias Burnus [this message]
2023-09-28  9:51       ` Jakub Jelinek
2023-09-28 11:00         ` Tobias Burnus
2023-09-28 11:02           ` Jakub Jelinek
2023-09-28  5:33 ` Thomas Koenig
2023-09-28 19:03   ` Toon Moene
2023-09-28 19:26     ` Jakub Jelinek
2023-09-28 19:59       ` Toon Moene
2023-09-28 20:02         ` David Edelsohn
2023-09-29 10:26         ` Andrew Stubbs
2023-09-29  6:03       ` Thomas Koenig

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=fe708d35-0bb3-4aeb-baac-aad2812ece5d@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=richard.guenther@gmail.com \
    --cc=tkoenig@netcologne.de \
    --cc=toon@moene.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).