[flang] Add IsIsoCType()
authorTim Keith <tkeith@nvidia.com>
Sat, 22 Jun 2019 00:32:11 +0000 (17:32 -0700)
committerTim Keith <tkeith@nvidia.com>
Sat, 22 Jun 2019 00:32:11 +0000 (17:32 -0700)
It identifies the types `C_PTR` and `C_FUNPTR` from predefined
module `ISO_C_BINDING`.

Original-commit: flang-compiler/f18@fcbef2e18b1b035429cb5b9e5d765bc89c2412ca
Reviewed-on: https://github.com/flang-compiler/f18/pull/521
Tree-same-pre-rewrite: false

flang/lib/semantics/check-allocate.cc
flang/lib/semantics/tools.cc
flang/lib/semantics/tools.h

index 90a266d..aa0d0da 100644 (file)
@@ -556,8 +556,7 @@ bool AllocationCheckerHelper::RunCoarrayRelatedChecks(
                   "Type-Spec in ALLOCATE must not be TEAM_TYPE from ISO_FORTRAN_ENV when an allocatable object is a coarray"_err_en_US)
               .Attach(name_.source, "'%s' is a coarray"_en_US, name_.source);
           return false;
-        } else if (IsDerivedTypeFromModule(derived, "iso_c_binding", "c_ptr") ||
-            IsDerivedTypeFromModule(derived, "iso_c_binding", "c_funptr")) {
+        } else if (IsIsoCType(derived)) {
           context
               .Say(allocateInfo_.typeSpecLoc.value(),
                   "Type-Spec in ALLOCATE must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray"_err_en_US)
@@ -578,9 +577,7 @@ bool AllocationCheckerHelper::RunCoarrayRelatedChecks(
                   "SOURCE or MOLD expression type must not be TEAM_TYPE from ISO_FORTRAN_ENV when an allocatable object is a coarray"_err_en_US)
               .Attach(name_.source, "'%s' is a coarray"_en_US, name_.source);
           return false;
-        } else if (IsDerivedTypeFromModule(
-                       &derived, "iso_c_binding", "c_ptr") ||
-            IsDerivedTypeFromModule(&derived, "iso_c_binding", "c_funptr")) {
+        } else if (IsIsoCType(&derived)) {
           context
               .Say(allocateInfo_.sourceExprLoc.value(),
                   "SOURCE or MOLD expression type must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray"_err_en_US)
index c388619..ecdccfb 100644 (file)
@@ -304,6 +304,11 @@ bool IsDerivedTypeFromModule(
   }
 }
 
+bool IsIsoCType(const DerivedTypeSpec *derived) {
+  return IsDerivedTypeFromModule(derived, "iso_c_binding", "c_ptr") ||
+      IsDerivedTypeFromModule(derived, "iso_c_binding", "c_funptr");
+}
+
 bool IsTeamType(const DerivedTypeSpec *derived) {
   return IsDerivedTypeFromModule(derived, "iso_fortran_env", "team_type");
 }
index e1de67c..280f4e4 100644 (file)
@@ -60,7 +60,10 @@ bool IsProcedurePointer(const Symbol &);
 // Is this a derived type from module with this name?
 bool IsDerivedTypeFromModule(
     const DerivedTypeSpec *derived, const char *module, const char *name);
-bool IsTeamType(const DerivedTypeSpec *derived);
+// Is this derived type TEAM_TYPE from module ISO_FORTRAN_ENV
+bool IsTeamType(const DerivedTypeSpec *);
+// Is this derived type either C_PTR or C_FUNPTR from module ISO_C_BINDING
+bool IsIsoCType(const DerivedTypeSpec *);
 const bool IsEventTypeOrLockType(const DerivedTypeSpec *);
 // Returns an ultimate component symbol that is a
 // coarray or nullptr if there are no such component.