]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Mention undefined behavior on integer overflow.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 19 Mar 2023 17:34:38 +0000 (18:34 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 19 Mar 2023 17:34:38 +0000 (18:34 +0100)
gcc/fortran/ChangeLog:

* gfortran.texi: Mention behavior on overflow.

gcc/fortran/gfortran.texi

index c483e13686d9340f731466c7174912ee2794c7ad..b96712987e18f5daab6f46b2c8e0b713f18be280 100644 (file)
@@ -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::
 @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