diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h index 51d6219427cce..dd384c516263e 100644 --- a/flang/include/flang/ISO_Fortran_binding.h +++ b/flang/include/flang/ISO_Fortran_binding.h @@ -10,7 +10,14 @@ #ifndef CFI_ISO_FORTRAN_BINDING_H_ #define CFI_ISO_FORTRAN_BINDING_H_ +/* When this header is included into the compiler and runtime implementations, + * it does so by means of a wrapper header that establishes namespaces and + * a macro for extra function attributes (RT_API_ATTRS). + */ +#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ #include +#define FORTRAN_ISO_NAMESPACE_ +#endif /* Standard interface to Fortran from C and C++. * These interfaces are named in subclause 18.5 of the Fortran 2018 @@ -22,12 +29,6 @@ #define RT_API_ATTRS #endif -#ifdef __cplusplus -namespace Fortran { -namespace ISO { -inline namespace Fortran_2018 { -#endif - /* 18.5.4 */ #define CFI_VERSION 20180515 @@ -169,7 +170,8 @@ template struct CdescStorage : public CFI_cdesc_t { template <> struct CdescStorage<1> : public CFI_cdesc_t {}; template <> struct CdescStorage<0> : public CFI_cdesc_t {}; } // namespace cfi_internal -#define CFI_CDESC_T(rank) ::Fortran::ISO::cfi_internal::CdescStorage +#define CFI_CDESC_T(rank) \ + FORTRAN_ISO_NAMESPACE_::cfi_internal::CdescStorage #else #define CFI_CDESC_T(_RANK) \ struct { \ @@ -199,9 +201,6 @@ RT_API_ATTRS int CFI_setpointer( CFI_cdesc_t *, const CFI_cdesc_t *source, const CFI_index_t lower_bounds[]); #ifdef __cplusplus } // extern "C" -} // inline namespace Fortran_2018 -} // namespace ISO -} // namespace Fortran #endif #endif /* CFI_ISO_FORTRAN_BINDING_H_ */ diff --git a/flang/include/flang/ISO_Fortran_binding_wrapper.h b/flang/include/flang/ISO_Fortran_binding_wrapper.h index c810ebccdbcad..83c974365e343 100644 --- a/flang/include/flang/ISO_Fortran_binding_wrapper.h +++ b/flang/include/flang/ISO_Fortran_binding_wrapper.h @@ -22,8 +22,18 @@ */ /* clang-format off */ +#include #include "Runtime/api-attrs.h" +#ifdef __cplusplus +namespace Fortran { +namespace ISO { +#define FORTRAN_ISO_NAMESPACE_ ::Fortran::ISO +#endif /* __cplusplus */ #include "ISO_Fortran_binding.h" +#ifdef __cplusplus +} // namespace ISO +} // namespace Fortran +#endif /* __cplusplus */ /* clang-format on */ #endif /* FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ */ diff --git a/flang/lib/Optimizer/CodeGen/DescriptorModel.h b/flang/lib/Optimizer/CodeGen/DescriptorModel.h index 39427a42f0f4d..ed35caef93014 100644 --- a/flang/lib/Optimizer/CodeGen/DescriptorModel.h +++ b/flang/lib/Optimizer/CodeGen/DescriptorModel.h @@ -113,7 +113,7 @@ getModel>() { /// Get the type model of the field number `Field` in an ISO CFI descriptor. template static constexpr TypeBuilderFunc getDescFieldTypeModel() { - Fortran::ISO::Fortran_2018::CFI_cdesc_t dummyDesc{}; + Fortran::ISO::CFI_cdesc_t dummyDesc{}; // check that the descriptor is exactly 8 fields as specified in CFI_cdesc_t // in flang/include/flang/ISO_Fortran_binding.h. auto [a, b, c, d, e, f, g, h] = dummyDesc;