diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h --- 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 --- /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 --- 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 --- 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 diff --git a/flang/include/flang/Runtime/type-code.h b/flang/include/flang/Runtime/type-code.h --- 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 #include diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- 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 --- 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 --- 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 --- 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 --- 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 diff --git a/flang/runtime/ISO_Fortran_util.h b/flang/runtime/ISO_Fortran_util.h --- 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 diff --git a/flang/runtime/allocatable.cpp b/flang/runtime/allocatable.cpp --- 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 --- 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 --- 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 --- 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 diff --git a/flang/unittests/Runtime/TemporaryStack.cpp b/flang/unittests/Runtime/TemporaryStack.cpp --- 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"