aboutsummaryrefslogtreecommitdiff
path: root/libgomp/error.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-08-20 11:36:52 +0200
committerJakub Jelinek <jakub@redhat.com>2021-08-20 11:36:52 +0200
commit0d973c0a0d90a0a302e7eda1a4d9709be3c5b102 (patch)
tree9201cdf5e6e4357301650e6ccfc09c63f380d800 /libgomp/error.c
parentf9400e4e4705845f2b0cdc4eab30c214e0e4cbe0 (diff)
downloadgcc-0d973c0a0d90a0a302e7eda1a4d9709be3c5b102.zip
gcc-0d973c0a0d90a0a302e7eda1a4d9709be3c5b102.tar.gz
gcc-0d973c0a0d90a0a302e7eda1a4d9709be3c5b102.tar.bz2
openmp: Implement the error directive
This patch implements the error directive. Depending on clauses it is either a compile time diagnostics (in that case diagnosed right away) or runtime diagnostics (libgomp API call that diagnoses at runtime), and either fatal or warning (error or warning at compile time or fatal error vs. error at runtime) and either has no message or user supplied message (this kind of e.g. deprecated attribute). The directive is also stand-alone directive when at runtime while utility (thus disappears from the IL as if it wasn't there for parsing like nothing directive) at compile time. There are some clarifications in the works ATM, so this patch doesn't yet require that for compile time diagnostics the user message must be a constant string literal, there are uncertainities on what exactly is valid argument of message clause (whether just const char * type, convertible to const char *, qualified/unqualified const char * or char * or what else) and what to do in templates. Currently even in templates it is diagnosed right away for compile time diagnostics, if we'll need to substitute it, we'd need to queue something into the IL, have pt.c handle it and diagnose only later. 2021-08-20 Jakub Jelinek <jakub@redhat.com> gcc/ * omp-builtins.def (BUILT_IN_GOMP_WARNING, BUILT_IN_GOMP_ERROR): New builtins. gcc/c-family/ * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_ERROR. * c-pragma.c (omp_pragmas): Add error directive. * c-omp.c (omp_directives): Uncomment error directive entry. gcc/c/ * c-parser.c (c_parser_omp_error): New function. (c_parser_pragma): Handle PRAGMA_OMP_ERROR. gcc/cp/ * parser.c (cp_parser_handle_statement_omp_attributes): Determine if PRAGMA_OMP_ERROR directive is C_OMP_DIR_STANDALONE. (cp_parser_omp_error): New function. (cp_parser_pragma): Handle PRAGMA_OMP_ERROR. gcc/fortran/ * types.def (BT_FN_VOID_CONST_PTR_SIZE): New DEF_FUNCTION_TYPE_2. * f95-lang.c (ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST): Define. gcc/testsuite/ * c-c++-common/gomp/error-1.c: New test. * c-c++-common/gomp/error-2.c: New test. * c-c++-common/gomp/error-3.c: New test. * g++.dg/gomp/attrs-1.C (bar): Add error directive test. * g++.dg/gomp/attrs-2.C (bar): Add error directive test. * g++.dg/gomp/attrs-13.C: New test. * g++.dg/gomp/error-1.C: New test. libgomp/ * libgomp.map (GOMP_5.1): Add GOMP_error and GOMP_warning. * libgomp_g.h (GOMP_warning, GOMP_error): Declare. * error.c (GOMP_warning, GOMP_error): New functions. * testsuite/libgomp.c-c++-common/error-1.c: New test.
Diffstat (limited to 'libgomp/error.c')
-rw-r--r--libgomp/error.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libgomp/error.c b/libgomp/error.c
index 3ddf3aa..9b69a4b 100644
--- a/libgomp/error.c
+++ b/libgomp/error.c
@@ -89,3 +89,34 @@ gomp_fatal (const char *fmt, ...)
gomp_vfatal (fmt, list);
va_end (list);
}
+
+void
+GOMP_warning (const char *msg, size_t msglen)
+{
+ if (msg && msglen == (size_t) -1)
+ gomp_error ("error directive encountered: %s", msg);
+ else if (msg)
+ {
+ fputs ("\nlibgomp: error directive encountered: ", stderr);
+ fwrite (msg, 1, msglen, stderr);
+ fputc ('\n', stderr);
+ }
+ else
+ gomp_error ("error directive encountered");
+}
+
+void
+GOMP_error (const char *msg, size_t msglen)
+{
+ if (msg && msglen == (size_t) -1)
+ gomp_fatal ("fatal error: error directive encountered: %s", msg);
+ else if (msg)
+ {
+ fputs ("\nlibgomp: fatal error: error directive encountered: ", stderr);
+ fwrite (msg, 1, msglen, stderr);
+ fputc ('\n', stderr);
+ exit (EXIT_FAILURE);
+ }
+ else
+ gomp_fatal ("fatal error: error directive encountered");
+}