[flang] Add bind(C) to buitlin C_PTR
authorValentin Clement <clementval@gmail.com>
Mon, 22 Aug 2022 09:12:20 +0000 (11:12 +0200)
committerValentin Clement <clementval@gmail.com>
Mon, 22 Aug 2022 09:12:37 +0000 (11:12 +0200)
D131585 Adds couple of semantics check for the components of BIND(C)
derived-type. This would raise an error when a component is of C_PTR
type. Add `bind(c)` to the `__builtin_c_ptr` type so the wrong error
is not triggered.

Reviewed By: peixin, jeanPerier

Differential Revision: https://reviews.llvm.org/D132350

flang/module/__fortran_builtins.f90
flang/test/Semantics/bind-c07.f90 [new file with mode: 0644]

index 19184c8..487041a 100644 (file)
@@ -19,7 +19,7 @@ module __Fortran_builtins
   private :: selected_int_kind
   integer, parameter, private :: int64 = selected_int_kind(18)
 
-  type :: __builtin_c_ptr
+  type, bind(c) :: __builtin_c_ptr
     integer(kind=int64) :: __address
   end type
 
diff --git a/flang/test/Semantics/bind-c07.f90 b/flang/test/Semantics/bind-c07.f90
new file mode 100644 (file)
index 0000000..ee39f5e
--- /dev/null
@@ -0,0 +1,11 @@
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+module bind_c_type
+  use, intrinsic :: iso_c_binding
+
+  type, bind(C) :: t
+    type(c_ptr) :: tcptr = C_NULL_PTR
+  end type
+end module
+
+! CHECK-LABEL: _QMbind_c_typeE.di.t.tcptr