[committed] Diagnose #pragma omp declare target without corresponding #pragma omp end declare target
diff mbox series

Message ID 20191111200709.GY4650@tucnak
State New
Headers show
Series
  • [committed] Diagnose #pragma omp declare target without corresponding #pragma omp end declare target
Related show

Commit Message

Jakub Jelinek Nov. 11, 2019, 8:07 p.m. UTC
Hi!

I found a bug in OpenMP 5.0 examples that GCC didn't flag as an error.
The following patch implements the missing diagnostics.

Bootstrapped/regtested on powerpc64le-linux, committed to trunk.

2019-11-11  Jakub Jelinek  <jakub@redhat.com>

	* c-parser.c (c_parser_translation_unit): Diagnose declare target
	without corresponding end declare target.

	* semantics.c (finish_translation_unit): Diagnose declare target
	without corresponding end declare target.

	* c-c++-common/gomp/declare-target-5.c: New test.


	Jakub

Patch
diff mbox series

--- gcc/c/c-parser.c.jj	2019-11-08 09:03:56.271250390 +0100
+++ gcc/c/c-parser.c	2019-11-11 11:09:46.910702347 +0100
@@ -1554,6 +1554,14 @@  c_parser_translation_unit (c_parser *par
   FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl)
     if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node)
       error ("storage size of %q+D isn%'t known", decl);
+
+  if (current_omp_declare_target_attribute)
+    {
+      if (!errorcount)
+        error ("%<#pragma omp declare target%> without corresponding "
+	       "%<#pragma omp end declare target%>");
+      current_omp_declare_target_attribute = 0;
+    }
 }
 
 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
--- gcc/cp/semantics.c.jj	2019-11-02 00:26:48.932847353 +0100
+++ gcc/cp/semantics.c	2019-11-11 11:29:55.009396475 +0100
@@ -3048,6 +3048,14 @@  finish_translation_unit (void)
 
   /* Do file scope __FUNCTION__ et al.  */
   finish_fname_decls ();
+
+  if (scope_chain->omp_declare_target_attribute)
+    {
+      if (!errorcount)
+	error ("%<#pragma omp declare target%> without corresponding "
+	       "%<#pragma omp end declare target%>");
+      scope_chain->omp_declare_target_attribute = 0;
+    }
 }
 
 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
--- gcc/testsuite/c-c++-common/gomp/declare-target-5.c.jj	2019-11-11 11:11:04.577524594 +0100
+++ gcc/testsuite/c-c++-common/gomp/declare-target-5.c	2019-11-11 11:18:40.289619051 +0100
@@ -0,0 +1,2 @@ 
+#pragma omp declare target
+void foo (void);	/* { dg-error "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */