Skip to content

Commit 33b54f0

Browse files
authored
[flang] Move internal Fortran::ISO namespace out of user-facing ISO_F… (#72909)
…ortran_binding.h ... and into the ISO_Fortran_binding_wrapper.h header, through which the compiler and runtime access its contents. This change ensures that user code that #includes ISO_Fortran_binding.h within 'extern "C" {' doesn't encounter mysterious namespace errors.
1 parent c13f7e1 commit 33b54f0

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

flang/include/flang/ISO_Fortran_binding.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
#ifndef CFI_ISO_FORTRAN_BINDING_H_
1111
#define CFI_ISO_FORTRAN_BINDING_H_
1212

13+
/* When this header is included into the compiler and runtime implementations,
14+
* it does so by means of a wrapper header that establishes namespaces and
15+
* a macro for extra function attributes (RT_API_ATTRS).
16+
*/
17+
#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
1318
#include <stddef.h>
19+
#define FORTRAN_ISO_NAMESPACE_
20+
#endif
1421

1522
/* Standard interface to Fortran from C and C++.
1623
* These interfaces are named in subclause 18.5 of the Fortran 2018
@@ -22,12 +29,6 @@
2229
#define RT_API_ATTRS
2330
#endif
2431

25-
#ifdef __cplusplus
26-
namespace Fortran {
27-
namespace ISO {
28-
inline namespace Fortran_2018 {
29-
#endif
30-
3132
/* 18.5.4 */
3233
#define CFI_VERSION 20180515
3334

@@ -169,7 +170,8 @@ template <int r> struct CdescStorage : public CFI_cdesc_t {
169170
template <> struct CdescStorage<1> : public CFI_cdesc_t {};
170171
template <> struct CdescStorage<0> : public CFI_cdesc_t {};
171172
} // namespace cfi_internal
172-
#define CFI_CDESC_T(rank) ::Fortran::ISO::cfi_internal::CdescStorage<rank>
173+
#define CFI_CDESC_T(rank) \
174+
FORTRAN_ISO_NAMESPACE_::cfi_internal::CdescStorage<rank>
173175
#else
174176
#define CFI_CDESC_T(_RANK) \
175177
struct { \
@@ -199,9 +201,6 @@ RT_API_ATTRS int CFI_setpointer(
199201
CFI_cdesc_t *, const CFI_cdesc_t *source, const CFI_index_t lower_bounds[]);
200202
#ifdef __cplusplus
201203
} // extern "C"
202-
} // inline namespace Fortran_2018
203-
} // namespace ISO
204-
} // namespace Fortran
205204
#endif
206205

207206
#endif /* CFI_ISO_FORTRAN_BINDING_H_ */

flang/include/flang/ISO_Fortran_binding_wrapper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@
2222
*/
2323

2424
/* clang-format off */
25+
#include <stddef.h>
2526
#include "Runtime/api-attrs.h"
27+
#ifdef __cplusplus
28+
namespace Fortran {
29+
namespace ISO {
30+
#define FORTRAN_ISO_NAMESPACE_ ::Fortran::ISO
31+
#endif /* __cplusplus */
2632
#include "ISO_Fortran_binding.h"
33+
#ifdef __cplusplus
34+
} // namespace ISO
35+
} // namespace Fortran
36+
#endif /* __cplusplus */
2737
/* clang-format on */
2838

2939
#endif /* FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ */

flang/lib/Optimizer/CodeGen/DescriptorModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ getModel<Fortran::ISO::cfi_internal::FlexibleArray<Fortran::ISO::CFI_dim_t>>() {
113113
/// Get the type model of the field number `Field` in an ISO CFI descriptor.
114114
template <int Field>
115115
static constexpr TypeBuilderFunc getDescFieldTypeModel() {
116-
Fortran::ISO::Fortran_2018::CFI_cdesc_t dummyDesc{};
116+
Fortran::ISO::CFI_cdesc_t dummyDesc{};
117117
// check that the descriptor is exactly 8 fields as specified in CFI_cdesc_t
118118
// in flang/include/flang/ISO_Fortran_binding.h.
119119
auto [a, b, c, d, e, f, g, h] = dummyDesc;

0 commit comments

Comments
 (0)