[2/5] c++, openmp: Fix wrong error messages

Message ID 20260407110826.8427-2-yangkun@disroot.org
State New
Headers
Series [1/5] c++: gcc_assert(false) replaced with gcc_unreachable() |

Commit Message

yangkun April 7, 2026, 11:08 a.m. UTC
  Error messages wrongly said "invalid depend kind"

gcc/cp/ChangeLog:
	* parser.cc (cp_parser_omp_clause_proc_bind): Fix error message
	(cp_parser_omp_clause_device_type): Likewise.

gcc/testsuite/ChangeLog:
	* gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C: New test.
---
 gcc/cp/parser.cc                            |  4 ++--
 gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C
  

Comments

Jakub Jelinek April 7, 2026, 3:50 p.m. UTC | #1
On Tue, Apr 07, 2026 at 07:08:23PM +0800, Yang Kun wrote:
> Error messages wrongly said "invalid depend kind"
> 
> gcc/cp/ChangeLog:
> 	* parser.cc (cp_parser_omp_clause_proc_bind): Fix error message
> 	(cp_parser_omp_clause_device_type): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 	* gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C: New test.
> ---
>  gcc/cp/parser.cc                            |  4 ++--
>  gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C | 12 ++++++++++++
>  2 files changed, 14 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C

LGTM, but do you have FSF Copyright assignment on file or do you wish
to submit this under DCO?
See https://gcc.gnu.org/contribute.html#legal
If under DCO, then it needs to be reposted with a Signed-Off-By line.

Checked the C FE and it doesn't have this bug, and for device_type
it even has better diagnostics of
  c_parser_error (parser, "expected %<host%>, %<nohost%> or %<any%>");
I guess we should for GCC 17 move to listing what are the valid kinds
unless the list is really long.

	Jakub
  
yangkun April 8, 2026, 9:01 a.m. UTC | #2
> LGTM, but do you have FSF Copyright assignment on file or do you wish
> to submit this under DCO?
> See https://gcc.gnu.org/contribute.html#legal
> If under DCO, then it needs to be reposted with a Signed-Off-By line.
Okay, I've added the "Signed-off-by:" line. Is that okay now?

> Checked the C FE and it doesn't have this bug, and for device_type
> it even has better diagnostics of
> c_parser_error (parser, "expected %<host%>, %<nohost%> or %<any%>");
> I guess we should for GCC 17 move to listing what are the valid kinds
> unless the list is really long.
I've updated the error message for `device_type` to match the C front 
end,
please have a review. Also, I thought this was a minor change that 
didn't
require testing, so I removed it.

Additionally, I'm not sure how to reply to emails sent using `git 
send-email`,
so I'm sending these patches as attachments.
  
Jakub Jelinek April 8, 2026, 1:46 p.m. UTC | #3
On Wed, Apr 08, 2026 at 11:01:44AM +0200, yangkun wrote:
> > LGTM, but do you have FSF Copyright assignment on file or do you wish
> > to submit this under DCO?
> > See https://gcc.gnu.org/contribute.html#legal
> > If under DCO, then it needs to be reposted with a Signed-Off-By line.
> Okay, I've added the "Signed-off-by:" line. Is that okay now?
> 
> > Checked the C FE and it doesn't have this bug, and for device_type
> > it even has better diagnostics of
> > c_parser_error (parser, "expected %<host%>, %<nohost%> or %<any%>");
> > I guess we should for GCC 17 move to listing what are the valid kinds
> > unless the list is really long.
> I've updated the error message for `device_type` to match the C front end,
> please have a review. Also, I thought this was a minor change that didn't
> require testing, so I removed it.
> 
> Additionally, I'm not sure how to reply to emails sent using `git
> send-email`,
> so I'm sending these patches as attachments.

Thanks, approved and committed now.

	Jakub
  

Patch

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 7b800af78..832d03f9f 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -45815,7 +45815,7 @@  cp_parser_omp_clause_proc_bind (cp_parser *parser, tree list,
   return c;
 
  invalid_kind:
-  cp_parser_error (parser, "invalid depend kind");
+  cp_parser_error (parser, "invalid proc_bind kind");
  resync_fail:
   cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
 					 /*or_comma=*/false,
@@ -45882,7 +45882,7 @@  cp_parser_omp_clause_device_type (cp_parser *parser, tree list,
   return c;
 
  invalid_kind:
-  cp_parser_error (parser, "invalid depend kind");
+  cp_parser_error (parser, "invalid device_type kind");
  resync_fail:
   cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
 					 /*or_comma=*/false,
diff --git a/gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C b/gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C
new file mode 100644
index 000000000..608f63611
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/clause-errmsg-1.C
@@ -0,0 +1,12 @@ 
+// Verify that proc_bind and device_type clauses name the right clause
+// in their diagnostics, not "depend".
+// { dg-do compile }
+// { dg-additional-options "-fopenmp" }
+
+void f () {
+  #pragma omp parallel proc_bind(bad)		// { dg-error "invalid proc_bind kind" }
+  ;
+}
+
+#pragma omp declare target device_type(bad)	// { dg-error "invalid device_type kind" }
+void g() {}