| 1 |
/* Copyright (C) 2005-2025 Free Software Foundation, Inc. |
| 2 |
Contributed by Richard Henderson <[email protected]>. |
| 3 |
|
| 4 |
This file is part of the GNU Offloading and Multi Processing Library |
| 5 |
(libgomp). |
| 6 |
|
| 7 |
Libgomp is free software; you can redistribute it and/or modify it |
| 8 |
under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 14 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 |
more details. |
| 16 |
|
| 17 |
Under Section 7 of GPL version 3, you are granted additional |
| 18 |
permissions described in the GCC Runtime Library Exception, version |
| 19 |
3.1, as published by the Free Software Foundation. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public License and |
| 22 |
a copy of the GCC Runtime Library Exception along with this program; |
| 23 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 24 |
<http://www.gnu.org/licenses/>. */ |
| 25 |
|
| 26 |
/* This file contains routines used to signal errors. Most places in the |
| 27 |
OpenMP API do not make any provision for failure, so we can't just |
| 28 |
defer the decision on reporting the problem to the user; we must do it |
| 29 |
ourselves or not at all. */ |
| 30 |
/* ??? Is this about what other implementations do? Assume stderr hasn't |
| 31 |
been pointed somewhere unsafe? */ |
| 32 |
|
| 33 |
#include "libgomp.h" |
| 34 |
#include <stdarg.h> |
| 35 |
#include <stdio.h> |
| 36 |
#include <stdlib.h> |
| 37 |
|
| 38 |
|
| 39 |
#undef gomp_vdebug |
| 40 |
void |
| 41 |
gomp_vdebug (int kind __attribute__ ((unused)), const char *msg, va_list list) |
| 42 |
{ |
| 43 |
if (gomp_debug_var) |
| 44 |
vfprintf (stderr, msg, list); |
| 45 |
} |
| 46 |
|
| 47 |
#undef gomp_debug |
| 48 |
void |
| 49 |
gomp_debug (int kind, const char *msg, ...) |
| 50 |
{ |
| 51 |
va_list list; |
| 52 |
|
| 53 |
va_start (list, msg); |
| 54 |
gomp_vdebug (kind, msg, list); |
| 55 |
va_end (list); |
| 56 |
} |
| 57 |
|
| 58 |
void |
| 59 |
gomp_verror (const char *fmt, va_list list) |
| 60 |
{ |
| 61 |
fputs ("\nlibgomp: ", stderr); |
| 62 |
vfprintf (stderr, fmt, list); |
| 63 |
fputc ('\n', stderr); |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
gomp_error (const char *fmt, ...) |
| 68 |
{ |
| 69 |
va_list list; |
| 70 |
|
| 71 |
va_start (list, fmt); |
| 72 |
gomp_verror (fmt, list); |
| 73 |
va_end (list); |
| 74 |
} |
| 75 |
|
| 76 |
void |
| 77 |
gomp_vfatal (const char *fmt, va_list list) |
| 78 |
{ |
| 79 |
gomp_verror (fmt, list); |
| 80 |
exit (EXIT_FAILURE); |
| 81 |
} |
| 82 |
|
| 83 |
void |
| 84 |
gomp_fatal (const char *fmt, ...) |
| 85 |
{ |
| 86 |
va_list list; |
| 87 |
|
| 88 |
va_start (list, fmt); |
| 89 |
gomp_vfatal (fmt, list); |
| 90 |
va_end (list); |
| 91 |
} |
| 92 |
|
| 93 |
void |
| 94 |
GOMP_warning (const char *msg, size_t msglen) |
| 95 |
{ |
| 96 |
if (msg && msglen == (size_t) -1) |
| 97 |
gomp_error ("error directive encountered: %s", msg); |
| 98 |
else if (msg) |
| 99 |
{ |
| 100 |
fputs ("\nlibgomp: error directive encountered: ", stderr); |
| 101 |
fwrite (msg, 1, msglen, stderr); |
| 102 |
fputc ('\n', stderr); |
| 103 |
} |
| 104 |
else |
| 105 |
gomp_error ("error directive encountered"); |
| 106 |
} |
| 107 |
|
| 108 |
void |
| 109 |
GOMP_error (const char *msg, size_t msglen) |
| 110 |
{ |
| 111 |
if (msg && msglen == (size_t) -1) |
| 112 |
gomp_fatal ("fatal error: error directive encountered: %s", msg); |
| 113 |
else if (msg) |
| 114 |
{ |
| 115 |
fputs ("\nlibgomp: fatal error: error directive encountered: ", stderr); |
| 116 |
fwrite (msg, 1, msglen, stderr); |
| 117 |
fputc ('\n', stderr); |
| 118 |
exit (EXIT_FAILURE); |
| 119 |
} |
| 120 |
else |
| 121 |
gomp_fatal ("fatal error: error directive encountered"); |
| 122 |
} |