6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
// Implements the required interoperability API from ISO_Fortran_binding.h
// as specified in section 18.5.5 of Fortran 2018.

#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "ISO_Fortran_util.h"
#include "terminator.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/pointer.h"
#include "flang/Runtime/type-code.h"
#include "terminator.h"
#include <cstdlib>

namespace Fortran::ISO {
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/ISO_Fortran_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// Internal utils for establishing CFI_cdesc_t descriptors.

#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/type-code.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "terminator.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include <cstdlib>

namespace Fortran::ISO {
Expand Down
10 changes: 7 additions & 3 deletions FortranRuntime/lib/Runtime/allocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/allocatable.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "assign-impl.h"
#include "derived.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/assign.h"
#include "flang/Runtime/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "type-info.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/assign.h"

using Fortran::common::TypeCategory;



namespace Fortran::runtime {
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/allocator-registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/allocator-registry.h"
#include "FortranRuntime/Runtime/allocator-registry.h"
#include "terminator.h"

namespace Fortran::runtime {
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/lib/Runtime/array-constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/array-constructor.h"
#include "FortranRuntime/Runtime/array-constructor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "derived.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/assign.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "type-info.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/assign.h"

namespace Fortran::runtime {

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/assign.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "assign-impl.h"
#include "derived.h"
#include "flang/Runtime/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#ifndef FORTRAN_RUNTIME_BUFFER_H_
#define FORTRAN_RUNTIME_BUFFER_H_

#include "flang/Runtime/freestanding-tools.h"
#include "flang/Runtime/memory.h"
#include "FortranRuntime/Runtime/memory.h"
#include "io-error.h"
#include "flang/Runtime/freestanding-tools.h"
#include <algorithm>
#include <cinttypes>
#include <cstring>
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/character.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/bit-population-count.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/character.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include <algorithm>
#include <cstring>

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/command.h"
#include "flang/Runtime//command.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "environment.h"
#include "flang/Runtime/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#ifndef FORTRAN_RUNTIME_CONNECTION_H_
#define FORTRAN_RUNTIME_CONNECTION_H_

#include "flang/Common/optional.h"
#include "format.h"
#include "flang/Common/optional.h"
#include <cinttypes>

namespace Fortran::runtime::io {
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//

#include "copy.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "stack.h"
#include "terminator.h"
#include "type-info.h"
#include "flang/Runtime/allocatable.h"
#include <cstring>

namespace Fortran::runtime {
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef FORTRAN_RUNTIME_COPY_H_
#define FORTRAN_RUNTIME_COPY_H_

#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"

namespace Fortran::runtime {

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/derived-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/derived-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "derived.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "type-info.h"
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include "derived.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/lib/Runtime/descriptor-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
// some scalar I/O data transfer APIs could be changed to bypass their use
// of descriptors in the future for better efficiency.)

#include "FortranRuntime/Runtime/descriptor.h"
#include "edit-input.h"
#include "edit-output.h"
#include "flang/Common/optional.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "io-stmt.h"
#include "namelist.h"
#include "terminator.h"
#include "type-info.h"
#include "unit.h"
#include "flang/Common/optional.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/cpp-type.h"

namespace Fortran::runtime::io::descr {
template <typename A>
Expand Down
10 changes: 6 additions & 4 deletions FortranRuntime/lib/Runtime/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/allocator-registry.h"
#include "ISO_Fortran_util.h"
#include "derived.h"
#include "flang/Runtime/allocator-registry.h"
#include "memory.h"
#include "stat.h"
#include "terminator.h"
Expand Down Expand Up @@ -141,8 +141,10 @@ RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(

RT_API_ATTRS std::size_t Descriptor::SizeInBytes() const {
const DescriptorAddendum *addendum{Addendum()};
return sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
(addendum ? addendum->SizeInBytes() : 0);
std::size_t bytes{ sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
(addendum ? addendum->SizeInBytes() : 0)};
assert (bytes <= MaxDescriptorSizeInBytes(raw_.rank,addendum) && "Descriptor must fit compiler-allocated space");
return bytes;
}

RT_API_ATTRS std::size_t Descriptor::Elements() const {
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/lib/Runtime/dot-product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Common/float128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/reduction.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "float.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/reduction.h"
#include <cfloat>
#include <cinttypes>

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/edit-input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
//===----------------------------------------------------------------------===//

#include "edit-input.h"
#include "namelist.h"
#include "utf.h"
#include "flang/Common/optional.h"
#include "flang/Common/real.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/freestanding-tools.h"
#include "namelist.h"
#include "utf.h"
#include <algorithm>
#include <cfenv>

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/edit-input.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#ifndef FORTRAN_RUNTIME_EDIT_INPUT_H_
#define FORTRAN_RUNTIME_EDIT_INPUT_H_

#include "flang/Common/decimal.h"
#include "format.h"
#include "io-stmt.h"
#include "flang/Common/decimal.h"

namespace Fortran::runtime::io {

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/edit-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include "edit-output.h"
#include "emit-encoded.h"
#include "utf.h"
#include "flang/Common/real.h"
#include "flang/Common/uint128.h"
#include "utf.h"
#include <algorithm>

namespace Fortran::runtime::io {
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/edit-output.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
// Drives the same fast binary-to-decimal formatting templates used
// in the f18 front-end.

#include "flang/Common/decimal.h"
#include "flang/Common/uint128.h"
#include "format.h"
#include "io-stmt.h"
#include "flang/Common/decimal.h"
#include "flang/Common/uint128.h"

namespace Fortran::runtime::io {

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/execute.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "environment.h"
#include "flang/Runtime/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/lib/Runtime/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
// extensions that will eventually be implemented in Fortran.

#include "flang/Runtime/extensions.h"
#include "flang/Runtime/command.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/entry-names.h"
#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Runtime/command.h"
#include "flang/Runtime/entry-names.h"
#include <chrono>
#include <cstring>
#include <ctime>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/extrema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
// and shapes and (for MAXLOC & MINLOC) result integer kinds. Also implements
// NORM2 using common infrastructure.

#include "reduction-templates.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/character.h"
#include "flang/Runtime/reduction.h"
#include "reduction-templates.h"
#include <algorithm>
#include <cfloat>
#include <cinttypes>
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "file.h"
#include "FortranRuntime/Runtime/memory.h"
#include "tools.h"
#include "flang/Common/magic-numbers.h"
#include "flang/Runtime/memory.h"
#include "flang/Runtime/magic-numbers.h"
#include <algorithm>
#include <cerrno>
#include <cstring>
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#ifndef FORTRAN_RUNTIME_FILE_H_
#define FORTRAN_RUNTIME_FILE_H_

#include "flang/Common/optional.h"
#include "flang/Runtime/memory.h"
#include "FortranRuntime/Runtime/memory.h"
#include "io-error.h"
#include "flang/Common/optional.h"
#include <cinttypes>

namespace Fortran::runtime::io {
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/findloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// Implements FINDLOC for all required operand types and shapes and result
// integer kinds.

#include "reduction-templates.h"
#include "flang/Runtime/character.h"
#include "flang/Runtime/reduction.h"
#include "reduction-templates.h"
#include <cinttypes>
#include <complex>

Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/format-implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#define FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_

#include "emit-encoded.h"
#include "flang/Common/decimal.h"
#include "flang/Common/format.h"
#include "flang/Runtime/main.h"
#include "format.h"
#include "io-stmt.h"
#include "memory.h"
#include "flang/Common/decimal.h"
#include "flang/Common/format.h"
#include "flang/Runtime/main.h"
#include <algorithm>
#include <cstring>
#include <limits>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#define FORTRAN_RUNTIME_FORMAT_H_

#include "environment.h"
#include "io-error.h"
#include "flang/Common/Fortran-consts.h"
#include "flang/Common/decimal.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/freestanding-tools.h"
#include "io-error.h"
#include <cinttypes>

namespace Fortran::runtime {
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/inquiry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// inquire about shape information of arrays -- LBOUND and SIZE.

#include "flang/Runtime/inquiry.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "copy.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include <algorithm>
Expand Down
6 changes: 4 additions & 2 deletions FortranRuntime/lib/Runtime/internal-unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "internal-unit.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/freestanding-tools.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "io-error.h"
#include "flang/Runtime/freestanding-tools.h"
#include <algorithm>
#include <type_traits>

Expand All @@ -36,6 +36,8 @@ RT_API_ATTRS InternalDescriptorUnit<DIR>::InternalDescriptorUnit(
Descriptor &d{descriptor()};
RUNTIME_CHECK(
terminator, that.SizeInBytes() <= d.SizeInBytes(maxRank, true, 0));
RUNTIME_CHECK(terminator,
that.SizeInBytes() <= MaxDescriptorSizeInBytes(maxRank, true, 0));
new (&d) Descriptor{that};
d.Check();
internalIoCharKind = thatType->second;
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/internal-unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#ifndef FORTRAN_RUNTIME_INTERNAL_UNIT_H_
#define FORTRAN_RUNTIME_INTERNAL_UNIT_H_

#include "FortranRuntime/Runtime/descriptor.h"
#include "connection.h"
#include "flang/Runtime/descriptor.h"
#include <cinttypes>
#include <type_traits>

Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/io-api-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#ifndef FORTRAN_RUNTIME_IO_API_COMMON_H_
#define FORTRAN_RUNTIME_IO_API_COMMON_H_

#include "flang/Common/api-attrs.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "io-stmt.h"
#include "terminator.h"
#include "unit.h"
#include "flang/Common/api-attrs.h"
#include "flang/Common/optional.h"

namespace Fortran::runtime::io {

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/io-api-minimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Implements the subset of the I/O statement API needed for basic
// list-directed output (PRINT *) of intrinsic types.

#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "edit-output.h"
#include "flang/Runtime/io-api.h"
#include "format.h"
#include "io-api-common.h"
#include "io-stmt.h"
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/lib/Runtime/io-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
// OutputReal{32,64}, OutputComplex{32,64}, OutputAscii, & EndIoStatement()
// are in runtime/io-api-minimal.cpp.

#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "FortranRuntime/Runtime/memory.h"
#include "descriptor-io.h"
#include "edit-input.h"
#include "edit-output.h"
#include "environment.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/memory.h"
#include "format.h"
#include "io-api-common.h"
#include "io-stmt.h"
#include "terminator.h"
#include "tools.h"
#include "unit.h"
#include "flang/Common/optional.h"
#include <cstdlib>
#include <memory>

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/io-error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "io-error.h"
#include "config.h"
#include "tools.h"
#include "flang/Common/magic-numbers.h"
#include "flang/Runtime/magic-numbers.h"
#include <cerrno>
#include <cstdarg>
#include <cstdio>
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/io-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#ifndef FORTRAN_RUNTIME_IO_ERROR_H_
#define FORTRAN_RUNTIME_IO_ERROR_H_

#include "flang/Runtime/iostat.h"
#include "flang/Runtime/memory.h"
#include "FortranRuntime/Runtime/iostat-funcs.h"
#include "FortranRuntime/Runtime/memory.h"
#include "terminator.h"
#include <cinttypes>

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/io-stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "io-stmt.h"
#include "FortranRuntime/Runtime/memory.h"
#include "connection.h"
#include "emit-encoded.h"
#include "flang/Runtime/memory.h"
#include "format.h"
#include "tools.h"
#include "unit.h"
Expand Down
10 changes: 5 additions & 5 deletions FortranRuntime/lib/Runtime/io-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
#ifndef FORTRAN_RUNTIME_IO_STMT_H_
#define FORTRAN_RUNTIME_IO_STMT_H_

#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "connection.h"
#include "file.h"
#include "flang/Common/optional.h"
#include "flang/Common/reference-wrapper.h"
#include "flang/Common/visit.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/io-api.h"
#include "format.h"
#include "internal-unit.h"
#include "io-error.h"
#include "flang/Common/optional.h"
#include "flang/Common/reference-wrapper.h"
#include "flang/Common/visit.h"
#include <flang/Common/variant.h>
#include <functional>
#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/iostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/iostat.h"
#include "FortranRuntime/Runtime/iostat-funcs.h"

namespace Fortran::runtime::io {
RT_OFFLOAD_API_GROUP_BEGIN
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/matmul-transpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
// to use the faster BLAS routines.

#include "flang/Runtime/matmul-transpose.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/c-or-cpp.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include <cstring>

namespace {
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
// Places where BLAS routines could be called are marked as TODO items.

#include "flang/Runtime/matmul.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/c-or-cpp.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include <cstring>

namespace {
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/memory.h"
#include "flang/Runtime/freestanding-tools.h"
#include "FortranRuntime/Runtime/memory.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Runtime/freestanding-tools.h"
#include <cstdlib>

namespace Fortran::runtime {
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/misc-intrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/misc-intrinsic.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/optional.h"
#include <algorithm>
#include <cstdio>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/namelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "namelist.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "descriptor-io.h"
#include "emit-encoded.h"
#include "flang/Runtime/io-api.h"
#include "io-stmt.h"
#include <algorithm>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/namelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#ifndef FORTRAN_RUNTIME_NAMELIST_H_
#define FORTRAN_RUNTIME_NAMELIST_H_

#include "flang/Common/api-attrs.h"
#include "non-tbp-dio.h"
#include "flang/Common/api-attrs.h"

#include <cstddef>

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/numeric-templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
#define FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_

#include "flang/Common/api-attrs.h"
#include "flang/Common/float128.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/api-attrs.h"
#include "flang/Common/float128.h"
#include <cstdint>
#include <limits>

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/numeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/numeric.h"
#include "flang/Common/float128.h"
#include "numeric-templates.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/float128.h"
#include <cfloat>
#include <climits>
#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

// Implements PRODUCT for all required operand types and shapes.

#include "reduction-templates.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/reduction.h"
#include "reduction-templates.h"
#include <cfloat>
#include <cinttypes>
#include <complex>
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/random-templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#ifndef FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
#define FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_

#include "flang/Common/optional.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "lock.h"
#include "numeric-templates.h"
#include "flang/Common/optional.h"
#include <algorithm>
#include <random>

Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/lib/Runtime/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
// RANDOM_SEED.

#include "flang/Runtime/random.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "lock.h"
#include "random-templates.h"
#include "terminator.h"
#include "flang/Common/float128.h"
#include "flang/Common/leading-zero-bit-count.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "lock.h"
#include "random-templates.h"
#include "terminator.h"
#include <cmath>
#include <cstdint>
#include <limits>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// REDUCE() implementation

#include "flang/Runtime/reduce.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "reduction-templates.h"
#include "terminator.h"
#include "tools.h"
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/reduction-templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#ifndef FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
#define FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_

#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "numeric-templates.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Runtime/cpp-type.h"
#include <algorithm>

namespace Fortran::runtime {
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp.

#include "flang/Runtime/reduction.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "reduction-templates.h"
#include <cinttypes>

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef FORTRAN_RUNTIME_STACK_H_
#define FORTRAN_RUNTIME_STACK_H_

#include "flang/Runtime/memory.h"
#include "FortranRuntime/Runtime/memory.h"
#include "terminator.h"

namespace Fortran::runtime {
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include "stat.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define FORTRAN_RUNTIME_STAT_H_
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Common/api-attrs.h"
#include "flang/Common/magic-numbers.h"
#include "flang/Runtime/magic-numbers.h"
namespace Fortran::runtime {

class Descriptor;
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// cancellation on intermediate results by using "Kahan summation"
// (basically the same as manual "double-double").

#include "reduction-templates.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/reduction.h"
#include "reduction-templates.h"
#include <cfloat>
#include <cinttypes>
#include <complex>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/support.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "ISO_Fortran_util.h"
#include "flang/Runtime/descriptor.h"
#include "type-info.h"

namespace Fortran::runtime {
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/temporary-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
// temporaries. For use in HLFIR lowering.

#include "flang/Runtime/temporary-stack.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/memory.h"
#include "terminator.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/assign.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/memory.h"
#include "terminator.h"

namespace {

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/time-intrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
// Implements time-related intrinsic subroutines.

#include "flang/Runtime/time-intrinsic.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Runtime/cpp-type.h"
#include <algorithm>
#include <cstdint>
#include <cstdio>
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/lib/Runtime/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#ifndef FORTRAN_RUNTIME_TOOLS_H_
#define FORTRAN_RUNTIME_TOOLS_H_

#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/memory.h"
#include "stat.h"
#include "terminator.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/freestanding-tools.h"
#include "flang/Runtime/memory.h"
#include "stat.h"
#include "terminator.h"
#include <cstring>
#include <functional>
#include <map>
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/transformational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// of the standard but it more likely to conform with its intent.

#include "flang/Runtime/transformational.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "copy.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/float128.h"

namespace Fortran::runtime {

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/lib/Runtime/type-code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/type-code.h"
#include "FortranRuntime/Runtime/type-code.h"
#include <cstdint>

namespace Fortran::runtime {
Expand Down
10 changes: 7 additions & 3 deletions FortranRuntime/lib/Runtime/type-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ RT_API_ATTRS std::size_t Component::SizeInBytes(
return GetElementByteSize(instance) * GetElements(instance);
} else if (category() == TypeCategory::Derived) {
const DerivedType *type{derivedType()};
return Descriptor::SizeInBytes(
rank_, true, type ? type->LenParameters() : 0);
auto bytes {Descriptor::SizeInBytes(
rank_, true, type ? type->LenParameters() : 0)};
assert(bytes <= MaxDescriptorSizeInBytes( rank_, true, type ? type->LenParameters() : 0));
return bytes;
} else {
return Descriptor::SizeInBytes(rank_);
auto bytes{ Descriptor::SizeInBytes(rank_)};
assert(bytes <= MaxDescriptorSizeInBytes( rank_));
return bytes;
}
}

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/type-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// A C++ perspective of the derived type description schemata in
// flang/module/__fortran_type_info.f90.

#include "FortranRuntime/Runtime/descriptor.h"
#include "terminator.h"
#include "flang/Common/Fortran-consts.h"
#include "flang/Common/bit-population-count.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/descriptor.h"
#include "terminator.h"
#include <cinttypes>
#include <memory>

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/lib/Runtime/unit-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#ifndef FORTRAN_RUNTIME_UNIT_MAP_H_
#define FORTRAN_RUNTIME_UNIT_MAP_H_

#include "flang/Common/fast-int-set.h"
#include "flang/Runtime/memory.h"
#include "FortranRuntime/Runtime/memory.h"
#include "lock.h"
#include "unit.h"
#include "flang/Common/fast-int-set.h"
#include <cstdint>
#include <cstdlib>

Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/lib/Runtime/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
#ifndef FORTRAN_RUNTIME_UNIT_H_
#define FORTRAN_RUNTIME_UNIT_H_

#include "FortranRuntime/Runtime/memory.h"
#include "buffer.h"
#include "connection.h"
#include "environment.h"
#include "file.h"
#include "flang/Common/constexpr-bitset.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/memory.h"
#include "format.h"
#include "io-error.h"
#include "io-stmt.h"
#include "lock.h"
#include "terminator.h"
#include "flang/Common/constexpr-bitset.h"
#include "flang/Common/optional.h"
#include <cstdlib>
#include <cstring>
#include <flang/Common/variant.h>
Expand Down
11 changes: 0 additions & 11 deletions FortranRuntime/unittests/Common/CMakeLists.txt

This file was deleted.

18 changes: 0 additions & 18 deletions FortranRuntime/unittests/Decimal/CMakeLists.txt

This file was deleted.

3 changes: 2 additions & 1 deletion FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include "FortranRuntime/Runtime/descriptor.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Testing/testing.h"
#include "llvm/Support/raw_ostream.h"
#include <type_traits>
Expand All @@ -28,6 +28,7 @@ template <int rank> class Test_CFI_CDESC_T {
MATCH(false, std::is_const<type>::value);
MATCH(false, std::is_volatile<type>::value);
// suitable in size
MATCH(true, Descriptor::SizeInBytes(rank_, false) <= Fortran::common::MaxDescriptorSizeInBytes( rank_, false));
if (rank > 0) {
MATCH(sizeof(dvStorage_), Descriptor::SizeInBytes(rank_, false));
} else { // C++ implementation over-allocates for rank=0 by 24bytes.
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/unittests/Evaluate/reshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "flang/Runtime/transformational.h"
#include "flang/Testing/testing.h"
#include <cinttypes>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/unittests/Runtime/AccessTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#ifndef _WIN32

#include "CrashHandlerFixture.h"
#include "gtest/gtest.h"
#include "flang/Runtime/extensions.h"
#include "llvm/ADT/Twine.h"
#include "gtest/gtest.h"

#include <fcntl.h>
#include <sys/stat.h>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/unittests/Runtime/Allocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/allocatable.h"
#include "tools.h"
#include "gtest/gtest.h"
#include "tools.h"

using namespace Fortran::runtime;

Expand Down
10 changes: 5 additions & 5 deletions FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//

#include "FortranRuntime/Runtime/array-constructor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/array-constructor.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/type-code.h"
#include "tools.h"
#include "gtest/gtest.h"

#include <memory>

Expand Down
10 changes: 5 additions & 5 deletions FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//

#include "FortranRuntime/Runtime/CUDA/allocator.h"
#include "FortranRuntime/Runtime/CUDA/descriptor.h"
#include "FortranRuntime/Runtime/allocatable.h"
#include "FortranRuntime/Runtime/allocator-registry.h"
#include "gtest/gtest.h"
#include "../../../runtime/terminator.h"
#include "flang/Runtime/CUDA/allocator.h"
#include "flang/Runtime/CUDA/descriptor.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/allocator-registry.h"
#include "flang/Support/Fortran.h"
#include "gtest/gtest.h"

#include "cuda_runtime.h"

Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/unittests/Runtime/CharacterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// in Fortran.

#include "flang/Runtime/character.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "gtest/gtest.h"
#include <cstring>
#include <functional>
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/unittests/Runtime/CommandTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/command.h"
#include "flang/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "flang/Runtime/execute.h"
#include "flang/Runtime/extensions.h"
#include "flang/Runtime/main.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstddef>
#include <cstdlib>

Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/unittests/Runtime/Derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/derived-api.h"
#include "flang/Runtime/descriptor.h"
#include "tools.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Runtime/derived-api.h"

using namespace Fortran::runtime;

Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
//===----------------------------------------------------------------------===//

#include "CrashHandlerFixture.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "gtest/gtest.h"
#include "flang/Runtime/main.h"
#include "flang/Runtime/stop.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
#include <cstring>
#include <string_view>

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/unittests/Runtime/Inquiry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/inquiry.h"
#include "flang/Runtime/type-code.h"
#include "tools.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "tools.h"

using namespace Fortran::runtime;
using Fortran::common::TypeCategory;
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/unittests/Runtime/ListInputTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include "../../lib/Runtime/io-error.h"
#include "CrashHandlerFixture.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "../../lib/Runtime/io-error.h"

using namespace Fortran::runtime;
using namespace Fortran::runtime::io;
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "CrashHandlerFixture.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include <algorithm>
#include <array>
#include <cstring>
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/unittests/Runtime/Matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/matmul.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/type-code.h"
#include "tools.h"
#include "gtest/gtest.h"

using namespace Fortran::runtime;
using Fortran::common::TypeCategory;
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//

#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/matmul-transpose.h"
#include "flang/Runtime/type-code.h"
#include "tools.h"
#include "gtest/gtest.h"

using namespace Fortran::runtime;
using Fortran::common::TypeCategory;
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime//misc-intrinsic.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "tools.h"
#include "gtest/gtest.h"
#include "flang/Runtime/misc-intrinsic.h"

using namespace Fortran::runtime;

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/unittests/Runtime/Namelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "../../lib/Runtime/namelist.h"
#include "CrashHandlerFixture.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include "tools.h"
#include <algorithm>
#include <cinttypes>
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/unittests/Runtime/Numeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/numeric.h"
#include "flang/Common/float128.h"
#include "gtest/gtest.h"
#include "flang/Common/float128.h"
#include <cmath>
#include <limits>

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "CrashHandlerFixture.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/io-api.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/io-api-funcs.h"
#include <algorithm>
#include <array>
#include <cstring>
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/unittests/Runtime/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/pointer.h"
#include "flang/Runtime/descriptor.h"
#include "tools.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "gtest/gtest.h"
#include "tools.h"

using namespace Fortran::runtime;

Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/unittests/Runtime/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime//random.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/type-code.h"
#include "flang/Runtime/random.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include <cmath>

Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/unittests/Runtime/Reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/reduction.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/reduce.h"
#include "flang/Runtime/type-code.h"
#include "tools.h"
#include "gtest/gtest.h"
#include <cstdint>
#include <cstring>
#include <string>
Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
/// runtime components and ensure the test fixture handles crashes as we expect.
//
//===----------------------------------------------------------------------===//
#include "../../lib/Runtime/terminator.h"
#include "CrashHandlerFixture.h"
#include "tools.h"
#include "../../lib/Runtime/terminator.h"
#include "flang/Runtime/io-api.h"
#include "flang/Runtime/transformational.h"
#include "tools.h"
#include <gtest/gtest.h>

using namespace Fortran::runtime;
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/unittests/Runtime/Stop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
#include "flang/Runtime/stop.h"
#include "../../lib/Runtime/environment.h"
#include "CrashHandlerFixture.h"
#include "../../lib/Runtime/environment.h"
#include <cstdlib>
#include <gtest/gtest.h>

Expand Down
4 changes: 2 additions & 2 deletions FortranRuntime/unittests/Runtime/Support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/support.h"
#include "flang/Runtime/descriptor.h"
#include "tools.h"
#include "FortranRuntime/Runtime/descriptor.h"
#include "gtest/gtest.h"
#include "tools.h"

using namespace Fortran::runtime;
using Fortran::common::TypeCategory;
Expand Down
8 changes: 4 additions & 4 deletions FortranRuntime/unittests/Runtime/TemporaryStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/temporary-stack.h"
#include "flang/Runtime/type-code.h"
#include "tools.h"
#include "gtest/gtest.h"
#include <vector>

using namespace Fortran::runtime;
Expand Down
2 changes: 1 addition & 1 deletion FortranRuntime/unittests/Runtime/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/time-intrinsic.h"
#include "gtest/gtest.h"
#include "flang/Runtime/time-intrinsic.h"
#include <algorithm>
#include <cctype>
#include <cerrno>
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/unittests/Runtime/Transformational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/transformational.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/type-code.h"
#include "tools.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "tools.h"
#include "flang/Common/float128.h"
#include <vector>

using namespace Fortran::runtime;
Expand Down
6 changes: 3 additions & 3 deletions FortranRuntime/unittests/Runtime/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#ifndef FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
#define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_

#include "FortranRuntime/Runtime/descriptor.h"
#include "FortranRuntime/Runtime/type-code.h"
#include "gtest/gtest.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/type-code.h"
#include "gtest/gtest.h"
#include <cstdint>
#include <cstring>
#include <vector>
Expand Down
3 changes: 1 addition & 2 deletions flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ set(LLVM_BUILD_TOOLS ON)

include_directories(BEFORE
${FLANG_BINARY_DIR}/include
${FLANG_SOURCE_DIR}/include
${FLANG_SOURCE_DIR}/../FortranRuntime/include)
${FLANG_SOURCE_DIR}/include)

# Add Flang-centric modules to cmake path.
list(INSERT CMAKE_MODULE_PATH 0
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/* clang-format off */
#include <stddef.h>
#include "flang/Common/api-attrs.h"
#include "flang/Common/api-attrs.h"
#ifdef __cplusplus
namespace Fortran {
namespace ISO {
Expand Down
25 changes: 25 additions & 0 deletions flang/include/flang/Common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Files in this directory are used by Flang (the compiler) and FortranRuntime
(the runtime library for Flang-compiled programs). They must be compatible by
both. For definitions used only by Flang, consider
`flang/{lib,include/flang}/Support` instead. For definitions used only by
FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.

The requirements for common code include:

* No dependence to LLVM, including LLVMSupport.

* No link-dependence to the C++ runtime. This means that e.g. `std::string`
cannot be used.

* No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
instead.

* Preprocessor macros from `config.h` and CMake
`(target/add)_compile_definitions` must be defined by both build scripts.
See `flang/cmake/modules/FlangCommon.cmake`.

* Some header files are included from `.c` files.
`#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.

* Global declarations may need to be annotated using definitions from
`api-attrs.h`.
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/*===-- include/flang/Common/api-attrs.h ----------------------------*- C -*-===
/*===-- include/flang/Common/api-attrs.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
*
*===----------------------------------------------------------------------===*/
*===------------------------------------------------------------------------===
*/

/*
* The file defines a set macros that can be used to apply
* different attributes/pragmas to functions/variables
* declared/defined/used in Flang runtime library.
*/

#ifndef FORTRAN_COMMON_API_ATTRS_H_
#define FORTRAN_COMMON_API_ATTRS_H_
#ifndef FORTRAN_RUNTIME_API_ATTRS_H_
#define FORTRAN_RUNTIME_API_ATTRS_H_

/*
* RT_EXT_API_GROUP_BEGIN/END pair is placed around definitions
Expand Down Expand Up @@ -177,4 +178,4 @@
#define RT_DEVICE_NOINLINE_HOST_INLINE inline
#endif

#endif /* FORTRAN_COMMON_API_ATTRS_H_ */
#endif /* !FORTRAN_RUNTIME_API_ATTRS_H_ */
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ template <typename INT> inline constexpr int TrailingZeroBitCount(INT x) {
}
}
} // namespace Fortran::common
#endif /* FORTRAN_COMMON_BIT_POPULATION_COUNT_H_ */
#endif // FORTRAN_COMMON_BIT_POPULATION_COUNT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ template <int BITS> class BitSet {
Word bits_{0};
};
} // namespace Fortran::common
#endif /* FORTRAN_COMMON_CONSTEXPR_BITSET_H_ */
#endif // FORTRAN_COMMON_CONSTEXPR_BITSET_H_
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ constexpr std::array<std::string_view, ITEMS> EnumNames(const char *p) {
}

} // namespace Fortran::common
#endif /* FORTRAN_COMMON_ENUM_CLASS_H_ */
#endif // FORTRAN_COMMON_ENUM_CLASS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ struct std::hash<Fortran::common::EnumSet<ENUM, values>> {
return std::hash(x.bitset());
}
};
#endif /* FORTRAN_COMMON_ENUM_SET_H_ */
#endif // FORTRAN_COMMON_ENUM_SET_H_
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- include/flang/Common/fast-int-set.h ---------------------*- C++ -*-===//
//===-- include/flang/Common/fast-int-set.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.
Expand Down Expand Up @@ -103,4 +103,4 @@ template <int N> class FastIntSet {
bool isFullyInitialized_{false}; // memory was cleared
};
} // namespace Fortran::common
#endif /* FORTRAN_COMMON_FAST_INT_SET_H_ */
#endif // FORTRAN_COMMON_FAST_INT_SET_H_
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===-- include/flang/Common/float128.h -----------------------------*- C -*-===
/*===-- flang/Common/float128.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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,4 +901,4 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
}

} // namespace Fortran::common
#endif /* FORTRAN_COMMON_FORMAT_H_ */
#endif // FORTRAN_COMMON_FORMAT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ template <typename A, typename... B>
using IfNoLvalue = std::enable_if_t<(... && !std::is_lvalue_reference_v<B>), A>;
template <typename... RVREF> using NoLvalue = IfNoLvalue<void, RVREF...>;
} // namespace Fortran::common
#endif /* FORTRAN_COMMON_IDIOMS_H_ */
#endif // FORTRAN_COMMON_IDIOMS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ template <typename A> inline constexpr int BitsNeededFor(A x) {
return 8 * sizeof x - LeadingZeroBitCount(x);
}
} // namespace Fortran::common
#endif /* FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_ */
#endif // FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// * cuda:: namespace need to be forced for all std:: references.
//
//===----------------------------------------------------------------------===//
#ifndef FORTRAN_COMMON_OPTIONAL_H_
#define FORTRAN_COMMON_OPTIONAL_H_
#ifndef FORTRAN_COMMON_OPTIONAL_H
#define FORTRAN_COMMON_OPTIONAL_H

#include "flang/Common/api-attrs.h"
#include <optional>
Expand Down Expand Up @@ -240,4 +240,4 @@ using std::optional;

} // namespace Fortran::common

#endif /* FORTRAN_COMMON_OPTIONAL_H_ */
#endif // FORTRAN_COMMON_OPTIONAL_H
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ class RealCharacteristics {
};

} // namespace Fortran::common
#endif /* FORTRAN_COMMON_REAL_H_ */
#endif // FORTRAN_COMMON_REAL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
//
// clang-format on

#ifndef FORTRAN_COMMON_REFERENCE_WRAPPER_H_
#define FORTRAN_COMMON_REFERENCE_WRAPPER_H_
#ifndef FORTRAN_COMMON_REFERENCE_WRAPPER_H
#define FORTRAN_COMMON_REFERENCE_WRAPPER_H

#include "flang/Common/api-attrs.h"
#include <functional>
Expand Down Expand Up @@ -111,4 +111,4 @@ using std::reference_wrapper;

} // namespace Fortran::common

#endif /* FORTRAN_COMMON_REFERENCE_WRAPPER_H_ */
#endif // FORTRAN_COMMON_REFERENCE_WRAPPER_H
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#ifndef FORTRAN_COMMON_RESTORER_H_
#define FORTRAN_COMMON_RESTORER_H_
#include "flang/Common/api-attrs.h"
#include "idioms.h"
#include "flang/Common/api-attrs.h"
namespace Fortran::common {
template <typename A> class Restorer {
public:
Expand Down Expand Up @@ -53,4 +53,4 @@ RT_API_ATTRS common::IfNoLvalue<Restorer<A>, B> ScopedSet(
return Restorer<A>{to, std::move(original)};
}
} // namespace Fortran::common
#endif /* FORTRAN_COMMON_RESTORER_H_ */
#endif // FORTRAN_COMMON_RESTORER_H_
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#define AVOID_NATIVE_UINT128_T 0
#endif

#include "flang/Common/api-attrs.h"
#include "leading-zero-bit-count.h"
#include "flang/Common/api-attrs.h"
#include <cstdint>
#include <type_traits>

Expand Down Expand Up @@ -303,4 +303,4 @@ template <int BITS>
using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;

} // namespace Fortran::common
#endif /* FORTRAN_COMMON_UINT128_H_ */
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// and the related names become available, though, they may correspond
// to alternative definitions (e.g. from cuda::std namespace).

#ifndef FORTRAN_COMMON_VARIANT_H_
#define FORTRAN_COMMON_VARIANT_H_
#ifndef FORTRAN_COMMON_VARIANT_H
#define FORTRAN_COMMON_VARIANT_H

#if RT_USE_LIBCUDACXX
#include <cuda/std/variant>
Expand All @@ -27,4 +27,4 @@ using cuda::std::visit;
#include <variant>
#endif // !RT_USE_LIBCUDACXX

#endif /* FORTRAN_COMMON_VARIANT_H_ */
#endif // FORTRAN_COMMON_VARIANT_H
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#ifndef FORTRAN_COMMON_VISIT_H_
#define FORTRAN_COMMON_VISIT_H_

#include "flang/Common/api-attrs.h"
#include "variant.h"
#include "flang/Common/api-attrs.h"
#include <type_traits>

namespace Fortran::common {
Expand Down Expand Up @@ -100,4 +100,4 @@ using Fortran::common::log2visit::visit;
#endif

} // namespace Fortran::common
#endif /* FORTRAN_COMMON_VISIT_H_ */
#endif // FORTRAN_COMMON_VISIT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

#endif // _WIN32

#endif /* FORTRAN_COMMON_WINDOWS_INCLUDE_H_ */
#endif // FORTRAN_COMMON_WINDOWS_INCLUDE_H_
13 changes: 7 additions & 6 deletions flang/include/flang/ISO_Fortran_binding.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/*===-- include/flang/Common/ISO_Fortran_binding.h ------------------*- C -*-===
/*===-- include/flang/ISO_Fortran_binding.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_COMMON_ISO_FORTRAN_BINDING_H_
#define FORTRAN_COMMON_ISO_FORTRAN_BINDING_H_
#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_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
#include <stddef.h>
#define FORTRAN_ISO_NAMESPACE_
#endif
Expand Down Expand Up @@ -206,4 +207,4 @@ RT_API_ATTRS int CFI_setpointer(
} // extern "C"
#endif

#endif /* FORTRAN_COMMON_ISO_FORTRAN_BINDING_H_ */
#endif /* CFI_ISO_FORTRAN_BINDING_H_ */
2 changes: 1 addition & 1 deletion flang/include/flang/Lower/Allocatable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "flang/Lower/AbstractConverter.h"
#include "flang/Optimizer/Builder/MutableBox.h"
#include "flang/Runtime/allocator-registry.h"
#include "flang/Runtime/allocator-registry-consts.h"
#include "llvm/ADT/StringRef.h"

namespace mlir {
Expand Down
1 change: 0 additions & 1 deletion flang/include/flang/Optimizer/Builder/IntrinsicCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ struct IntrinsicLibrary {
fir::ExtendedValue genUbound(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
fir::ExtendedValue genUnpack(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
fir::ExtendedValue genVerify(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
fir::ExtendedValue genNumericStorageSize(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);

/// Implement all conversion functions like DBLE, the first argument is
/// the value to convert. There may be an additional KIND arguments that
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Builder/MutableBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H

#include "flang/Optimizer/Builder/BoxValue.h"
#include "flang/Runtime/allocator-registry.h"
#include "flang/Runtime/allocator-registry-consts.h"
#include "llvm/ADT/StringRef.h"

namespace mlir {
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define OPTIMIZER_DESCRIPTOR_MODEL_H

#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/descriptor-consts.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/IR/BuiltinTypes.h"
#include "llvm/Support/ErrorHandling.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_

#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/entry-names.h"

#define CUDA_REPORT_IF_ERROR(expr) \
Expand Down Expand Up @@ -43,4 +43,4 @@ void *CUFAllocUnified(std::size_t);
void CUFFreeUnified(void *);

} // namespace Fortran::runtime::cuda
#endif /* FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_ */
#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
#define FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_

#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/entry-names.h"
#include <cstddef>

Expand All @@ -27,4 +27,4 @@ void RTDECL(CUFFreeDesciptor)(

} // extern "C"
} // namespace Fortran::runtime::cuda
#endif /* FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_ */
#endif // FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
25 changes: 25 additions & 0 deletions flang/include/flang/Runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Files in this directory are used by Flang (the compiler) and FortranRuntime
(the runtime library for Flang-compiled programs). They must be compatible by
both. For definitions used only by Flang, consider
`flang/{lib,include/flang}/Support` instead. For definitions used only by
FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.

The requirements for common code include:

* No dependence to LLVM, including LLVMSupport.

* No link-dependence to the C++ runtime. This means that e.g. `std::string`
cannot be used.

* No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
instead.

* Preprocessor macros from `config.h` and CMake
`(target/add)_compile_definitions` must be defined by both build scripts.
See `flang/cmake/modules/FlangCommon.cmake`.

* Some header files are included from `.c` files.
`#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.

* Global declarations may need to be annotated using definitions from
`api-attrs.h`.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
#ifndef FORTRAN_RUNTIME_ALLOCATABLE_H_
#define FORTRAN_RUNTIME_ALLOCATABLE_H_

#include "flang/Runtime/descriptor.h"
#include "flang/Common/Fortran-consts.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/entry-names.h"

namespace Fortran::runtime {
using SubscriptValue = ISO::CFI_index_t;
using common::TypeCategory;

extern "C" {

Expand Down Expand Up @@ -129,4 +132,4 @@ void RTDECL(AllocatableDeallocateNoFinal)(
Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_ALLOCATABLE_H_ */
#endif // FORTRAN_RUNTIME_ALLOCATABLE_H_
20 changes: 20 additions & 0 deletions flang/include/flang/Runtime/allocator-registry-consts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- include/flang/Runtime/allocator-registry-consts.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_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_
#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_

static constexpr unsigned kDefaultAllocator = 0;

// Allocator used for CUF
static constexpr unsigned kPinnedAllocatorPos = 1;
static constexpr unsigned kDeviceAllocatorPos = 2;
static constexpr unsigned kManagedAllocatorPos = 3;
static constexpr unsigned kUnifiedAllocatorPos = 4;

#endif /* FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_ */
54 changes: 54 additions & 0 deletions flang/include/flang/Runtime/array-constructor-consts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//===-- include/flang/Runtime/array-constructor-consts.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
//
//===----------------------------------------------------------------------===//

// External APIs to create temporary storage for array constructors when their
// final extents or length parameters cannot be pre-computed.

#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_
#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_

#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/entry-names.h"
#include <cstdint>

namespace Fortran::runtime {
struct ArrayConstructorVector;

// Max sizeof(ArrayConstructorVector) and sizeof(ArrayConstructorVector) for any
// target.
// TODO: Use target-specific size/alignment instead of overapproximation.
constexpr std::size_t MaxArrayConstructorVectorSizeInBytes = 2 * 40;
constexpr std::size_t MaxArrayConstructorVectorAlignInBytes = 8;

extern "C" {
// API to initialize an ArrayConstructorVector before any values are pushed to
// it. Inlined code is only expected to allocate the "ArrayConstructorVector"
// class instance storage with sufficient size (using
// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of
// the target the runtime is compiled for). This avoids the need for the runtime
// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
// is used to validate that lowering allocated enough space for it.
void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
const char *sourceFile = nullptr, int sourceLine = 0);

// Generic API to push any kind of entity into the array constructor (any
// Fortran type and any rank).
void RTDECL(PushArrayConstructorValue)(
ArrayConstructorVector &vector, const Descriptor &from);

// API to push scalar array constructor value of:
// - a numerical or logical type,
// - or a derived type that has no length parameters, and no allocatable
// component (that would require deep copies).
// It requires no descriptor for the value that is passed via its base address.
void RTDECL(PushArrayConstructorSimpleScalar)(
ArrayConstructorVector &vector, void *from);
} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ void RTDECL(AssignPolymorphic)(Descriptor &to, const Descriptor &from,
const char *sourceFile = nullptr, int sourceLine = 0);
} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_ASSIGN_H_ */
#endif // FORTRAN_RUNTIME_ASSIGN_H_
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
#define NORETURN IF_CPLUSPLUS([[noreturn]])
#define NO_ARGUMENTS IF_NOT_CPLUSPLUS(void)

#endif /* FORTRAN_RUNTIME_C_OR_CPP_H_ */
#endif // FORTRAN_RUNTIME_C_OR_CPP_H_
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ void RTDECL(Verify)(Descriptor &result, const Descriptor &string,
const char *sourceFile = nullptr, int sourceLine = 0);
}
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_CHARACTER_H_ */
#endif // FORTRAN_RUNTIME_CHARACTER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ std::int32_t RTNAME(GetCwd)(
}
} // namespace Fortran::runtime

#endif /* FORTRAN_RUNTIME_COMMAND_H_ */
#endif // FORTRAN_RUNTIME_COMMAND_H_
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ template <> struct CppTypeForHelper<TypeCategory::Logical, 1> {
};

} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_CPP_TYPE_H_ */
#endif // FORTRAN_RUNTIME_CPP_TYPE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ bool RTDECL(ExtendsTypeOf)(const Descriptor &, const Descriptor &);

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_DERIVED_API_H_ */
#endif // FORTRAN_RUNTIME_DERIVED_API_H_
73 changes: 73 additions & 0 deletions flang/include/flang/Runtime/descriptor-consts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//===-- include/flang/Runtime/descriptor-consts.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_RUNTIME_DESCRIPTOR_CONSTS_H_
#define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_

#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Common/api-attrs.h"
#include <cstddef>
#include <cstdint>

// Value of the addendum presence flag.
#define _CFI_ADDENDUM_FLAG 1
// Number of bits needed to be shifted when manipulating the allocator index.
#define _CFI_ALLOCATOR_IDX_SHIFT 1
// Allocator index mask.
#define _CFI_ALLOCATOR_IDX_MASK 0b00001110

namespace Fortran::runtime::typeInfo {
using TypeParameterValue = std::int64_t;
class DerivedType;
} // namespace Fortran::runtime::typeInfo

namespace Fortran::runtime {
class Descriptor;
using SubscriptValue = ISO::CFI_index_t;

/// Returns size in bytes of the descriptor (not the data)
/// This must be at least as large as the largest descriptor of any target
/// triple.
static constexpr RT_API_ATTRS std::size_t MaxDescriptorSizeInBytes(
int rank, bool addendum = false, int lengthTypeParameters = 0) {
// Layout:
//
// fortran::runtime::Descriptor {
// ISO::CFI_cdesc_t {
// void *base_addr; (pointer -> up to 8 bytes)
// size_t elem_len; (up to 8 bytes)
// int version; (up to 4 bytes)
// CFI_rank_t rank; (unsigned char -> 1 byte)
// CFI_type_t type; (signed char -> 1 byte)
// CFI_attribute_t attribute; (unsigned char -> 1 byte)
// unsigned char extra; (1 byte)
// }
// }
// fortran::runtime::Dimension[rank] {
// ISO::CFI_dim_t {
// CFI_index_t lower_bound; (ptrdiff_t -> up to 8 bytes)
// CFI_index_t extent; (ptrdiff_t -> up to 8 bytes)
// CFI_index_t sm; (ptrdiff_t -> up to 8 bytes)
// }
// }
// fortran::runtime::DescriptorAddendum {
// const typeInfo::DerivedType *derivedType_; (pointer -> up to 8
// bytes) typeInfo::TypeParameterValue len_[lenParameters]; (int64_t -> 8
// bytes)
// }
std::size_t bytes{24u + rank * 24u};
if (addendum || lengthTypeParameters > 0) {
if (lengthTypeParameters < 1)
lengthTypeParameters = 1;
bytes += 8u + static_cast<std::size_t>(lengthTypeParameters) * 8u;
}
return bytes;
}

} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ */
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*===-- include/flang/Runtime/entry-names.h -------------------------*- C -*-===
/*===-- include/flang/Runtime/entry-names.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
*
*===----------------------------------------------------------------------===*/
*===------------------------------------------------------------------------===
*/

/* Defines the macro RTNAME(n) which decorates the external name of a runtime
* library function or object with extra characters so that it
Expand All @@ -15,8 +16,8 @@
* The value of REVISION should not be changed until/unless the API to the
* runtime library must change in some way that breaks backward compatibility.
*/
#ifndef FORTRAN_RUNTIME_ENTRY_NAMES_H_
#define FORTRAN_RUNTIME_ENTRY_NAMES_H_
#ifndef FORTRAN_RUNTIME_ENTRY_NAMES_H
#define FORTRAN_RUNTIME_ENTRY_NAMES_H

#include "flang/Common/api-attrs.h"

Expand All @@ -40,4 +41,4 @@
#define RTNAME_STRING(name) RTNAME_STRINGIFY(RTNAME(name))
#endif

#endif /* FORTRAN_RUNTIME_ENTRY_NAMES_H_ */
#endif /* !FORTRAN_RUNTIME_ENTRY_NAMES_H */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- include/flang/Runtime/exceptions.h ----------------------*- C++ -*-===//
//===-- include/flang/Runtime/exceptions.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.
Expand Down Expand Up @@ -26,4 +26,4 @@ std::uint32_t RTNAME(MapException)(std::uint32_t excepts);

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_EXCEPTIONS_H_ */
#endif // FORTRAN_RUNTIME_EXCEPTIONS_H_
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- include/flang/Runtime/execute.h -------------------------*- C++ -*-===//
//===-- include/flang/Runtime/command.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.
Expand Down Expand Up @@ -26,4 +26,4 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait = true,
}
} // namespace Fortran::runtime

#endif /* FORTRAN_RUNTIME_EXECUTE_H_ */
#endif // FORTRAN_RUNTIME_EXECUTE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ std::int64_t FORTRAN_PROCEDURE_NAME(access)(const char *name,
#endif

} // extern "C"
#endif /* FORTRAN_RUNTIME_EXTENSIONS_H_ */
#endif // FORTRAN_RUNTIME_EXTENSIONS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ using std::toupper;
#endif // !STD_TOUPPER_UNSUPPORTED

} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_ */
#endif // FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- include/flang/Runtime/inquiry.h -------------------------*- C++ -*-===//
//===-- include/flang/Runtime/inquiry.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.
Expand Down Expand Up @@ -40,4 +40,4 @@ void RTDECL(Ubound)(void *result, const Descriptor &array, int kind,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_INQUIRY_H_ */
#endif // FORTRAN_RUNTIME_INQUIRY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#ifndef FORTRAN_RUNTIME_IO_API_H_
#define FORTRAN_RUNTIME_IO_API_H_

#include "flang/Common/magic-numbers.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/entry-names.h"
#include "flang/Runtime/iostat.h"
#include "flang/Runtime/magic-numbers.h"
#include <cinttypes>
#include <cstddef>

Expand Down Expand Up @@ -51,9 +51,6 @@ constexpr InquiryKeywordHash HashInquiryKeyword(const char *p) {
return hash;
}

RT_API_ATTRS const char *InquiryKeywordHashDecode(
char *buffer, std::size_t, InquiryKeywordHash);

extern "C" {

#define IONAME(name) RTNAME(io##name)
Expand Down Expand Up @@ -369,4 +366,4 @@ enum Iostat IODECL(EndIoStatement)(Cookie);

} // extern "C"
} // namespace Fortran::runtime::io
#endif /* FORTRAN_RUNTIME_IO_API_H_ */
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef FORTRAN_RUNTIME_IOSTAT_H_
#define FORTRAN_RUNTIME_IOSTAT_H_
#include "flang/Common/api-attrs.h"
#include "flang/Common/magic-numbers.h"
#include "flang/Runtime/magic-numbers.h"
namespace Fortran::runtime::io {

// The value of IOSTAT= is zero when no error, end-of-record,
Expand Down Expand Up @@ -89,7 +89,5 @@ enum Iostat {
IostatNonExternalDefinedUnformattedIo,
};

RT_API_ATTRS const char *IostatErrorString(int);

} // namespace Fortran::runtime::io
#endif /* FORTRAN_RUNTIME_IOSTAT_H_ */
#endif // FORTRAN_RUNTIME_IOSTAT_H_
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#if 0 /*===-- include/flang/Runtime/magic-numbers.h ---------------*- C -*-===*/
*
#if 0 /*===-- include/flang/Runtime/magic-numbers.h -----------------------===*/
/*
* 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
*
/*===----------------------------------------------------------------------===*/
*===----------------------------------------------------------------------===*/
#endif
#if 0
This header can be included into both Fortran and C.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ void RTNAME(ProgramStart)(
void RTNAME(ByteswapOption)(void); // -byteswapio
FORTRAN_EXTERN_C_END

#endif /* FORTRAN_RUNTIME_MAIN_H_ */
#endif // FORTRAN_RUNTIME_MAIN_H_
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ void RTDECL(MatmulTransposeDirect)(const Descriptor &, const Descriptor &,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_MATMUL_TRANSPOSE_H_ */
#endif // FORTRAN_RUNTIME_MATMUL_TRANSPOSE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ void RTDECL(MatmulDirect)(const Descriptor &, const Descriptor &,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_MATMUL_H_ */
#endif // FORTRAN_RUNTIME_MATMUL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ void RTDECL(TransferSize)(Descriptor &result, const Descriptor &source,
std::int64_t size);
} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_MISC_INTRINSIC_H_ */
#endif // FORTRAN_RUNTIME_MISC_INTRINSIC_H_
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,4 @@ CppTypeFor<TypeCategory::Real, 16> RTDECL(FPow16k)(

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_NUMERIC_H_ */
#endif // FORTRAN_RUNTIME_NUMERIC_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
#ifndef FORTRAN_RUNTIME_POINTER_H_
#define FORTRAN_RUNTIME_POINTER_H_

#include "flang/Runtime/descriptor.h"
#include "flang/Common/Fortran-consts.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/entry-names.h"

namespace Fortran::runtime {
using SubscriptValue = ISO::CFI_index_t;
using common::TypeCategory;

extern "C" {

// Data pointer initialization for NULLIFY(), "p=>NULL()`, & for ALLOCATE().
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- include/flang/Runtime/ragged.h --------------------------*- C++ -*-===//
//===-- Runtime/ragged.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.
Expand Down Expand Up @@ -57,4 +57,4 @@ void RTDECL(RaggedArrayDeallocate)(void *raggedArrayHeader);

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_RAGGED_H_ */
#endif // FORTRAN_RUNTIME_RAGGED_H_
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,4 @@ void RTDECL(ReduceDerivedTypeDim)(Descriptor &result, const Descriptor &array,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_REDUCE_H_ */
#endif // FORTRAN_RUNTIME_REDUCE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,4 @@ bool RTDECL(DotProductLogical)(const Descriptor &, const Descriptor &,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_REDUCTION_H_ */
#endif // FORTRAN_RUNTIME_REDUCTION_H_
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ NORETURN void RTNAME(ReportFatalUserError)(

FORTRAN_EXTERN_C_END

#endif /* FORTRAN_RUNTIME_STOP_H_ */
#endif // FORTRAN_RUNTIME_STOP_H_
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ void RTDECL(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_SUPPORT_H_ */
#endif // FORTRAN_RUNTIME_SUPPORT_H_
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ void RTNAME(DestroyDescriptorStack)(void *opaquePtr);
} // extern "C"
} // namespace Fortran::runtime

#endif /* FORTRAN_RUNTIME_TEMPORARY_STACK_H_ */
#endif // FORTRAN_RUNTIME_TEMPORARY_STACK_H_
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ void RTNAME(Etime)(const Descriptor *values, const Descriptor *time,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_TIME_INTRINSIC_H_ */
#endif // FORTRAN_RUNTIME_TIME_INTRINSIC_H_
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ void RTDECL(Unpack)(Descriptor &result, const Descriptor &vector,

} // extern "C"
} // namespace Fortran::runtime
#endif /* FORTRAN_RUNTIME_TRANSFORMATIONAL_H_ */
#endif // FORTRAN_RUNTIME_TRANSFORMATIONAL_H_
6 changes: 3 additions & 3 deletions flang/include/flang/Support/Fortran-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_FORTRAN_FEATURES_H_
#define FORTRAN_COMMON_FORTRAN_FEATURES_H_
#ifndef FORTRAN_SUPPORT_FORTRAN_FEATURES_H_
#define FORTRAN_SUPPORT_FORTRAN_FEATURES_H_

#include "flang/Common/enum-set.h"
#include "flang/Common/idioms.h"
Expand Down Expand Up @@ -191,4 +191,4 @@ class LanguageFeatureControl {
bool warnAllUsage_{false};
};
} // namespace Fortran::common
#endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_
#endif /* FORTRAN_SUPPORT_FORTRAN_FEATURES_H_ */
8 changes: 4 additions & 4 deletions flang/include/flang/Support/Fortran.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- include/flang/Common/Fortran.h --------------------------*- C++ -*-===//
//===-- include/flang/Support/Fortran.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_COMMON_FORTRAN_H_
#define FORTRAN_COMMON_FORTRAN_H_
#ifndef FORTRAN_SUPPORT_FORTRAN_H_
#define FORTRAN_SUPPORT_FORTRAN_H_

// Fortran language concepts that are used in many phases are defined
// once here to avoid redundancy and needless translation.
Expand Down Expand Up @@ -107,4 +107,4 @@ inline std::string GetExternalAssemblyName(
}

} // namespace Fortran::common
#endif // FORTRAN_COMMON_FORTRAN_H_
#endif /* FORTRAN_SUPPORT_FORTRAN_H_ */
6 changes: 3 additions & 3 deletions flang/include/flang/Support/MathOptionsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
///
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_MATHOPTIONSBASE_H
#define FORTRAN_COMMON_MATHOPTIONSBASE_H
#ifndef FORTRAN_SUPPORT_MATHOPTIONSBASE_H_
#define FORTRAN_SUPPORT_MATHOPTIONSBASE_H_

namespace Fortran::common {

Expand All @@ -41,4 +41,4 @@ class MathOptionsBase {

} // namespace Fortran::common

#endif // FORTRAN_COMMON_MATHOPTIONSBASE_H
#endif /* FORTRAN_SUPPORT_MATHOPTIONSBASE_H_ */
6 changes: 3 additions & 3 deletions flang/include/flang/Support/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_VERSION_H
#define FORTRAN_COMMON_VERSION_H
#ifndef FORTRAN_SUPPORT_VERSION_H_
#define FORTRAN_SUPPORT_VERSION_H_

#include "flang/Version.inc"
#include "llvm/ADT/StringRef.h"
Expand Down Expand Up @@ -53,4 +53,4 @@ std::string getFlangFullVersion();
std::string getFlangToolFullVersion(llvm::StringRef ToolName);
} // namespace Fortran::common

#endif // FORTRAN_COMMON_VERSION_H
#endif /* FORTRAN_SUPPORT_VERSION_H_ */
6 changes: 3 additions & 3 deletions flang/include/flang/Support/default-kinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_DEFAULT_KINDS_H_
#define FORTRAN_COMMON_DEFAULT_KINDS_H_
#ifndef FORTRAN_SUPPORT_DEFAULT_KINDS_H_
#define FORTRAN_SUPPORT_DEFAULT_KINDS_H_

#include "flang/Support/Fortran.h"
#include <cstdint>
Expand Down Expand Up @@ -58,4 +58,4 @@ class IntrinsicTypeDefaultKinds {
int defaultLogicalKind_{defaultIntegerKind_};
};
} // namespace Fortran::common
#endif // FORTRAN_COMMON_DEFAULT_KINDS_H_
#endif /* FORTRAN_SUPPORT_DEFAULT_KINDS_H_ */
6 changes: 3 additions & 3 deletions flang/include/flang/Support/indirection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_INDIRECTION_H_
#define FORTRAN_COMMON_INDIRECTION_H_
#ifndef FORTRAN_SUPPORT_INDIRECTION_H_
#define FORTRAN_SUPPORT_INDIRECTION_H_

// Define a smart pointer class template that is rather like
// non-nullable std::unique_ptr<>. Indirection<> is, like a C++ reference
Expand Down Expand Up @@ -171,4 +171,4 @@ template <typename A> class ForwardOwningPointer {
void (*deleter_)(A *){nullptr};
};
} // namespace Fortran::common
#endif // FORTRAN_COMMON_INDIRECTION_H_
#endif /* FORTRAN_SUPPORT_INDIRECTION_H_ */
6 changes: 3 additions & 3 deletions flang/include/flang/Support/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_INTERVAL_H_
#define FORTRAN_COMMON_INTERVAL_H_
#ifndef FORTRAN_SUPPORT_INTERVAL_H_
#define FORTRAN_SUPPORT_INTERVAL_H_

// Defines a generalized template class Interval<A> to represent
// the half-open interval [x .. x+n).
Expand Down Expand Up @@ -126,4 +126,4 @@ template <typename A> class Interval {
std::size_t size_{0};
};
} // namespace Fortran::common
#endif // FORTRAN_COMMON_INTERVAL_H_
#endif /* FORTRAN_SUPPORT_INTERVAL_H_ */
6 changes: 3 additions & 3 deletions flang/include/flang/Support/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_TEMPLATE_H_
#define FORTRAN_COMMON_TEMPLATE_H_
#ifndef FORTRAN_SUPPORT_TEMPLATE_H_
#define FORTRAN_SUPPORT_TEMPLATE_H_

#include "flang/Common/idioms.h"
#include "flang/Common/variant.h"
Expand Down Expand Up @@ -322,4 +322,4 @@ common::IfNoLvalue<typename VISITOR::Result, VISITOR> SearchTypes(
std::move(visitor), std::move(defaultResult));
}
} // namespace Fortran::common
#endif // FORTRAN_COMMON_TEMPLATE_H_
#endif /* FORTRAN_SUPPORT_TEMPLATE_H_ */
6 changes: 3 additions & 3 deletions flang/include/flang/Support/unwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_COMMON_UNWRAP_H_
#define FORTRAN_COMMON_UNWRAP_H_
#ifndef FORTRAN_SUPPORT_UNWRAP_H_
#define FORTRAN_SUPPORT_UNWRAP_H_

#include "indirection.h"
#include "reference-counted.h"
Expand Down Expand Up @@ -155,4 +155,4 @@ template <typename A, typename B> std::optional<A> UnwrapCopy(const B &x) {
}
}
} // namespace Fortran::common
#endif // FORTRAN_COMMON_UNWRAP_H_
#endif /* FORTRAN_SUPPORT_UNWRAP_H_ */
25 changes: 25 additions & 0 deletions flang/include/flang/Testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Files in this directory are used by Flang (the compiler) and FortranRuntime
(the runtime library for Flang-compiled programs). They must be compatible by
both. For definitions used only by Flang, consider
`flang/{lib,include/flang}/Support` instead. For definitions used only by
FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.

The requirements for common code include:

* No dependence to LLVM, including LLVMSupport.

* No link-dependence to the C++ runtime. This means that e.g. `std::string`
cannot be used.

* No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
instead.

* Preprocessor macros from `config.h` and CMake
`(target/add)_compile_definitions` must be defined by both build scripts.
See `flang/cmake/modules/FlangCommon.cmake`.

* Some header files are included from `.c` files.
`#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.

* Global declarations may need to be annotated using definitions from
`api-attrs.h`.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion flang/lib/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if(FLANG_VENDOR)
endif()


add_flang_library(FortranCommon
add_flang_library(FortranCommon PARTIAL_SOURCES_INTENDED
../Support/Fortran.cpp
../Support/Fortran-features.cpp
../Support/default-kinds.cpp
Expand Down
25 changes: 25 additions & 0 deletions flang/lib/Common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Files in this directory are used by Flang (the compiler) and FortranRuntime
(the runtime library for Flang-compiled programs). They must be compatible by
both. For definitions used only by Flang, consider
`flang/{lib,include/flang}/Support` instead. For definitions used only by
FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.

The requirements for common code include:

* No dependence to LLVM, including LLVMSupport.

* No link-dependence to the C++ runtime. This means that e.g. `std::string`
cannot be used.

* No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
instead.

* Preprocessor macros from `config.h` and CMake
`(target/add)_compile_definitions` must be defined by both build scripts.
See `flang/cmake/modules/FlangCommon.cmake`.

* Some header files are included from `.c` files.
`#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.

* Global declarations may need to be annotated using definitions from
`api-attrs.h`.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 11 additions & 12 deletions flang/lib/Decimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
endif ()
include_directories(BEFORE
${FLANG_SOURCE_DIR}/include
${FLANG_SOURCE_DIR}/../FortranRuntime/include)
${FLANG_SOURCE_DIR}/include)
endif()

check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
Expand All @@ -51,8 +50,8 @@ endif()
add_definitions(-U_GLIBCXX_ASSERTIONS)

set(sources
../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
../Common/binary-to-decimal.cpp
../Common/decimal-to-binary.cpp
)

include(AddFlangOffloadRuntime)
Expand All @@ -64,23 +63,23 @@ add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN ${sources})
if (DEFINED MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
add_flang_library(FortranDecimal.static INSTALL_WITH_TOOLCHAIN
../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
../Common/binary-to-decimal.cpp
../Common/decimal-to-binary.cpp
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
add_flang_library(FortranDecimal.dynamic INSTALL_WITH_TOOLCHAIN
../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
../Common/binary-to-decimal.cpp
../Common/decimal-to-binary.cpp
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
add_flang_library(FortranDecimal.static_dbg INSTALL_WITH_TOOLCHAIN
../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
../Common/binary-to-decimal.cpp
../Common/decimal-to-binary.cpp
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
add_flang_library(FortranDecimal.dynamic_dbg INSTALL_WITH_TOOLCHAIN
../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
../Common/binary-to-decimal.cpp
../Common/decimal-to-binary.cpp
)
add_dependencies(FortranDecimal FortranDecimal.static FortranDecimal.dynamic
FortranDecimal.static_dbg FortranDecimal.dynamic_dbg)
Expand Down
3 changes: 0 additions & 3 deletions flang/lib/Evaluate/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

using namespace Fortran::parser::literals;



namespace Fortran::evaluate {


void RealFlagWarnings(
FoldingContext &context, const RealFlags &flags, const char *operation) {
if (context.languageFeatures().ShouldWarn(
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Evaluate/fold-logical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "fold-implementation.h"
#include "fold-matmul.h"
#include "fold-reduction.h"
#include "flang/Common/magic-numbers.h"
#include "flang/Evaluate/check-expression.h"
#include "flang/Runtime/magic-numbers.h"

namespace Fortran::evaluate {

Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "flang/Optimizer/Support/FatalError.h"
#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Optimizer/Support/Utils.h"
#include "flang/Runtime/allocator-registry.h"
#include "flang/Runtime/allocator-registry-consts.h"
#include "flang/Semantics/runtime-type-info.h"
#include "flang/Semantics/tools.h"
#include "llvm/Support/CommandLine.h"
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Builder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)

add_flang_library(FIRBuilder
add_flang_library(FIRBuilder PARTIAL_SOURCES_INTENDED
BoxValue.cpp
Character.cpp
Complex.cpp
Expand Down
6 changes: 3 additions & 3 deletions flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "flang/Optimizer/Builder/Runtime/ArrayConstructor.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
#include "flang/Runtime/array-constructor.h"
#include "flang/Runtime/array-constructor-consts.h"

using namespace Fortran::runtime;

Expand All @@ -29,8 +29,8 @@ mlir::Value fir::runtime::genInitArrayConstructorVector(
// the target. The "cookieSize" argument is used to validate this wild
// assumption until runtime interfaces are improved.
std::size_t arrayVectorStructBitSize =
2 * sizeof(Fortran::runtime::ArrayConstructorVector) * 8;
std::size_t alignLike = alignof(Fortran::runtime::ArrayConstructorVector) * 8;
MaxArrayConstructorVectorSizeInBytes * 8;
std::size_t alignLike = MaxArrayConstructorVectorAlignInBytes * 8;
fir::SequenceType::Extent numElem =
(arrayVectorStructBitSize + alignLike - 1) / alignLike;
mlir::Type intType = builder.getIntegerType(alignLike);
Expand Down
18 changes: 7 additions & 11 deletions flang/lib/Optimizer/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Optimizer/Support/TypeCode.h"
#include "flang/Optimizer/Support/Utils.h"
#include "flang/Runtime/allocator-registry.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/allocator-registry-consts.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Semantics/runtime-type-info.h"
#include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
Expand Down Expand Up @@ -1273,16 +1273,12 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
insertField(rewriter, loc, descriptor, {kExtraPosInBox}, extraField);
} else {
// Compute the value of the extra field based on allocator_idx and
// addendum present using a Descriptor object.
Fortran::runtime::StaticDescriptor staticDescriptor;
Fortran::runtime::Descriptor &desc{staticDescriptor.descriptor()};
desc.raw().extra = 0;
desc.SetAllocIdx(allocatorIdx);
// addendum present.
unsigned extra = allocatorIdx << _CFI_ALLOCATOR_IDX_SHIFT;
if (hasAddendum)
desc.SetHasAddendum();
descriptor =
insertField(rewriter, loc, descriptor, {kExtraPosInBox},
this->genI32Constant(loc, rewriter, desc.raw().extra));
extra |= _CFI_ADDENDUM_FLAG;
descriptor = insertField(rewriter, loc, descriptor, {kExtraPosInBox},
this->genI32Constant(loc, rewriter, extra));
}

if (hasAddendum) {
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Dialect/FIRType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,4 +1467,4 @@ fir::getTypeSizeAndAlignmentOrCrash(mlir::Location loc, mlir::Type ty,
if (result)
return *result;
TODO(loc, "computing size of a component");
}
}
8 changes: 6 additions & 2 deletions flang/lib/Semantics/compute-offsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "flang/Evaluate/fold.h"
#include "flang/Evaluate/shape.h"
#include "flang/Evaluate/type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Semantics/scope.h"
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/symbol.h"
Expand Down Expand Up @@ -341,8 +341,12 @@ auto ComputeOffsetsHelper::GetSizeAndAlignment(
const auto *derived{evaluate::GetDerivedTypeSpec(dyType)};
int lenParams{derived ? CountLenParameters(*derived) : 0};
bool needAddendum{derived || (dyType && dyType->IsUnlimitedPolymorphic())};
std::size_t size{runtime::Descriptor::SizeInBytes(

// FIXME: Get descriptor size from targetCharacteristics instead
// overapproximation
std::size_t size{runtime::MaxDescriptorSizeInBytes(
symbol.Rank(), needAddendum, lenParams)};

return {size, targetCharacteristics.descriptorAlignment()};
}
if (IsProcedurePointer(symbol)) {
Expand Down
25 changes: 25 additions & 0 deletions flang/lib/Testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Files in this directory are used by Flang (the compiler) and FortranRuntime
(the runtime library for Flang-compiled programs). They must be compatible by
both. For definitions used only by Flang, consider
`flang/{lib,include/flang}/Support` instead. For definitions used only by
FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.

The requirements for common code include:

* No dependence to LLVM, including LLVMSupport.

* No link-dependence to the C++ runtime. This means that e.g. `std::string`
cannot be used.

* No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
instead.

* Preprocessor macros from `config.h` and CMake
`(target/add)_compile_definitions` must be defined by both build scripts.
See `flang/cmake/modules/FlangCommon.cmake`.

* Some header files are included from `.c` files.
`#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.

* Global declarations may need to be annotated using definitions from
`api-attrs.h`.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion flang/module/__fortran_builtins.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
!
!===------------------------------------------------------------------------===!

#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

! These naming shenanigans prevent names from Fortran intrinsic modules
! from being usable on INTRINSIC statements, and force the program
Expand Down
2 changes: 1 addition & 1 deletion flang/module/__fortran_ieee_exceptions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
! here under another name so that IEEE_ARITHMETIC can USE it and export its
! declarations without clashing with a non-intrinsic module in a program.

#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

module __fortran_ieee_exceptions
use __fortran_builtins, only: &
Expand Down
2 changes: 1 addition & 1 deletion flang/module/cudadevice.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!===-- module/cudadevice.f90 -----------------------------------------------===!
!===-- module/cudedevice.f90 -----------------------------------------------===!
!
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
! See https://llvm.org/LICENSE.txt for license information.
Expand Down
2 changes: 1 addition & 1 deletion flang/module/ieee_arithmetic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

! Fortran 2018 Clause 17

#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

module ieee_arithmetic
! F18 Clause 17.1p1:
Expand Down
2 changes: 1 addition & 1 deletion flang/module/iso_fortran_env.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

! See Fortran 2023, subclause 16.10.2

#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

module iso_fortran_env

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!===-- lib/Runtime/iso_fortran_env_impl.f90 --------------------------------===!
!===-- module/iso_fortran_env_impl.f90 --=--------------------------------===!
!
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
! See https://llvm.org/LICENSE.txt for license information.
Expand Down
43 changes: 11 additions & 32 deletions flang/module/mma.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,9 @@ pure __vector_pair function func_vpi0vp(arg1, arg2); \
!dir$ ignore_tkr(r) arg2; \
end function;

! FIXME: Potential Flang bug: combining multiple of those on a single line breaks after preprocessing as an explicit step as done by CMake
! Line counting is also wrong
FUNC_VPI0VI(1)
FUNC_VPI0VI(2)
FUNC_VPI0VI(4)
FUNC_VPI0VI(8)
FUNC_VPI0VU(1)
FUNC_VPI0VU(2)
FUNC_VPI0VU(4)
FUNC_VPI0VU(8)
FUNC_VPI0VR(4)
FUNC_VPI0VR(8)
FUNC_VPI0VI(1) FUNC_VPI0VI(2) FUNC_VPI0VI(4) FUNC_VPI0VI(8)
FUNC_VPI0VU(1) FUNC_VPI0VU(2) FUNC_VPI0VU(4) FUNC_VPI0VU(8)
FUNC_VPI0VR(4) FUNC_VPI0VR(8)
FUNC_VPI0VP

#undef FUNC_VPI0VP
Expand Down Expand Up @@ -153,26 +144,14 @@ elemental subroutine sub_vpvr##VKIND##vr##VKIND(pair, arg1, arg2); \
vector(real(VKIND)), intent(in) :: arg1, arg2; \
end subroutine ;

ELEM_SUB_VPVIVI(1)
ELEM_SUB_VPVIVI(2)
ELEM_SUB_VPVIVI(4)
ELEM_SUB_VPVIVI(8)
ELEM_SUB_VPVUVU(1)
ELEM_SUB_VPVUVU(2)
ELEM_SUB_VPVUVU(4)
ELEM_SUB_VPVUVU(8)
ELEM_SUB_VPVRVR(4)
ELEM_SUB_VPVRVR(8)
SUB_VPI0VI(1)
SUB_VPI0VI(2)
SUB_VPI0VI(4)
SUB_VPI0VI(8)
SUB_VPI0VU(1)
SUB_VPI0VU(2)
SUB_VPI0VU(4)
SUB_VPI0VU(8)
SUB_VPI0VR(4)
SUB_VPI0VR(8)
ELEM_SUB_VPVIVI(1) ELEM_SUB_VPVIVI(2)
ELEM_SUB_VPVIVI(4) ELEM_SUB_VPVIVI(8)
ELEM_SUB_VPVUVU(1) ELEM_SUB_VPVUVU(2)
ELEM_SUB_VPVUVU(4) ELEM_SUB_VPVUVU(8)
ELEM_SUB_VPVRVR(4) ELEM_SUB_VPVRVR(8)
SUB_VPI0VI(1) SUB_VPI0VI(2) SUB_VPI0VI(4) SUB_VPI0VI(8)
SUB_VPI0VU(1) SUB_VPI0VU(2) SUB_VPI0VU(4) SUB_VPI0VU(8)
SUB_VPI0VR(4) SUB_VPI0VR(8)

#undef ELEM_SUB_VPVIVI
#undef ELEM_SUB_VPVUVU
Expand Down
2 changes: 1 addition & 1 deletion flang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
if config.cc:
libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
libdecimal = os.path.join(config.flang_lib_dir, "libFortranDecimal.a")
include = os.path.join(config.flang_src_dir, "..", "FortranRuntime", "include")
include = os.path.join(config.flang_src_dir, "include")

if (
os.path.isfile(libruntime)
Expand Down
6 changes: 2 additions & 4 deletions flang/tools/f18/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,19 @@ if (NOT CMAKE_CROSSCOMPILING)
set(compile_with "-fsyntax-only")
set(object_output "")
set(include_in_link FALSE)
set(fullpath "${FLANG_SOURCE_DIR}/module/${filename}.f90")
if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
set(compile_with -c -o ${object_output})
set(include_in_link TRUE)
set(fullpath "${FLANG_SOURCE_DIR}/../FortranRuntime/lib/Runtime/${filename}.f90")
endif()

set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})
# TODO: We may need to flag this with conditional, in case Flang is built w/o OpenMP support
add_custom_command(OUTPUT ${base}.mod ${object_output}
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
COMMAND flang-new ${opts} ${decls} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
${fullpath}
DEPENDS flang-new ${fullpath} ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
${FLANG_SOURCE_DIR}/module/${filename}.f90
DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
)
list(APPEND MODULE_FILES ${base}.mod)
install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
Expand Down
6 changes: 4 additions & 2 deletions flang/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ endif()
add_custom_target(FlangUnitTests)
set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests")

include_directories("../../FortranRuntime/include")

function(add_flang_unittest_offload_properties target)
# Set CUDA_RESOLVE_DEVICE_SYMBOLS.
if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
Expand Down Expand Up @@ -72,8 +74,8 @@ function(add_flang_nongtest_unittest test_name)
endfunction()

add_subdirectory(Optimizer)
add_subdirectory(../../FortranRuntime/unittests/Common Common)
add_subdirectory(../../FortranRuntime/unittests/Decimal Decimal)
add_subdirectory(Common)
add_subdirectory(Decimal)
add_subdirectory(Evaluate)
add_subdirectory(../../FortranRuntime/unittests/Runtime Runtime)
add_subdirectory(Frontend)
3 changes: 3 additions & 0 deletions flang/unittests/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_flang_unittest(FlangCommonTests
FastIntSetTest.cpp
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- unittests/Common/FastIntSetTest.cpp ---------------------*- C++ -*-===//
//===-- flang/unittests/Common/FastIntSetTest.cpp ---------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang/Common/fast-int-set.h"
#include "gtest/gtest.h"
#include "flang/Common/fast-int-set.h"
#include <optional>

TEST(FastIntSetTests, Sanity) {
Expand Down
10 changes: 10 additions & 0 deletions flang/unittests/Decimal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_flang_nongtest_unittest(quick-sanity-test
FortranDecimal
)

# This test is not run by default as it takes a long time to execute.
add_flang_nongtest_unittest(thorough-test
SLOW_TEST
FortranDecimal
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//===-- unittests/Decimal/quick-sanity-test.cpp -----------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang/Common/decimal.h"
#include "llvm/Support/raw_ostream.h"
#include <cinttypes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//===-- unittests/Decimal/thorough-test.cpp ---------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang/Common/decimal.h"
#include "llvm/Support/raw_ostream.h"
#include <cinttypes>
Expand Down
6 changes: 3 additions & 3 deletions flang/unittests/Evaluate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_library(FortranEvaluateTesting
../../../FortranRuntime/lib/Testing/testing.cpp
../../../FortranRuntime/lib/Testing/fp-testing.cpp
../../lib/Testing/testing.cpp
../../lib/Testing/fp-testing.cpp
)
set_target_properties(FortranEvaluateTesting PROPERTIES FOLDER "Flang/Tests")
if (LLVM_LINK_LLVM_DYLIB)
Expand Down Expand Up @@ -76,4 +76,4 @@ add_flang_nongtest_unittest(folding
FortranSemantics
)

add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime)
add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "flang/Optimizer/Builder/Runtime/Allocatable.h"
#include "RuntimeCallTestBase.h"
#include "gtest/gtest.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/descriptor-consts.h"

using namespace Fortran::runtime;

Expand Down