diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2019-08-17 08:45:37 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2019-08-17 08:45:37 +0300 |
commit | d74a8b0579edd0c42921eccc45ab986d24f2fef0 (patch) | |
tree | 2059efcc45ffef85dfef605dcc8b39c8765e07bd /libgfortran/runtime | |
parent | 777c02825229f14cf91c6044827ea42a77ded4a3 (diff) | |
download | gcc-d74a8b0579edd0c42921eccc45ab986d24f2fef0.zip gcc-d74a8b0579edd0c42921eccc45ab986d24f2fef0.tar.gz gcc-d74a8b0579edd0c42921eccc45ab986d24f2fef0.tar.bz2 |
PR fortran/68401 Improve allocation error message
Improve the error message that is printed when a memory allocation
fails, by including the location, and the size of the allocation that
failed.
Regtested on x86_64-pc-linux-gnu.
gcc/fortran/ChangeLog:
2019-08-17 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/68401
* trans-decl.c (gfc_build_builtin_function_decls): Replace
os_error with os_error_at decl.
* trans.c (trans_runtime_error_vararg): Modify so the error
function decl is passed directly.
(gfc_trans_runtime_error): Pass correct error function decl.
(gfc_trans_runtime_check): Likewise.
(trans_os_error_at): New function.
(gfc_call_malloc): Use trans_os_error_at.
(gfc_allocate_using_malloc): Likewise.
(gfc_call_realloc): Likewise.
* trans.h (gfor_fndecl_os_error): Replace with gfor_fndecl_os_error_at.
libgfortran/ChangeLog:
2019-08-17 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/68401
* gfortran.map: Add GFORTRAN_10 node, add _gfortran_os_error_at
symbol.
* libgfortran.h (os_error_at): New prototype.
* runtime/error.c (os_error_at): New function.
From-SVN: r274599
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/error.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index 0335a16..cbe0642 100644 --- a/libgfortran/runtime/error.c +++ b/libgfortran/runtime/error.c @@ -403,7 +403,51 @@ os_error (const char *message) estr_writev (iov, 5); exit_error (1); } -iexport(os_error); +iexport(os_error); /* TODO, DEPRECATED, ABI: Should not be exported + anymore when bumping so version. */ + + +/* Improved version of os_error with a printf style format string and + a locus. */ + +void +os_error_at (const char *where, const char *message, ...) +{ + char errmsg[STRERR_MAXSZ]; + char buffer[STRERR_MAXSZ]; + struct iovec iov[6]; + va_list ap; + recursion_check (); + int written; + + iov[0].iov_base = (char*) where; + iov[0].iov_len = strlen (where); + + iov[1].iov_base = (char*) ": "; + iov[1].iov_len = strlen (iov[1].iov_base); + + va_start (ap, message); + written = vsnprintf (buffer, STRERR_MAXSZ, message, ap); + va_end (ap); + iov[2].iov_base = buffer; + if (written >= 0) + iov[2].iov_len = written; + else + iov[2].iov_len = 0; + + iov[3].iov_base = (char*) ": "; + iov[3].iov_len = strlen (iov[3].iov_base); + + iov[4].iov_base = gf_strerror (errno, errmsg, STRERR_MAXSZ); + iov[4].iov_len = strlen (iov[4].iov_base); + + iov[5].iov_base = (char*) "\n"; + iov[5].iov_len = 1; + + estr_writev (iov, 6); + exit_error (1); +} +iexport(os_error_at); /* void runtime_error()-- These are errors associated with an |