public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Koenig <tkoenig@netcologne.de>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [patch, fortran, doc] Explicitly mention undefined overflow
Date: Sun, 19 Mar 2023 09:32:45 +0100	[thread overview]
Message-ID: <eee8f01b-7e2c-c465-eaed-226714dc9655@netcologne.de> (raw)

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

Here's also an update on the docs to explicitly mention behavior
on overflow.

Maybe this will reach another 0.05% of users...

OK for trunk?

Best regards

	Thomas

gcc/fortran/ChangeLog:

	* gfortran.texi: Mention behavior on overflow.

[-- Attachment #2: overflow.diff --]
[-- Type: text/x-patch, Size: 1414 bytes --]

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index c483e13686d..93c66b18938 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -820,6 +820,7 @@ might in some way or another become visible to the programmer.
 * File operations on symbolic links::
 * File format of unformatted sequential files::
 * Asynchronous I/O::
+* Behavior on integer overflow::o
 @end menu
 
 
@@ -1160,6 +1161,23 @@ sytems, such as Linux, it is necessary to specify @option{-pthread},
 @c Maybe this chapter should be merged with the 'Standards' section,
 @c whenever that is written :-)
 
+@node Behavior on integer overflow
+@section Behavior on integer overflow
+@cindex integer overflow
+@cindex overflow handling
+
+Integer overflow is prohibited by the Fortran standard.  The behavior
+of gfortran on integer overflow is undefined by default.  Traditional
+code, like linear congruential pseudo-random number generators in old
+programs that rely on specific, non-standard behavior may generate
+unexpected results.  The @option{-fsanitize=undefined} option can be
+used to detect such code at runtime.
+
+It is recommended to use the intrinsic subroutine @code{RANDOM_NUMBER}
+for random number generators or, if the old behavior is desired, to
+use the @option{-fwrapv} option.  Note that this option can impact
+performance.
+
 @node Extensions
 @chapter Extensions
 @cindex extensions

             reply	other threads:[~2023-03-19  8:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-19  8:32 Thomas Koenig [this message]
2023-03-19 13:12 ` Paul Richard Thomas
2023-03-19 17:40   ` Thomas Koenig
2023-03-20  7:14     ` Thomas Koenig
2023-03-20 21:32       ` Harald Anlauf
2023-03-20 21:32         ` Harald Anlauf
2023-03-19 13:15 ` Andreas Schwab

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=eee8f01b-7e2c-c465-eaed-226714dc9655@netcologne.de \
    --to=tkoenig@netcologne.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.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).