annotate libgfortran/runtime/stop.c @ 113:bdf41c9fa0b7

remove RECTYPE
author mir3636
date Fri, 17 Nov 2017 06:33:55 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Implementation of the STOP statement.
kono
parents:
diff changeset
2 Copyright (C) 2002-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3 Contributed by Paul Brook <paul@nowt.org>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of the GNU Fortran runtime library (libgfortran).
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 Libgfortran is free software; you can redistribute it and/or
kono
parents:
diff changeset
8 modify it under the terms of the GNU General Public
kono
parents:
diff changeset
9 License as published by the Free Software Foundation; either
kono
parents:
diff changeset
10 version 3 of the License, or (at your option) any later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 Libgfortran is distributed in the hope that it will be useful,
kono
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
15 GNU General Public License for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #include "libgfortran.h"
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #ifdef HAVE_UNISTD_H
kono
parents:
diff changeset
29 #include <unistd.h>
kono
parents:
diff changeset
30 #endif
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 /* Fortran 2008 demands: If any exception (14) is signaling on that image, the
kono
parents:
diff changeset
34 processor shall issue a warning indicating which exceptions are signaling;
kono
parents:
diff changeset
35 this warning shall be on the unit identified by the named constant
kono
parents:
diff changeset
36 ERROR_UNIT (13.8.2.8). In line with other compilers, we do not report
kono
parents:
diff changeset
37 inexact - and we optionally ignore underflow, cf. thread starting at
kono
parents:
diff changeset
38 http://mailman.j3-fortran.org/pipermail/j3/2013-June/006452.html. */
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 static void
kono
parents:
diff changeset
41 report_exception (void)
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 int set_excepts;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 if (!compile_options.fpe_summary)
kono
parents:
diff changeset
46 return;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 set_excepts = get_fpu_except_flags ();
kono
parents:
diff changeset
49 if ((set_excepts & compile_options.fpe_summary) == 0)
kono
parents:
diff changeset
50 return;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 estr_write ("Note: The following floating-point exceptions are signalling:");
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 if ((compile_options.fpe_summary & GFC_FPE_INVALID)
kono
parents:
diff changeset
55 && (set_excepts & GFC_FPE_INVALID))
kono
parents:
diff changeset
56 estr_write (" IEEE_INVALID_FLAG");
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 if ((compile_options.fpe_summary & GFC_FPE_ZERO)
kono
parents:
diff changeset
59 && (set_excepts & GFC_FPE_ZERO))
kono
parents:
diff changeset
60 estr_write (" IEEE_DIVIDE_BY_ZERO");
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 if ((compile_options.fpe_summary & GFC_FPE_OVERFLOW)
kono
parents:
diff changeset
63 && (set_excepts & GFC_FPE_OVERFLOW))
kono
parents:
diff changeset
64 estr_write (" IEEE_OVERFLOW_FLAG");
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 if ((compile_options.fpe_summary & GFC_FPE_UNDERFLOW)
kono
parents:
diff changeset
67 && (set_excepts & GFC_FPE_UNDERFLOW))
kono
parents:
diff changeset
68 estr_write (" IEEE_UNDERFLOW_FLAG");
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 if ((compile_options.fpe_summary & GFC_FPE_DENORMAL)
kono
parents:
diff changeset
71 && (set_excepts & GFC_FPE_DENORMAL))
kono
parents:
diff changeset
72 estr_write (" IEEE_DENORMAL");
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 if ((compile_options.fpe_summary & GFC_FPE_INEXACT)
kono
parents:
diff changeset
75 && (set_excepts & GFC_FPE_INEXACT))
kono
parents:
diff changeset
76 estr_write (" IEEE_INEXACT_FLAG");
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 estr_write ("\n");
kono
parents:
diff changeset
79 }
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 /* A numeric STOP statement. */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 extern _Noreturn void stop_numeric (GFC_INTEGER_4);
kono
parents:
diff changeset
85 export_proto(stop_numeric);
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 void
kono
parents:
diff changeset
88 stop_numeric (GFC_INTEGER_4 code)
kono
parents:
diff changeset
89 {
kono
parents:
diff changeset
90 report_exception ();
kono
parents:
diff changeset
91 st_printf ("STOP %d\n", (int)code);
kono
parents:
diff changeset
92 exit (code);
kono
parents:
diff changeset
93 }
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 /* A character string or blank STOP statement. */
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 void
kono
parents:
diff changeset
99 stop_string (const char *string, GFC_INTEGER_4 len)
kono
parents:
diff changeset
100 {
kono
parents:
diff changeset
101 report_exception ();
kono
parents:
diff changeset
102 if (string)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 estr_write ("STOP ");
kono
parents:
diff changeset
105 (void) write (STDERR_FILENO, string, len);
kono
parents:
diff changeset
106 estr_write ("\n");
kono
parents:
diff changeset
107 }
kono
parents:
diff changeset
108 exit (0);
kono
parents:
diff changeset
109 }
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 /* Per Fortran 2008, section 8.4: "Execution of a STOP statement initiates
kono
parents:
diff changeset
113 normal termination of execution. Execution of an ERROR STOP statement
kono
parents:
diff changeset
114 initiates error termination of execution." Thus, error_stop_string returns
kono
parents:
diff changeset
115 a nonzero exit status code. */
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 extern _Noreturn void error_stop_string (const char *, GFC_INTEGER_4);
kono
parents:
diff changeset
118 export_proto(error_stop_string);
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 void
kono
parents:
diff changeset
121 error_stop_string (const char *string, GFC_INTEGER_4 len)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 report_exception ();
kono
parents:
diff changeset
124 estr_write ("ERROR STOP ");
kono
parents:
diff changeset
125 (void) write (STDERR_FILENO, string, len);
kono
parents:
diff changeset
126 estr_write ("\n");
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 exit_error (1);
kono
parents:
diff changeset
129 }
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 /* A numeric ERROR STOP statement. */
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 extern _Noreturn void error_stop_numeric (GFC_INTEGER_4);
kono
parents:
diff changeset
135 export_proto(error_stop_numeric);
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 void
kono
parents:
diff changeset
138 error_stop_numeric (GFC_INTEGER_4 code)
kono
parents:
diff changeset
139 {
kono
parents:
diff changeset
140 report_exception ();
kono
parents:
diff changeset
141 st_printf ("ERROR STOP %d\n", (int) code);
kono
parents:
diff changeset
142 exit_error (code);
kono
parents:
diff changeset
143 }