2004-05-13 08:41:07 +02:00
|
|
|
/* Implementation of the STOP statement.
|
2021-01-04 10:26:59 +01:00
|
|
|
Copyright (C) 2002-2021 Free Software Foundation, Inc.
|
2004-05-13 08:41:07 +02:00
|
|
|
Contributed by Paul Brook <paul@nowt.org>
|
|
|
|
|
2011-05-14 09:55:51 +02:00
|
|
|
This file is part of the GNU Fortran runtime library (libgfortran).
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2005-01-12 22:27:33 +01:00
|
|
|
Libgfortran is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
2004-05-13 08:41:07 +02:00
|
|
|
License as published by the Free Software Foundation; either
|
2009-04-09 17:00:19 +02:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2005-01-12 22:27:33 +01:00
|
|
|
|
|
|
|
Libgfortran is distributed in the hope that it will be useful,
|
2004-05-13 08:41:07 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-01-12 22:27:33 +01:00
|
|
|
GNU General Public License for more details.
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
#include "libgfortran.h"
|
2013-05-04 23:23:11 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2011-05-14 09:55:51 +02:00
|
|
|
#include <unistd.h>
|
2013-05-04 23:23:11 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-21 20:12:59 +02:00
|
|
|
#include <string.h>
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2013-06-17 09:48:21 +02:00
|
|
|
/* Fortran 2008 demands: If any exception (14) is signaling on that image, the
|
|
|
|
processor shall issue a warning indicating which exceptions are signaling;
|
|
|
|
this warning shall be on the unit identified by the named constant
|
|
|
|
ERROR_UNIT (13.8.2.8). In line with other compilers, we do not report
|
|
|
|
inexact - and we optionally ignore underflow, cf. thread starting at
|
|
|
|
http://mailman.j3-fortran.org/pipermail/j3/2013-June/006452.html. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
report_exception (void)
|
|
|
|
{
|
2018-09-21 20:12:59 +02:00
|
|
|
struct iovec iov[8];
|
|
|
|
int set_excepts, iovcnt = 1;
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
if (!compile_options.fpe_summary)
|
|
|
|
return;
|
|
|
|
|
|
|
|
set_excepts = get_fpu_except_flags ();
|
|
|
|
if ((set_excepts & compile_options.fpe_summary) == 0)
|
|
|
|
return;
|
|
|
|
|
2018-09-21 20:12:59 +02:00
|
|
|
iov[0].iov_base = (char*) "Note: The following floating-point exceptions are signalling:";
|
|
|
|
iov[0].iov_len = strlen (iov[0].iov_base);
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
if ((compile_options.fpe_summary & GFC_FPE_INVALID)
|
|
|
|
&& (set_excepts & GFC_FPE_INVALID))
|
2018-09-21 20:12:59 +02:00
|
|
|
{
|
|
|
|
iov[iovcnt].iov_base = (char*) " IEEE_INVALID_FLAG";
|
|
|
|
iov[iovcnt].iov_len = strlen (iov[iovcnt].iov_base);
|
|
|
|
iovcnt++;
|
|
|
|
}
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
if ((compile_options.fpe_summary & GFC_FPE_ZERO)
|
|
|
|
&& (set_excepts & GFC_FPE_ZERO))
|
2018-09-21 20:12:59 +02:00
|
|
|
{
|
|
|
|
iov[iovcnt].iov_base = (char*) " IEEE_DIVIDE_BY_ZERO";
|
|
|
|
iov[iovcnt].iov_len = strlen (iov[iovcnt].iov_base);
|
|
|
|
iovcnt++;
|
|
|
|
}
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
if ((compile_options.fpe_summary & GFC_FPE_OVERFLOW)
|
|
|
|
&& (set_excepts & GFC_FPE_OVERFLOW))
|
2018-09-21 20:12:59 +02:00
|
|
|
{
|
|
|
|
iov[iovcnt].iov_base = (char*) " IEEE_OVERFLOW_FLAG";
|
|
|
|
iov[iovcnt].iov_len = strlen (iov[iovcnt].iov_base);
|
|
|
|
iovcnt++;
|
|
|
|
}
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
if ((compile_options.fpe_summary & GFC_FPE_UNDERFLOW)
|
|
|
|
&& (set_excepts & GFC_FPE_UNDERFLOW))
|
2018-09-21 20:12:59 +02:00
|
|
|
{
|
|
|
|
iov[iovcnt].iov_base = (char*) " IEEE_UNDERFLOW_FLAG";
|
|
|
|
iov[iovcnt].iov_len = strlen (iov[iovcnt].iov_base);
|
|
|
|
iovcnt++;
|
|
|
|
}
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
if ((compile_options.fpe_summary & GFC_FPE_DENORMAL)
|
|
|
|
&& (set_excepts & GFC_FPE_DENORMAL))
|
2018-09-21 20:12:59 +02:00
|
|
|
{
|
|
|
|
iov[iovcnt].iov_base = (char*) " IEEE_DENORMAL";
|
|
|
|
iov[iovcnt].iov_len = strlen (iov[iovcnt].iov_base);
|
|
|
|
iovcnt++;
|
|
|
|
}
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
if ((compile_options.fpe_summary & GFC_FPE_INEXACT)
|
|
|
|
&& (set_excepts & GFC_FPE_INEXACT))
|
2018-09-21 20:12:59 +02:00
|
|
|
{
|
|
|
|
iov[iovcnt].iov_base = (char*) " IEEE_INEXACT_FLAG";
|
|
|
|
iov[iovcnt].iov_len = strlen (iov[iovcnt].iov_base);
|
|
|
|
iovcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
iov[iovcnt].iov_base = (char*) "\n";
|
|
|
|
iov[iovcnt].iov_len = 1;
|
|
|
|
iovcnt++;
|
2013-06-17 09:48:21 +02:00
|
|
|
|
2018-09-21 20:12:59 +02:00
|
|
|
estr_writev (iov, iovcnt);
|
2013-06-17 09:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-20 06:44:11 +02:00
|
|
|
/* A numeric STOP statement. */
|
|
|
|
|
2018-02-23 10:07:24 +01:00
|
|
|
extern _Noreturn void stop_numeric (int, bool);
|
2010-05-20 06:44:11 +02:00
|
|
|
export_proto(stop_numeric);
|
|
|
|
|
2004-05-13 08:41:07 +02:00
|
|
|
void
|
2018-02-23 10:07:24 +01:00
|
|
|
stop_numeric (int code, bool quiet)
|
2004-05-13 08:41:07 +02:00
|
|
|
{
|
2018-02-23 10:07:24 +01:00
|
|
|
if (!quiet)
|
|
|
|
{
|
|
|
|
report_exception ();
|
|
|
|
st_printf ("STOP %d\n", code);
|
|
|
|
}
|
2011-05-14 10:44:09 +02:00
|
|
|
exit (code);
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
|
|
|
|
2010-10-21 02:45:15 +02:00
|
|
|
|
2010-05-20 06:44:11 +02:00
|
|
|
/* A character string or blank STOP statement. */
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
void
|
2018-02-23 10:07:24 +01:00
|
|
|
stop_string (const char *string, size_t len, bool quiet)
|
2004-05-13 08:41:07 +02:00
|
|
|
{
|
2018-02-23 10:07:24 +01:00
|
|
|
if (!quiet)
|
2010-05-20 21:40:30 +02:00
|
|
|
{
|
2018-02-23 10:07:24 +01:00
|
|
|
report_exception ();
|
|
|
|
if (string)
|
|
|
|
{
|
2018-09-21 20:12:59 +02:00
|
|
|
struct iovec iov[3];
|
|
|
|
iov[0].iov_base = (char*) "STOP ";
|
|
|
|
iov[0].iov_len = strlen (iov[0].iov_base);
|
|
|
|
iov[1].iov_base = (char*) string;
|
|
|
|
iov[1].iov_len = len;
|
|
|
|
iov[2].iov_base = (char*) "\n";
|
|
|
|
iov[2].iov_len = 1;
|
|
|
|
estr_writev (iov, 3);
|
2018-02-23 10:07:24 +01:00
|
|
|
}
|
2010-05-20 21:40:30 +02:00
|
|
|
}
|
2011-05-14 10:44:09 +02:00
|
|
|
exit (0);
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
re PR fortran/39997 (Procedure(), pointer & implicit typing: rejects-valid / accepts-invalid?)
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* intrinsic.c (add_functions): Add num_images.
* decl.c (gfc_match_end): Handle END CRITICAL.
* intrinsic.h (gfc_simplify_num_images): Add prototype.
* dump-parse-tree.c (show_code_node): Dump CRITICAL, ERROR STOP,
and SYNC.
* gfortran.h (gfc_statement): Add enum items for those.
(gfc_exec_op) Ditto.
(gfc_isym_id): Add num_images.
* trans-stmt.c (gfc_trans_stop): Handle ERROR STOP.
(gfc_trans_sync,gfc_trans_critical): New functions.
* trans-stmt.h (gfc_trans_stop,gfc_trans_sync,
gfc_trans_critical): Add/update prototypes.
* trans.c (gfc_trans_code): Handle CRITICAL, ERROR STOP,
and SYNC statements.
* trans.h (gfor_fndecl_error_stop_string) Add variable.
* resolve.c (resolve_sync): Add function.
(gfc_resolve_blocks): Handle CRITICAL.
(resolve_code): Handle CRITICAL, ERROR STOP,
(resolve_branch): Add CRITICAL constraint check.
and SYNC statements.
* st.c (gfc_free_statement): Add new statements.
* trans-decl.c (gfor_fndecl_error_stop_string): Global variable.
(gfc_build_builtin_function_decls): Initialize it.
* match.c (gfc_match_if): Handle ERROR STOP and SYNC.
(gfc_match_critical, gfc_match_error_stop, sync_statement,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory):
New functions.
(match_exit_cycle): Handle CRITICAL constraint.
(gfc_match_stopcode): Handle ERROR STOP.
* match.h (gfc_match_critical, gfc_match_error_stop,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory): Add prototype.
* parse.c (decode_statement, gfc_ascii_statement,
parse_executable): Handle new statements.
(parse_critical_block): New function.
* parse.h (gfc_compile_state): Add COMP_CRITICAL.
* intrinsic.texi (num_images): Document new function.
* simplify.c (gfc_simplify_num_images): Add function.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* gfortran.dg/coarray_1.f90: New test.
* gfortran.dg/coarray_2.f90: New test.
* gfortran.dg/coarray_3.f90: New test.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* runtime/stop.c (error_stop_string): New function.
* gfortran.map (_gfortran_error_stop_string): Add.
From-SVN: r158008
2010-04-06 18:26:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Per Fortran 2008, section 8.4: "Execution of a STOP statement initiates
|
|
|
|
normal termination of execution. Execution of an ERROR STOP statement
|
|
|
|
initiates error termination of execution." Thus, error_stop_string returns
|
|
|
|
a nonzero exit status code. */
|
2010-05-20 06:44:11 +02:00
|
|
|
|
2018-02-23 10:07:24 +01:00
|
|
|
extern _Noreturn void error_stop_string (const char *, size_t, bool);
|
2010-05-20 06:44:11 +02:00
|
|
|
export_proto(error_stop_string);
|
|
|
|
|
re PR fortran/39997 (Procedure(), pointer & implicit typing: rejects-valid / accepts-invalid?)
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* intrinsic.c (add_functions): Add num_images.
* decl.c (gfc_match_end): Handle END CRITICAL.
* intrinsic.h (gfc_simplify_num_images): Add prototype.
* dump-parse-tree.c (show_code_node): Dump CRITICAL, ERROR STOP,
and SYNC.
* gfortran.h (gfc_statement): Add enum items for those.
(gfc_exec_op) Ditto.
(gfc_isym_id): Add num_images.
* trans-stmt.c (gfc_trans_stop): Handle ERROR STOP.
(gfc_trans_sync,gfc_trans_critical): New functions.
* trans-stmt.h (gfc_trans_stop,gfc_trans_sync,
gfc_trans_critical): Add/update prototypes.
* trans.c (gfc_trans_code): Handle CRITICAL, ERROR STOP,
and SYNC statements.
* trans.h (gfor_fndecl_error_stop_string) Add variable.
* resolve.c (resolve_sync): Add function.
(gfc_resolve_blocks): Handle CRITICAL.
(resolve_code): Handle CRITICAL, ERROR STOP,
(resolve_branch): Add CRITICAL constraint check.
and SYNC statements.
* st.c (gfc_free_statement): Add new statements.
* trans-decl.c (gfor_fndecl_error_stop_string): Global variable.
(gfc_build_builtin_function_decls): Initialize it.
* match.c (gfc_match_if): Handle ERROR STOP and SYNC.
(gfc_match_critical, gfc_match_error_stop, sync_statement,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory):
New functions.
(match_exit_cycle): Handle CRITICAL constraint.
(gfc_match_stopcode): Handle ERROR STOP.
* match.h (gfc_match_critical, gfc_match_error_stop,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory): Add prototype.
* parse.c (decode_statement, gfc_ascii_statement,
parse_executable): Handle new statements.
(parse_critical_block): New function.
* parse.h (gfc_compile_state): Add COMP_CRITICAL.
* intrinsic.texi (num_images): Document new function.
* simplify.c (gfc_simplify_num_images): Add function.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* gfortran.dg/coarray_1.f90: New test.
* gfortran.dg/coarray_2.f90: New test.
* gfortran.dg/coarray_3.f90: New test.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* runtime/stop.c (error_stop_string): New function.
* gfortran.map (_gfortran_error_stop_string): Add.
From-SVN: r158008
2010-04-06 18:26:02 +02:00
|
|
|
void
|
2018-02-23 10:07:24 +01:00
|
|
|
error_stop_string (const char *string, size_t len, bool quiet)
|
re PR fortran/39997 (Procedure(), pointer & implicit typing: rejects-valid / accepts-invalid?)
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* intrinsic.c (add_functions): Add num_images.
* decl.c (gfc_match_end): Handle END CRITICAL.
* intrinsic.h (gfc_simplify_num_images): Add prototype.
* dump-parse-tree.c (show_code_node): Dump CRITICAL, ERROR STOP,
and SYNC.
* gfortran.h (gfc_statement): Add enum items for those.
(gfc_exec_op) Ditto.
(gfc_isym_id): Add num_images.
* trans-stmt.c (gfc_trans_stop): Handle ERROR STOP.
(gfc_trans_sync,gfc_trans_critical): New functions.
* trans-stmt.h (gfc_trans_stop,gfc_trans_sync,
gfc_trans_critical): Add/update prototypes.
* trans.c (gfc_trans_code): Handle CRITICAL, ERROR STOP,
and SYNC statements.
* trans.h (gfor_fndecl_error_stop_string) Add variable.
* resolve.c (resolve_sync): Add function.
(gfc_resolve_blocks): Handle CRITICAL.
(resolve_code): Handle CRITICAL, ERROR STOP,
(resolve_branch): Add CRITICAL constraint check.
and SYNC statements.
* st.c (gfc_free_statement): Add new statements.
* trans-decl.c (gfor_fndecl_error_stop_string): Global variable.
(gfc_build_builtin_function_decls): Initialize it.
* match.c (gfc_match_if): Handle ERROR STOP and SYNC.
(gfc_match_critical, gfc_match_error_stop, sync_statement,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory):
New functions.
(match_exit_cycle): Handle CRITICAL constraint.
(gfc_match_stopcode): Handle ERROR STOP.
* match.h (gfc_match_critical, gfc_match_error_stop,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory): Add prototype.
* parse.c (decode_statement, gfc_ascii_statement,
parse_executable): Handle new statements.
(parse_critical_block): New function.
* parse.h (gfc_compile_state): Add COMP_CRITICAL.
* intrinsic.texi (num_images): Document new function.
* simplify.c (gfc_simplify_num_images): Add function.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* gfortran.dg/coarray_1.f90: New test.
* gfortran.dg/coarray_2.f90: New test.
* gfortran.dg/coarray_3.f90: New test.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* runtime/stop.c (error_stop_string): New function.
* gfortran.map (_gfortran_error_stop_string): Add.
From-SVN: r158008
2010-04-06 18:26:02 +02:00
|
|
|
{
|
2018-02-23 10:07:24 +01:00
|
|
|
if (!quiet)
|
|
|
|
{
|
2018-09-21 20:12:59 +02:00
|
|
|
struct iovec iov[3];
|
2018-02-23 10:07:24 +01:00
|
|
|
report_exception ();
|
2018-09-21 20:12:59 +02:00
|
|
|
iov[0].iov_base = (char*) "ERROR STOP ";
|
|
|
|
iov[0].iov_len = strlen (iov[0].iov_base);
|
|
|
|
iov[1].iov_base = (char*) string;
|
|
|
|
iov[1].iov_len = len;
|
|
|
|
iov[2].iov_base = (char*) "\n";
|
|
|
|
iov[2].iov_len = 1;
|
|
|
|
estr_writev (iov, 3);
|
2018-02-23 10:07:24 +01:00
|
|
|
}
|
2015-09-05 00:17:11 +02:00
|
|
|
exit_error (1);
|
re PR fortran/39997 (Procedure(), pointer & implicit typing: rejects-valid / accepts-invalid?)
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* intrinsic.c (add_functions): Add num_images.
* decl.c (gfc_match_end): Handle END CRITICAL.
* intrinsic.h (gfc_simplify_num_images): Add prototype.
* dump-parse-tree.c (show_code_node): Dump CRITICAL, ERROR STOP,
and SYNC.
* gfortran.h (gfc_statement): Add enum items for those.
(gfc_exec_op) Ditto.
(gfc_isym_id): Add num_images.
* trans-stmt.c (gfc_trans_stop): Handle ERROR STOP.
(gfc_trans_sync,gfc_trans_critical): New functions.
* trans-stmt.h (gfc_trans_stop,gfc_trans_sync,
gfc_trans_critical): Add/update prototypes.
* trans.c (gfc_trans_code): Handle CRITICAL, ERROR STOP,
and SYNC statements.
* trans.h (gfor_fndecl_error_stop_string) Add variable.
* resolve.c (resolve_sync): Add function.
(gfc_resolve_blocks): Handle CRITICAL.
(resolve_code): Handle CRITICAL, ERROR STOP,
(resolve_branch): Add CRITICAL constraint check.
and SYNC statements.
* st.c (gfc_free_statement): Add new statements.
* trans-decl.c (gfor_fndecl_error_stop_string): Global variable.
(gfc_build_builtin_function_decls): Initialize it.
* match.c (gfc_match_if): Handle ERROR STOP and SYNC.
(gfc_match_critical, gfc_match_error_stop, sync_statement,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory):
New functions.
(match_exit_cycle): Handle CRITICAL constraint.
(gfc_match_stopcode): Handle ERROR STOP.
* match.h (gfc_match_critical, gfc_match_error_stop,
gfc_match_sync_all, gfc_match_sync_images,
gfc_match_sync_memory): Add prototype.
* parse.c (decode_statement, gfc_ascii_statement,
parse_executable): Handle new statements.
(parse_critical_block): New function.
* parse.h (gfc_compile_state): Add COMP_CRITICAL.
* intrinsic.texi (num_images): Document new function.
* simplify.c (gfc_simplify_num_images): Add function.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* gfortran.dg/coarray_1.f90: New test.
* gfortran.dg/coarray_2.f90: New test.
* gfortran.dg/coarray_3.f90: New test.
2010-04-06 Tobias Burnus <burnus@net-b.de>
PR fortran/39997
* runtime/stop.c (error_stop_string): New function.
* gfortran.map (_gfortran_error_stop_string): Add.
From-SVN: r158008
2010-04-06 18:26:02 +02:00
|
|
|
}
|
2010-05-20 06:44:11 +02:00
|
|
|
|
2010-10-21 02:45:15 +02:00
|
|
|
|
|
|
|
/* A numeric ERROR STOP statement. */
|
2010-05-20 06:44:11 +02:00
|
|
|
|
2018-02-23 10:07:24 +01:00
|
|
|
extern _Noreturn void error_stop_numeric (int, bool);
|
2010-05-20 06:44:11 +02:00
|
|
|
export_proto(error_stop_numeric);
|
|
|
|
|
|
|
|
void
|
2018-02-23 10:07:24 +01:00
|
|
|
error_stop_numeric (int code, bool quiet)
|
2010-05-20 06:44:11 +02:00
|
|
|
{
|
2018-02-23 10:07:24 +01:00
|
|
|
if (!quiet)
|
|
|
|
{
|
|
|
|
report_exception ();
|
|
|
|
st_printf ("ERROR STOP %d\n", code);
|
|
|
|
}
|
2015-09-05 00:17:11 +02:00
|
|
|
exit_error (code);
|
2010-05-20 06:44:11 +02:00
|
|
|
}
|