]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Improve OpenMP map diagnostics.
authorAndrew Stubbs <ams@codesourcery.com>
Thu, 4 Jul 2019 11:43:47 +0000 (11:43 +0000)
committerThomas Schwinge <thomas@codesourcery.com>
Tue, 3 Mar 2020 11:48:34 +0000 (12:48 +0100)
2019-07-04  Andrew Stubbs  <ams@codesourcery.com>

Backport from mainline:
2019-07-04  Andrew Stubbs  <ams@codesourcery.com>

gcc/cp/
* cp-tree.h (cp_omp_emit_unmappable_type_notes): New prototype.
* decl.c (cp_finish_decl): Call cp_omp_emit_unmappable_type_notes.
* decl2.c (cp_omp_mappable_type): Move contents to ...
(cp_omp_mappable_type_1):  ... here and add note output.
(cp_omp_emit_unmappable_type_notes): New function.
* semantics.c (finish_omp_clauses): Call
cp_omp_emit_unmappable_type_notes in four places.

gcc/testsuite/
* g++.dg/gomp/unmappable-1.C: New file.

(cherry picked from openacc-gcc-9-branch commit
d12faf81132cbd663cbe74aeb0c31c7dbf73495e)

gcc/cp/ChangeLog.omp
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/g++.dg/gomp/unmappable-1.C [new file with mode: 0644]

index 9d16175e1f27755c7b6ac1440899b3864c0bdc83..11ed1e729ef3f4e8bd6ec22c31f0edf3db0181fb 100644 (file)
@@ -1,3 +1,16 @@
+2019-07-04  Andrew Stubbs  <ams@codesourcery.com>
+
+       Backport from mainline:
+       2019-07-04  Andrew Stubbs  <ams@codesourcery.com>
+
+       * cp-tree.h (cp_omp_emit_unmappable_type_notes): New prototype.
+       * decl.c (cp_finish_decl): Call cp_omp_emit_unmappable_type_notes.
+       * decl2.c (cp_omp_mappable_type): Move contents to ...
+       (cp_omp_mappable_type_1):  ... here and add note output.
+       (cp_omp_emit_unmappable_type_notes): New function.
+       * semantics.c (finish_omp_clauses): Call
+       cp_omp_emit_unmappable_type_notes in four places.
+
 2018-12-19  Julian Brown  <julian@codesourcery.com>
             Maciej W. Rozycki  <macro@codesourcery.com>
 
index ff4ce068a83601bb083f4b3e848cea6569d48b0a..515d40fc6b2208fe82f5204eb84db0877755aab1 100644 (file)
@@ -6533,6 +6533,7 @@ extern int parm_index                           (tree);
 extern tree vtv_start_verification_constructor_init_function (void);
 extern tree vtv_finish_verification_constructor_init_function (tree);
 extern bool cp_omp_mappable_type               (tree);
+extern bool cp_omp_emit_unmappable_type_notes  (tree);
 extern void cp_check_const_attributes (tree);
 
 /* in error.c */
index 01c89cd572d12f9afacc83986568da116e1cbcca..1c45172773632965e733b199702d7d97ddb9d0bb 100644 (file)
@@ -7406,8 +7406,11 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
                            DECL_ATTRIBUTES (decl));
       complete_type (TREE_TYPE (decl));
       if (!cp_omp_mappable_type (TREE_TYPE (decl)))
-       error ("%q+D in declare target directive does not have mappable type",
-              decl);
+       {
+         error ("%q+D in declare target directive does not have mappable"
+                " type", decl);
+         cp_omp_emit_unmappable_type_notes (TREE_TYPE (decl));
+       }
       else if (!lookup_attribute ("omp declare target",
                                  DECL_ATTRIBUTES (decl))
               && !lookup_attribute ("omp declare target link",
index 6f23ee1cd3fe853a13840f3b68ca11f823b4f86e..b10f7306f34b222aa92bb9e73bbed11e99f75f84 100644 (file)
@@ -1406,32 +1406,68 @@ cp_check_const_attributes (tree attributes)
     }
 }
 
-/* Return true if TYPE is an OpenMP mappable type.  */
-bool
-cp_omp_mappable_type (tree type)
+/* Return true if TYPE is an OpenMP mappable type.
+   If NOTES is non-zero, emit a note message for each problem.  */
+static bool
+cp_omp_mappable_type_1 (tree type, bool notes)
 {
+  bool result = true;
+
   /* Mappable type has to be complete.  */
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
-    return false;
+    {
+      if (notes)
+       {
+         tree decl = TYPE_MAIN_DECL (type);
+         inform ((decl ? DECL_SOURCE_LOCATION (decl) : input_location),
+                 "incomplete type %qT is not mappable", type);
+       }
+      result = false;
+    }
   /* Arrays have mappable type if the elements have mappable type.  */
   while (TREE_CODE (type) == ARRAY_TYPE)
     type = TREE_TYPE (type);
   /* A mappable type cannot contain virtual members.  */
   if (CLASS_TYPE_P (type) && CLASSTYPE_VTABLES (type))
-    return false;
+    {
+      if (notes)
+       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
+               "type %qT with virtual members is not mappable", type);
+      result = false;
+    }
   /* All data members must be non-static.  */
   if (CLASS_TYPE_P (type))
     {
       tree field;
       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
        if (VAR_P (field))
-         return false;
+         {
+           if (notes)
+             inform (DECL_SOURCE_LOCATION (field),
+                     "static field %qD is not mappable", field);
+           result = false;
+         }
        /* All fields must have mappable types.  */
        else if (TREE_CODE (field) == FIELD_DECL
-                && !cp_omp_mappable_type (TREE_TYPE (field)))
-         return false;
+                && !cp_omp_mappable_type_1 (TREE_TYPE (field), notes))
+         result = false;
     }
-  return true;
+  return result;
+}
+
+/* Return true if TYPE is an OpenMP mappable type.  */
+bool
+cp_omp_mappable_type (tree type)
+{
+  return cp_omp_mappable_type_1 (type, false);
+}
+
+/* Return true if TYPE is an OpenMP mappable type.
+   Emit an error messages if not.  */
+bool
+cp_omp_emit_unmappable_type_notes (tree type)
+{
+  return cp_omp_mappable_type_1 (type, true);
 }
 
 /* Return the last pushed declaration for the symbol DECL or NULL
index 657f23c6a582a06dbfc3ca5bc273caeae71345f6..b8fa0c795bedeaedc61b8beec3676fa7925a7e0e 100644 (file)
@@ -7186,6 +7186,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
                                "array section does not have mappable type "
                                "in %qs clause",
                                omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+                     cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
                      remove = true;
                    }
                  while (TREE_CODE (t) == ARRAY_REF)
@@ -7267,6 +7268,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
                  error_at (OMP_CLAUSE_LOCATION (c),
                            "%qE does not have a mappable type in %qs clause",
                            t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+                 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
                  remove = true;
                }
              while (TREE_CODE (t) == COMPONENT_REF)
@@ -7345,6 +7347,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
              error_at (OMP_CLAUSE_LOCATION (c),
                        "%qD does not have a mappable type in %qs clause", t,
                        omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+             cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
              remove = true;
            }
          else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
@@ -7495,6 +7498,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
              error_at (OMP_CLAUSE_LOCATION (c),
                        "%qD does not have a mappable type in %qs clause", t,
                        omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+             cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
              remove = true;
            }
          if (remove)
index bca34723c90b6f6bcb02d2047a8e2d62c88e388d..fc20b357f3f085476cf50fe103ad4832f07e670b 100644 (file)
@@ -1,3 +1,10 @@
+2019-07-04  Andrew Stubbs  <ams@codesourcery.com>
+
+       Backport from mainline:
+       2019-07-04  Andrew Stubbs  <ams@codesourcery.com>
+
+       * g++.dg/gomp/unmappable-1.C: New file.
+
 2019-05-31  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        * c-c++-common/goacc/kernels-decompose-1.c: Change 'note:' to
diff --git a/gcc/testsuite/g++.dg/gomp/unmappable-1.C b/gcc/testsuite/g++.dg/gomp/unmappable-1.C
new file mode 100644 (file)
index 0000000..d00ccb5
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+class C /* { dg-message "type .C. with virtual members is not mappable" } */
+{
+public:
+  static int static_member; /* { dg-message "static field .C::static_member. is not mappable" } */
+  virtual void f() {}
+};
+
+extern C v[];
+
+int
+main ()
+{
+#pragma omp target map(v) /* { dg-error ".v. does not have a mappable type in .map. clause" } */
+  /* { dg-message "incomplete type .C \\\[\\\]. is not mappable" "" { target *-*-* } .-1 } */
+  {
+  }
+}