[flang-commits] [flang] 668f261 - [flang] Make ISO_Fortran_binding.h a standalone header again.

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Aug 22 18:56:33 PDT 2023


Author: Slava Zakharin
Date: 2023-08-22T18:56:27-07:00
New Revision: 668f261bfa53d6f9cd9131ca6b1079ec940ab81b

URL: https://github.com/llvm/llvm-project/commit/668f261bfa53d6f9cd9131ca6b1079ec940ab81b
DIFF: https://github.com/llvm/llvm-project/commit/668f261bfa53d6f9cd9131ca6b1079ec940ab81b.diff

LOG: [flang] Make ISO_Fortran_binding.h a standalone header again.

This implements the proposal from
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442/6
Since ISO_Fortran_binding.h is supposed to be included from users'
C/C++ codes, it would better have no dependencies on other header
files.

Reviewed By: PeteSteinfeld

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

Added: 
    flang/include/flang/ISO_Fortran_binding_wrapper.h

Modified: 
    flang/include/flang/ISO_Fortran_binding.h
    flang/include/flang/Optimizer/Support/TypeCode.h
    flang/include/flang/Runtime/descriptor.h
    flang/include/flang/Runtime/type-code.h
    flang/lib/Optimizer/CodeGen/CodeGen.cpp
    flang/lib/Optimizer/CodeGen/DescriptorModel.h
    flang/lib/Optimizer/Dialect/FIRType.cpp
    flang/lib/Optimizer/Transforms/LoopVersioning.cpp
    flang/runtime/ISO_Fortran_binding.cpp
    flang/runtime/ISO_Fortran_util.h
    flang/runtime/allocatable.cpp
    flang/runtime/stat.h
    flang/runtime/temporary-stack.cpp
    flang/unittests/Evaluate/ISO-Fortran-binding.cpp
    flang/unittests/Runtime/TemporaryStack.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index a0e05db1c16816..e576da753f1940 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -18,7 +18,9 @@
  * implementation.
  */
 
-#include "Runtime/api-attrs.h"
+#ifndef RT_API_ATTRS
+#define RT_API_ATTRS
+#endif
 
 #ifdef __cplusplus
 namespace Fortran {

diff  --git a/flang/include/flang/ISO_Fortran_binding_wrapper.h b/flang/include/flang/ISO_Fortran_binding_wrapper.h
new file mode 100644
index 00000000000000..c810ebccdbcadd
--- /dev/null
+++ b/flang/include/flang/ISO_Fortran_binding_wrapper.h
@@ -0,0 +1,29 @@
+/*===-- include/flang/ISO_Fortran_binding_wrapper.h ---------------*- C++ -*-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ * ===-----------------------------------------------------------------------===
+ */
+
+#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#define FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+
+/* A thin wrapper around flang/include/ISO_Fortran_binding.h
+ * This header file must be included when ISO_Fortran_binding.h
+ * definitions/declarations are needed in Flang compiler/runtime
+ * sources. The inclusion of Runtime/api-attrs.h below sets up
+ * proper values for the macros used in ISO_Fortran_binding.h
+ * for the device offload builds.
+ * flang/include/ISO_Fortran_binding.h is made a standalone
+ * header file so that it can be used on its own in users'
+ * C/C++ programs.
+ */
+
+/* clang-format off */
+#include "Runtime/api-attrs.h"
+#include "ISO_Fortran_binding.h"
+/* clang-format on */
+
+#endif /* FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ */

diff  --git a/flang/include/flang/Optimizer/Support/TypeCode.h b/flang/include/flang/Optimizer/Support/TypeCode.h
index fef937b518aa85..308c82118d5020 100644
--- a/flang/include/flang/Optimizer/Support/TypeCode.h
+++ b/flang/include/flang/Optimizer/Support/TypeCode.h
@@ -13,7 +13,7 @@
 #ifndef FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
 #define FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
 
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace fir {

diff  --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h
index 318c0ab47d209e..62a8d123bf2ee0 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/flang/include/flang/Runtime/descriptor.h
@@ -18,7 +18,7 @@
 // User C code is welcome to depend on that ISO_Fortran_binding.h file,
 // but should never reference this internal header.
 
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/memory.h"
 #include "flang/Runtime/type-code.h"
 #include <algorithm>

diff  --git a/flang/include/flang/Runtime/type-code.h b/flang/include/flang/Runtime/type-code.h
index 21e4102c8be797..df38611ab8760a 100644
--- a/flang/include/flang/Runtime/type-code.h
+++ b/flang/include/flang/Runtime/type-code.h
@@ -10,7 +10,7 @@
 #define FORTRAN_RUNTIME_TYPE_CODE_H_
 
 #include "flang/Common/Fortran.h"
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include <optional>
 #include <utility>
 

diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 0fbee616ac9a51..76c15547429195 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -13,7 +13,6 @@
 #include "flang/Optimizer/CodeGen/CodeGen.h"
 
 #include "CGOps.h"
-#include "flang/ISO_Fortran_binding.h"
 #include "flang/Optimizer/Dialect/FIRAttr.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIRType.h"

diff  --git a/flang/lib/Optimizer/CodeGen/DescriptorModel.h b/flang/lib/Optimizer/CodeGen/DescriptorModel.h
index 964e18885e7fbb..19b53d4b843f38 100644
--- a/flang/lib/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/lib/Optimizer/CodeGen/DescriptorModel.h
@@ -22,7 +22,7 @@
 #ifndef OPTIMIZER_DESCRIPTOR_MODEL_H
 #define OPTIMIZER_DESCRIPTOR_MODEL_H
 
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/BuiltinTypes.h"

diff  --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index b3f5653815c3f0..c1fc8494cb65d1 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -11,7 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Optimizer/Dialect/FIRType.h"
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
 #include "flang/Tools/PointerModels.h"

diff  --git a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
index 63786e377bb4a5..c191df21d5abc1 100644
--- a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
+++ b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
@@ -40,7 +40,7 @@
 ///       could be part of the cost analysis above.
 //===----------------------------------------------------------------------===//
 
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Runtime/Inquiry.h"

diff  --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang/runtime/ISO_Fortran_binding.cpp
index a9e2c3e11eb08b..8130875e47360f 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang/runtime/ISO_Fortran_binding.cpp
@@ -9,9 +9,9 @@
 // Implements the required interoperability API from ISO_Fortran_binding.h
 // as specified in section 18.5.5 of Fortran 2018.
 
-#include "flang/ISO_Fortran_binding.h"
 #include "ISO_Fortran_util.h"
 #include "terminator.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/type-code.h"
 #include <cstdlib>

diff  --git a/flang/runtime/ISO_Fortran_util.h b/flang/runtime/ISO_Fortran_util.h
index c829a822eb387b..7d527bfd65789d 100644
--- a/flang/runtime/ISO_Fortran_util.h
+++ b/flang/runtime/ISO_Fortran_util.h
@@ -12,7 +12,7 @@
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
 #include "terminator.h"
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/type-code.h"
 #include <cstdlib>

diff  --git a/flang/runtime/allocatable.cpp b/flang/runtime/allocatable.cpp
index 96da5868f5f87d..b53440c2c3fad6 100644
--- a/flang/runtime/allocatable.cpp
+++ b/flang/runtime/allocatable.cpp
@@ -12,7 +12,7 @@
 #include "stat.h"
 #include "terminator.h"
 #include "type-info.h"
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
 #include "flang/Runtime/descriptor.h"
 

diff  --git a/flang/runtime/stat.h b/flang/runtime/stat.h
index e5b49d625912df..7ba797c3741869 100644
--- a/flang/runtime/stat.h
+++ b/flang/runtime/stat.h
@@ -11,7 +11,7 @@
 
 #ifndef FORTRAN_RUNTIME_STAT_H_
 #define FORTRAN_RUNTIME_STAT_H_
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/magic-numbers.h"
 namespace Fortran::runtime {
 

diff  --git a/flang/runtime/temporary-stack.cpp b/flang/runtime/temporary-stack.cpp
index 9107eb7654db48..b4d7c6064457f2 100644
--- a/flang/runtime/temporary-stack.cpp
+++ b/flang/runtime/temporary-stack.cpp
@@ -11,7 +11,7 @@
 
 #include "flang/Runtime/temporary-stack.h"
 #include "terminator.h"
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/memory.h"

diff  --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
index d356d19add8fef..09a51e6cea10b7 100644
--- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -1,5 +1,5 @@
 #include "testing.h"
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
 #include "llvm/Support/raw_ostream.h"
 #include <type_traits>

diff  --git a/flang/unittests/Runtime/TemporaryStack.cpp b/flang/unittests/Runtime/TemporaryStack.cpp
index 8ca5a27a4c15c7..0a9344969ca6ba 100644
--- a/flang/unittests/Runtime/TemporaryStack.cpp
+++ b/flang/unittests/Runtime/TemporaryStack.cpp
@@ -8,7 +8,7 @@
 
 #include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"


        


More information about the flang-commits mailing list