From 42e5abb5b291e78aeb152d7c636c75fe4d90492a Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 14 Oct 2024 13:55:16 +0200 Subject: [PATCH 1/5] Split headers in preparation for cross-compilation. NFC. --- flang/include/flang/Lower/Allocatable.h | 2 +- .../flang/Optimizer/Builder/MutableBox.h | 2 +- .../flang/Optimizer/CodeGen/DescriptorModel.h | 2 +- flang/include/flang/Runtime/CUDA/allocator.h | 2 +- flang/include/flang/Runtime/CUDA/descriptor.h | 2 +- .../flang/Runtime/allocator-registry-consts.h | 20 +++++ .../flang/Runtime/allocator-registry.h | 9 +-- .../flang/Runtime/array-constructor-consts.h | 54 +++++++++++++ .../include/flang/Runtime/array-constructor.h | 80 +++---------------- .../include/flang/Runtime/descriptor-consts.h | 72 +++++++++++++++++ flang/include/flang/Runtime/descriptor.h | 15 +--- flang/include/flang/Runtime/io-api-funcs.h | 39 +++++++++ flang/include/flang/Runtime/io-api.h | 3 - flang/include/flang/Runtime/iostat-funcs.h | 23 ++++++ flang/include/flang/Runtime/iostat.h | 2 - flang/lib/Lower/ConvertVariable.cpp | 2 +- .../Builder/Runtime/ArrayConstructor.cpp | 6 +- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 18 ++--- flang/lib/Semantics/compute-offsets.cpp | 8 +- flang/runtime/environment-default-list.h | 0 flang/runtime/extensions.cpp | 2 +- flang/runtime/internal-unit.cpp | 2 + flang/runtime/io-api-common.h | 2 +- flang/runtime/io-api-minimal.cpp | 2 +- flang/runtime/io-api.cpp | 2 +- flang/runtime/io-error.h | 2 +- flang/runtime/io-stmt.h | 2 +- flang/runtime/iostat.cpp | 2 +- flang/runtime/namelist.cpp | 2 +- .../Builder/Runtime/AllocatableTest.cpp | 2 +- 30 files changed, 254 insertions(+), 127 deletions(-) create mode 100644 flang/include/flang/Runtime/allocator-registry-consts.h create mode 100644 flang/include/flang/Runtime/array-constructor-consts.h create mode 100644 flang/include/flang/Runtime/descriptor-consts.h create mode 100644 flang/include/flang/Runtime/io-api-funcs.h create mode 100644 flang/include/flang/Runtime/iostat-funcs.h mode change 100755 => 100644 flang/runtime/environment-default-list.h diff --git a/flang/include/flang/Lower/Allocatable.h b/flang/include/flang/Lower/Allocatable.h index 1209b157ed1f41..0e89af94af40f6 100644 --- a/flang/include/flang/Lower/Allocatable.h +++ b/flang/include/flang/Lower/Allocatable.h @@ -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 { diff --git a/flang/include/flang/Optimizer/Builder/MutableBox.h b/flang/include/flang/Optimizer/Builder/MutableBox.h index fea7c7204837b4..39657ddaf6e03a 100644 --- a/flang/include/flang/Optimizer/Builder/MutableBox.h +++ b/flang/include/flang/Optimizer/Builder/MutableBox.h @@ -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 { diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h index ff0cf29e8073e6..9cccf8db87270e 100644 --- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h +++ b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h @@ -23,7 +23,7 @@ #define OPTIMIZER_DESCRIPTOR_MODEL_H #include "flang/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" diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h index 4527c9f18fa054..cc88896b1f0bd6 100644 --- a/flang/include/flang/Runtime/CUDA/allocator.h +++ b/flang/include/flang/Runtime/CUDA/allocator.h @@ -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) \ diff --git a/flang/include/flang/Runtime/CUDA/descriptor.h b/flang/include/flang/Runtime/CUDA/descriptor.h index d593989420420f..501a834f43bd42 100644 --- a/flang/include/flang/Runtime/CUDA/descriptor.h +++ b/flang/include/flang/Runtime/CUDA/descriptor.h @@ -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 diff --git a/flang/include/flang/Runtime/allocator-registry-consts.h b/flang/include/flang/Runtime/allocator-registry-consts.h new file mode 100644 index 00000000000000..70735c2fc7a71c --- /dev/null +++ b/flang/include/flang/Runtime/allocator-registry-consts.h @@ -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_ */ diff --git a/flang/include/flang/Runtime/allocator-registry.h b/flang/include/flang/Runtime/allocator-registry.h index acfada506fafc6..c5db7b2b1f2014 100644 --- a/flang/include/flang/Runtime/allocator-registry.h +++ b/flang/include/flang/Runtime/allocator-registry.h @@ -10,17 +10,10 @@ #define FORTRAN_RUNTIME_ALLOCATOR_H_ #include "flang/Common/api-attrs.h" +#include "flang/Runtime/allocator-registry-consts.h" #include #include -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; - #define MAX_ALLOCATOR 7 // 3 bits are reserved in the descriptor. namespace Fortran::runtime { diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h new file mode 100644 index 00000000000000..da058874e50487 --- /dev/null +++ b/flang/include/flang/Runtime/array-constructor-consts.h @@ -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 + +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_ */ diff --git a/flang/include/flang/Runtime/array-constructor.h b/flang/include/flang/Runtime/array-constructor.h index 46fc0418c7991e..c068af9ba120c0 100644 --- a/flang/include/flang/Runtime/array-constructor.h +++ b/flang/include/flang/Runtime/array-constructor.h @@ -12,6 +12,7 @@ #ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ #define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ +#include "flang/Runtime/array-constructor-consts.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/entry-names.h" #include @@ -42,77 +43,14 @@ struct ArrayConstructorVector { private: unsigned char useValueLengthParameters_ : 1; }; +static_assert(sizeof(Fortran::runtime::ArrayConstructorVector) <= + MaxArrayConstructorVectorSizeInBytes, + "ABI requires sizeof(ArrayConstructorVector) to be smaller than " + "MaxArrayConstructorVectorSizeInBytes"); +static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <= + MaxArrayConstructorVectorAlignInBytes, + "ABI requires alignof(ArrayConstructorVector) to be smaller than " + "MaxArrayConstructorVectorAlignInBytes"); -// This file defines an API to "push" an evaluated array constructor value -// "from" into some storage "to" of an array constructor. It can be seen as a -// form of std::vector::push_back() implementation for Fortran array -// constructors. In the APIs and ArrayConstructorVector struct above: -// -// - "to" is a ranked-1 descriptor whose declared type is already set to the -// array constructor derived type. It may be already allocated, even before the -// first call to this API, or it may be unallocated. "to" extent is increased -// every time a "from" is pushed past its current extent. At this end of the -// API calls, its extent is the extent of the array constructor. If "to" is -// unallocated and its extent is not null, it is assumed this is the final array -// constructor extent value, and the first allocation already "reserves" storage -// space accordingly to avoid reallocations. -// - "from" is a scalar or array descriptor for the evaluated array -// constructor value that must be copied into the storage of "to" at -// "nextValuePosition". -// - "useValueLengthParameters" must be set to true if the array constructor -// has length parameters and no type spec. If it is true and "to" is -// unallocated, "to" will take the length parameters of "from". If it is true -// and "to" is an allocated character array constructor, it will be checked -// that "from" length matches the one from "to". When it is false, the -// character length must already be set in "to" before the first call to this -// API and "from" character lengths are allowed to mismatch from "to". -// - "nextValuePosition" is the zero based sequence position of "from" in the -// array constructor. It is updated after this call by the number of "from" -// elements. It should be set to zero by the caller of this API before the first -// call. -// - "actualAllocationSize" is the current allocation size of "to" storage. It -// may be bigger than "to" extent for reallocation optimization purposes, but -// should never be smaller, unless this is the first call and "to" is -// unallocated. It is updated by the runtime after each successful allocation or -// reallocation. It should be set to "to" extent if "to" is allocated before the -// first call of this API, and can be left undefined otherwise. -// -// Note that this API can be used with "to" being a variable (that can be -// discontiguous). This can be done when the variable is the left hand side of -// an assignment from an array constructor as long as: -// - none of the ac-value overlaps with the variable, -// - this is an intrinsic assignment that is not a whole allocatable -// assignment, *and* for a type that has no components requiring user defined -// assignments, -// - the variable is properly finalized before using this API if its need to, -// - "useValueLengthParameters" should be set to false in this case, even if -// the array constructor has no type-spec, since the variable may have a -// different character length than the array constructor values. - -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_ARRAYCONSTRUCTOR_H_ diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h new file mode 100644 index 00000000000000..098eb59ca01b2e --- /dev/null +++ b/flang/include/flang/Runtime/descriptor-consts.h @@ -0,0 +1,72 @@ +//===-- 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/api-attrs.h" +#include "flang/ISO_Fortran_binding_wrapper.h" +#include +#include + +// 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; + +/// 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(lengthTypeParameters) * 8u; + } + return bytes; +} + +} // namespace Fortran::runtime +#endif /* FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ */ diff --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h index 030d0c1031fbaa..6d0f09c79508cb 100644 --- a/flang/include/flang/Runtime/descriptor.h +++ b/flang/include/flang/Runtime/descriptor.h @@ -19,6 +19,7 @@ // but should never reference this internal header. #include "flang/ISO_Fortran_binding_wrapper.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/memory.h" #include "flang/Runtime/type-code.h" #include @@ -28,11 +29,6 @@ #include #include -namespace Fortran::runtime::typeInfo { -using TypeParameterValue = std::int64_t; -class DerivedType; -} // namespace Fortran::runtime::typeInfo - namespace Fortran::runtime { using SubscriptValue = ISO::CFI_index_t; @@ -420,13 +416,6 @@ class Descriptor { void Dump(FILE * = stdout) const; -// 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 - RT_API_ATTRS inline bool HasAddendum() const { return raw_.extra & _CFI_ADDENDUM_FLAG; } @@ -464,6 +453,8 @@ class alignas(Descriptor) StaticDescriptor { static constexpr bool hasAddendum{ADDENDUM || MAX_LEN_PARMS > 0}; static constexpr std::size_t byteSize{ Descriptor::SizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)}; + static_assert(byteSize <= + MaxDescriptorSizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)); RT_OFFLOAD_VAR_GROUP_END RT_API_ATTRS Descriptor &descriptor() { diff --git a/flang/include/flang/Runtime/io-api-funcs.h b/flang/include/flang/Runtime/io-api-funcs.h new file mode 100644 index 00000000000000..e81c3cb8156c4e --- /dev/null +++ b/flang/include/flang/Runtime/io-api-funcs.h @@ -0,0 +1,39 @@ +//===-- include/flang/Runtime/io-api-funcs.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 API between compiled code and I/O runtime library. + +#ifndef FORTRAN_RUNTIME_IO_API_FUNCS_H_ +#define FORTRAN_RUNTIME_IO_API_FUNCS_H_ + +#include "flang/Common/uint128.h" +#include "flang/Runtime/entry-names.h" +#include "flang/Runtime/io-api.h" +#include "flang/Runtime/iostat.h" +#include "flang/Runtime/magic-numbers.h" +#include +#include + +namespace Fortran::runtime { +class Descriptor; +} // namespace Fortran::runtime + +namespace Fortran::runtime::io { + +struct NonTbpDefinedIoTable; +class NamelistGroup; +class IoStatementState; +using Cookie = IoStatementState *; +using ExternalUnit = int; +using AsynchronousId = int; + +RT_API_ATTRS const char *InquiryKeywordHashDecode( + char *buffer, std::size_t, InquiryKeywordHash); + +} // namespace Fortran::runtime::io +#endif /* FORTRAN_RUNTIME_IO_API_FUNCS_H_ */ diff --git a/flang/include/flang/Runtime/io-api.h b/flang/include/flang/Runtime/io-api.h index 328afc715a3f1e..e588b46dc4b3a1 100644 --- a/flang/include/flang/Runtime/io-api.h +++ b/flang/include/flang/Runtime/io-api.h @@ -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) diff --git a/flang/include/flang/Runtime/iostat-funcs.h b/flang/include/flang/Runtime/iostat-funcs.h new file mode 100644 index 00000000000000..3ab4527ea829ae --- /dev/null +++ b/flang/include/flang/Runtime/iostat-funcs.h @@ -0,0 +1,23 @@ +//===-- include/flang/Runtime/iostat-funcs.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 values returned by the runtime for IOSTAT= specifiers +// on I/O statements. + +#ifndef FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ +#define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ + +#include "flang/Common/api-attrs.h" +#include "flang/Runtime/iostat.h" + +namespace Fortran::runtime::io { + +RT_API_ATTRS const char *IostatErrorString(int); + +} // namespace Fortran::runtime::io +#endif /* FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ */ diff --git a/flang/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat.h index 6ce7c82b424eb7..0565718f6c103d 100644 --- a/flang/include/flang/Runtime/iostat.h +++ b/flang/include/flang/Runtime/iostat.h @@ -89,7 +89,5 @@ enum Iostat { IostatNonExternalDefinedUnformattedIo, }; -RT_API_ATTRS const char *IostatErrorString(int); - } // namespace Fortran::runtime::io #endif // FORTRAN_RUNTIME_IOSTAT_H_ diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index f76d44f5479d32..82bedca7bd41dd 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -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" diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp index c786bef5cb1c4c..b7c6dc5fb2bf6c 100644 --- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp @@ -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; @@ -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); diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 88293bcf36a780..eed389380f7cca 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -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" @@ -1273,16 +1273,12 @@ struct EmboxCommonConversion : public fir::FIROpConversion { 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) { diff --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp index b5a58ddca0ecdd..c5774ed30de748 100644 --- a/flang/lib/Semantics/compute-offsets.cpp +++ b/flang/lib/Semantics/compute-offsets.cpp @@ -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" @@ -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)) { diff --git a/flang/runtime/environment-default-list.h b/flang/runtime/environment-default-list.h old mode 100755 new mode 100644 diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp index be3833db88b07a..8cd5f3ce696b49 100644 --- a/flang/runtime/extensions.cpp +++ b/flang/runtime/extensions.cpp @@ -15,7 +15,7 @@ #include "flang/Runtime/command.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/entry-names.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" #include #include #include diff --git a/flang/runtime/internal-unit.cpp b/flang/runtime/internal-unit.cpp index f28700ee015815..f8f3877efb20ea 100644 --- a/flang/runtime/internal-unit.cpp +++ b/flang/runtime/internal-unit.cpp @@ -36,6 +36,8 @@ RT_API_ATTRS InternalDescriptorUnit::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; diff --git a/flang/runtime/io-api-common.h b/flang/runtime/io-api-common.h index c7b86cab73a525..b4ac9a61c09ec3 100644 --- a/flang/runtime/io-api-common.h +++ b/flang/runtime/io-api-common.h @@ -14,7 +14,7 @@ #include "unit.h" #include "flang/Common/api-attrs.h" #include "flang/Common/optional.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" namespace Fortran::runtime::io { diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp index ad76fe3de0324c..82376cf9641664 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang/runtime/io-api-minimal.cpp @@ -16,7 +16,7 @@ #include "terminator.h" #include "tools.h" #include "unit.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" namespace Fortran::runtime::io { RT_EXT_API_GROUP_BEGIN diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp index e3c6b9e5ca8959..0fe69c981d17c7 100644 --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -13,7 +13,6 @@ // OutputReal{32,64}, OutputComplex{32,64}, OutputAscii, & EndIoStatement() // are in runtime/io-api-minimal.cpp. -#include "flang/Runtime/io-api.h" #include "descriptor-io.h" #include "edit-input.h" #include "edit-output.h" @@ -26,6 +25,7 @@ #include "unit.h" #include "flang/Common/optional.h" #include "flang/Runtime/descriptor.h" +#include "flang/Runtime/io-api-funcs.h" #include "flang/Runtime/memory.h" #include #include diff --git a/flang/runtime/io-error.h b/flang/runtime/io-error.h index 426573e2faf00c..22e43db7102882 100644 --- a/flang/runtime/io-error.h +++ b/flang/runtime/io-error.h @@ -16,7 +16,7 @@ #define FORTRAN_RUNTIME_IO_ERROR_H_ #include "terminator.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-funcs.h" #include "flang/Runtime/memory.h" #include diff --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h index 2e0ca46078ecdc..30d7bd86c54b37 100644 --- a/flang/runtime/io-stmt.h +++ b/flang/runtime/io-stmt.h @@ -20,7 +20,7 @@ #include "flang/Common/reference-wrapper.h" #include "flang/Common/visit.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" #include #include #include diff --git a/flang/runtime/iostat.cpp b/flang/runtime/iostat.cpp index 39e224cb01286b..0d71eb09e0a504 100644 --- a/flang/runtime/iostat.cpp +++ b/flang/runtime/iostat.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-funcs.h" namespace Fortran::runtime::io { RT_OFFLOAD_API_GROUP_BEGIN diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp index af092de70f7819..cfed7f2c6bf97d 100644 --- a/flang/runtime/namelist.cpp +++ b/flang/runtime/namelist.cpp @@ -10,7 +10,7 @@ #include "descriptor-io.h" #include "emit-encoded.h" #include "io-stmt.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" #include #include #include diff --git a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp index 1db43cacc90f07..f618e72d7b7f3c 100644 --- a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp +++ b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp @@ -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; From 8757eb974fcc57630e85ed1ad838bb2dbbb5a162 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 14 Oct 2024 16:51:07 +0200 Subject: [PATCH 2/5] Move SubscriptValue to public header --- flang/include/flang/Runtime/descriptor-consts.h | 1 + flang/include/flang/Runtime/descriptor.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h index 098eb59ca01b2e..c08e5018d0af53 100644 --- a/flang/include/flang/Runtime/descriptor-consts.h +++ b/flang/include/flang/Runtime/descriptor-consts.h @@ -28,6 +28,7 @@ class DerivedType; 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 diff --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h index 6d0f09c79508cb..dd36fba157ca92 100644 --- a/flang/include/flang/Runtime/descriptor.h +++ b/flang/include/flang/Runtime/descriptor.h @@ -31,7 +31,6 @@ namespace Fortran::runtime { -using SubscriptValue = ISO::CFI_index_t; class Terminator; RT_VAR_GROUP_BEGIN From b1dafd4a54487791d2495b07bfe265e0a4f05bba Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 14 Oct 2024 17:05:51 +0200 Subject: [PATCH 3/5] Keep common files in flang/ --- .../Runtime/allocator-registry.h | 11 +- .../Runtime/array-constructor.h | 48 +++++++ .../Runtime/descriptor.h | 22 +--- .../FortranRuntime/Runtime/io-api-funcs.h | 39 ++++++ .../FortranRuntime/Runtime/iostat-funcs.h | 23 ++++ .../Runtime/memory.h | 2 +- .../Runtime/type-code.h | 2 +- .../include/flang/Runtime/array-constructor.h | 118 ------------------ FortranRuntime/lib/Runtime/CMakeLists.txt | 5 +- FortranRuntime/lib/Runtime/CUDA/allocator.cpp | 4 +- .../lib/Runtime/CUDA/descriptor.cpp | 4 +- .../lib/Runtime/Float128Math/math-entries.h | 4 +- .../lib/Runtime/ISO_Fortran_binding.cpp | 6 +- FortranRuntime/lib/Runtime/ISO_Fortran_util.h | 6 +- FortranRuntime/lib/Runtime/allocatable.cpp | 10 +- .../lib/Runtime/allocator-registry.cpp | 2 +- .../lib/Runtime/array-constructor.cpp | 8 +- FortranRuntime/lib/Runtime/assign.cpp | 2 +- FortranRuntime/lib/Runtime/buffer.h | 4 +- FortranRuntime/lib/Runtime/character.cpp | 6 +- FortranRuntime/lib/Runtime/command.cpp | 4 +- FortranRuntime/lib/Runtime/connection.h | 2 +- FortranRuntime/lib/Runtime/copy.cpp | 4 +- FortranRuntime/lib/Runtime/copy.h | 2 +- FortranRuntime/lib/Runtime/derived-api.cpp | 2 +- FortranRuntime/lib/Runtime/derived.cpp | 2 +- FortranRuntime/lib/Runtime/descriptor-io.h | 8 +- FortranRuntime/lib/Runtime/descriptor.cpp | 10 +- FortranRuntime/lib/Runtime/dot-product.cpp | 8 +- FortranRuntime/lib/Runtime/edit-input.cpp | 4 +- FortranRuntime/lib/Runtime/edit-input.h | 2 +- FortranRuntime/lib/Runtime/edit-output.cpp | 2 +- FortranRuntime/lib/Runtime/edit-output.h | 4 +- FortranRuntime/lib/Runtime/execute.cpp | 2 +- FortranRuntime/lib/Runtime/extensions.cpp | 8 +- FortranRuntime/lib/Runtime/extrema.cpp | 2 +- FortranRuntime/lib/Runtime/file.cpp | 4 +- FortranRuntime/lib/Runtime/file.h | 4 +- FortranRuntime/lib/Runtime/findloc.cpp | 2 +- .../lib/Runtime/format-implementation.h | 6 +- FortranRuntime/lib/Runtime/format.h | 2 +- FortranRuntime/lib/Runtime/inquiry.cpp | 2 +- FortranRuntime/lib/Runtime/internal-unit.cpp | 6 +- FortranRuntime/lib/Runtime/internal-unit.h | 2 +- FortranRuntime/lib/Runtime/io-api-common.h | 6 +- FortranRuntime/lib/Runtime/io-api-minimal.cpp | 2 +- FortranRuntime/lib/Runtime/io-api.cpp | 8 +- FortranRuntime/lib/Runtime/io-error.cpp | 2 +- FortranRuntime/lib/Runtime/io-error.h | 4 +- FortranRuntime/lib/Runtime/io-stmt.cpp | 2 +- FortranRuntime/lib/Runtime/io-stmt.h | 10 +- FortranRuntime/lib/Runtime/iostat.cpp | 2 +- .../lib/Runtime/matmul-transpose.cpp | 6 +- FortranRuntime/lib/Runtime/matmul.cpp | 6 +- FortranRuntime/lib/Runtime/memory.cpp | 4 +- FortranRuntime/lib/Runtime/misc-intrinsic.cpp | 4 +- FortranRuntime/lib/Runtime/namelist.cpp | 2 +- FortranRuntime/lib/Runtime/namelist.h | 2 +- .../lib/Runtime/numeric-templates.h | 4 +- FortranRuntime/lib/Runtime/numeric.cpp | 2 +- FortranRuntime/lib/Runtime/product.cpp | 2 +- FortranRuntime/lib/Runtime/random-templates.h | 4 +- FortranRuntime/lib/Runtime/random.cpp | 8 +- FortranRuntime/lib/Runtime/reduce.cpp | 2 +- .../lib/Runtime/reduction-templates.h | 4 +- FortranRuntime/lib/Runtime/reduction.cpp | 2 +- FortranRuntime/lib/Runtime/stack.h | 2 +- FortranRuntime/lib/Runtime/stat.cpp | 2 +- FortranRuntime/lib/Runtime/stat.h | 2 +- FortranRuntime/lib/Runtime/sum.cpp | 2 +- FortranRuntime/lib/Runtime/support.cpp | 2 +- .../lib/Runtime/temporary-stack.cpp | 6 +- FortranRuntime/lib/Runtime/time-intrinsic.cpp | 4 +- FortranRuntime/lib/Runtime/tools.h | 8 +- .../lib/Runtime/transformational.cpp | 4 +- FortranRuntime/lib/Runtime/type-code.cpp | 2 +- FortranRuntime/lib/Runtime/type-info.cpp | 10 +- FortranRuntime/lib/Runtime/type-info.h | 4 +- FortranRuntime/lib/Runtime/unit-map.h | 4 +- FortranRuntime/lib/Runtime/unit.h | 6 +- .../unittests/Common/CMakeLists.txt | 11 -- .../unittests/Decimal/CMakeLists.txt | 18 --- .../Evaluate/ISO-Fortran-binding.cpp | 3 +- FortranRuntime/unittests/Evaluate/reshape.cpp | 2 +- .../unittests/Runtime/AccessTest.cpp | 2 +- .../unittests/Runtime/Allocatable.cpp | 2 +- .../unittests/Runtime/ArrayConstructor.cpp | 10 +- .../unittests/Runtime/CUDA/AllocatorCUF.cpp | 10 +- .../unittests/Runtime/CharacterTest.cpp | 2 +- .../unittests/Runtime/CommandTest.cpp | 6 +- FortranRuntime/unittests/Runtime/Derived.cpp | 6 +- .../unittests/Runtime/ExternalIOTest.cpp | 6 +- FortranRuntime/unittests/Runtime/Inquiry.cpp | 4 +- .../unittests/Runtime/ListInputTest.cpp | 6 +- .../unittests/Runtime/LogicalFormatTest.cpp | 4 +- FortranRuntime/unittests/Runtime/Matmul.cpp | 8 +- .../unittests/Runtime/MatmulTranspose.cpp | 8 +- .../unittests/Runtime/MiscIntrinsic.cpp | 8 +- FortranRuntime/unittests/Runtime/Namelist.cpp | 4 +- FortranRuntime/unittests/Runtime/Numeric.cpp | 2 +- .../unittests/Runtime/NumericalFormatTest.cpp | 4 +- FortranRuntime/unittests/Runtime/Pointer.cpp | 4 +- FortranRuntime/unittests/Runtime/Random.cpp | 6 +- .../unittests/Runtime/Reduction.cpp | 8 +- .../unittests/Runtime/RuntimeCrashTest.cpp | 4 +- FortranRuntime/unittests/Runtime/Stop.cpp | 2 +- FortranRuntime/unittests/Runtime/Support.cpp | 4 +- .../unittests/Runtime/TemporaryStack.cpp | 8 +- FortranRuntime/unittests/Runtime/Time.cpp | 2 +- .../unittests/Runtime/Transformational.cpp | 6 +- FortranRuntime/unittests/Runtime/tools.h | 6 +- flang/CMakeLists.txt | 3 +- .../include/flang/Common/Fortran-consts.h | 0 .../Common/ISO_Fortran_binding_wrapper.h | 2 +- flang/include/flang/Common/README.md | 25 ++++ .../include/flang/Common/api-attrs.h | 11 +- .../flang/Common/binary-floating-point.h | 0 .../flang/Common/bit-population-count.h | 2 +- .../include/flang/Common/constexpr-bitset.h | 2 +- .../include/flang/Common/decimal.h | 0 .../include/flang/Common/enum-class.h | 2 +- .../include/flang/Common/enum-set.h | 2 +- .../include/flang/Common/fast-int-set.h | 4 +- .../include/flang/Common/float128.h | 2 +- .../include/flang/Common/format.h | 2 +- .../include/flang/Common/idioms.h | 2 +- .../flang/Common/leading-zero-bit-count.h | 2 +- .../include/flang/Common/optional.h | 6 +- .../include/flang/Common/real.h | 2 +- .../include/flang/Common/reference-wrapper.h | 6 +- .../include/flang/Common/restorer.h | 4 +- .../include/flang/Common/target-rounding.h | 0 .../include/flang/Common/uint128.h | 4 +- .../include/flang/Common/variant.h | 6 +- .../include/flang/Common/visit.h | 4 +- .../include/flang/Common/windows-include.h | 2 +- flang/include/flang/ISO_Fortran_binding.h | 13 +- flang/include/flang/Lower/Allocatable.h | 2 +- .../flang/Optimizer/Builder/IntrinsicCall.h | 1 - .../flang/Optimizer/Builder/MutableBox.h | 2 +- .../flang/Optimizer/CodeGen/DescriptorModel.h | 2 +- .../include/flang/Runtime/CUDA/allocator.h | 4 +- .../include/flang/Runtime/CUDA/descriptor.h | 4 +- flang/include/flang/Runtime/README.md | 25 ++++ .../include/flang/Runtime/allocatable.h | 7 +- .../flang/Runtime/allocator-registry-consts.h | 20 +++ .../flang/Runtime/array-constructor-consts.h | 54 ++++++++ .../include/flang/Runtime/assign.h | 2 +- .../include/flang/Runtime/c-or-cpp.h | 2 +- .../include/flang/Runtime/character.h | 2 +- .../include/flang/Runtime/command.h | 2 +- .../include/flang/Runtime/cpp-type.h | 2 +- .../include/flang/Runtime/derived-api.h | 2 +- .../include/flang/Runtime/descriptor-consts.h | 72 +++++++++++ .../include/flang/Runtime/entry-names.h | 11 +- .../include/flang/Runtime/exceptions.h | 4 +- .../include/flang/Runtime/execute.h | 4 +- .../include/flang/Runtime/extensions.h | 2 +- .../flang/Runtime/freestanding-tools.h | 2 +- .../include/flang/Runtime/inquiry.h | 4 +- .../include/flang/Runtime/io-api.h | 7 +- .../include/flang/Runtime/iostat.h | 6 +- .../include/flang/Runtime}/magic-numbers.h | 6 +- .../include/flang/Runtime/main.h | 2 +- .../flang/Runtime/matmul-instances.inc | 0 .../include/flang/Runtime/matmul-transpose.h | 2 +- .../include/flang/Runtime/matmul.h | 2 +- .../include/flang/Runtime/misc-intrinsic.h | 2 +- .../include/flang/Runtime/numeric.h | 2 +- .../include/flang/Runtime/pointer.h | 6 +- .../include/flang/Runtime/ragged.h | 4 +- .../include/flang/Runtime/random.h | 0 .../include/flang/Runtime/reduce.h | 2 +- .../include/flang/Runtime/reduction.h | 2 +- .../include/flang/Runtime/stop.h | 2 +- .../include/flang/Runtime/support.h | 2 +- .../include/flang/Runtime/temporary-stack.h | 2 +- .../include/flang/Runtime/time-intrinsic.h | 2 +- .../include/flang/Runtime/transformational.h | 2 +- .../include/flang/Support/Fortran-features.h | 6 +- flang/include/flang/Support/Fortran.h | 8 +- flang/include/flang/Support/MathOptionsBase.h | 6 +- flang/include/flang/Support/Version.h | 6 +- flang/include/flang/Support/default-kinds.h | 6 +- flang/include/flang/Support/indirection.h | 6 +- flang/include/flang/Support/interval.h | 6 +- flang/include/flang/Support/template.h | 6 +- flang/include/flang/Support/unwrap.h | 6 +- flang/include/flang/Testing/README.md | 25 ++++ .../include/flang/Testing/fp-testing.h | 0 .../include/flang/Testing/testing.h | 0 flang/lib/Common/CMakeLists.txt | 2 +- flang/lib/Common/README.md | 25 ++++ .../lib/Common/big-radix-floating-point.h | 0 .../lib/Common/binary-to-decimal.cpp | 0 .../lib/Common/decimal-to-binary.cpp | 0 flang/lib/Decimal/CMakeLists.txt | 23 ++-- flang/lib/Evaluate/common.cpp | 3 - flang/lib/Evaluate/fold-logical.cpp | 2 +- flang/lib/Lower/ConvertVariable.cpp | 2 +- flang/lib/Optimizer/Builder/CMakeLists.txt | 2 +- .../Builder/Runtime/ArrayConstructor.cpp | 6 +- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 18 ++- flang/lib/Optimizer/Dialect/FIRType.cpp | 2 +- flang/lib/Semantics/compute-offsets.cpp | 8 +- flang/lib/Testing/README.md | 25 ++++ .../lib/Testing/fp-testing.cpp | 0 .../lib/Testing/testing.cpp | 0 flang/module/__fortran_builtins.f90 | 2 +- flang/module/__fortran_ieee_exceptions.f90 | 2 +- flang/module/cudadevice.f90 | 2 +- flang/module/ieee_arithmetic.f90 | 2 +- flang/module/iso_fortran_env.f90 | 2 +- .../module}/iso_fortran_env_impl.f90 | 2 +- flang/test/lit.cfg.py | 2 +- flang/tools/f18/CMakeLists.txt | 6 +- flang/unittests/CMakeLists.txt | 6 +- flang/unittests/Common/CMakeLists.txt | 3 + .../unittests/Common/FastIntSetTest.cpp | 4 +- flang/unittests/Decimal/CMakeLists.txt | 10 ++ .../unittests/Decimal/quick-sanity-test.cpp | 8 -- .../unittests/Decimal/thorough-test.cpp | 8 -- flang/unittests/Evaluate/CMakeLists.txt | 6 +- .../Builder/Runtime/AllocatableTest.cpp | 2 +- 224 files changed, 814 insertions(+), 587 deletions(-) rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/allocator-registry.h (82%) create mode 100644 FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/descriptor.h (96%) create mode 100644 FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h create mode 100644 FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/memory.h (98%) rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/type-code.h (97%) delete mode 100644 FortranRuntime/include/flang/Runtime/array-constructor.h delete mode 100644 FortranRuntime/unittests/Common/CMakeLists.txt delete mode 100644 FortranRuntime/unittests/Decimal/CMakeLists.txt rename {FortranRuntime => flang}/include/flang/Common/Fortran-consts.h (100%) rename {FortranRuntime => flang}/include/flang/Common/ISO_Fortran_binding_wrapper.h (97%) create mode 100644 flang/include/flang/Common/README.md rename {FortranRuntime => flang}/include/flang/Common/api-attrs.h (97%) rename {FortranRuntime => flang}/include/flang/Common/binary-floating-point.h (100%) rename {FortranRuntime => flang}/include/flang/Common/bit-population-count.h (98%) rename {FortranRuntime => flang}/include/flang/Common/constexpr-bitset.h (98%) rename {FortranRuntime => flang}/include/flang/Common/decimal.h (100%) rename {FortranRuntime => flang}/include/flang/Common/enum-class.h (98%) rename {FortranRuntime => flang}/include/flang/Common/enum-set.h (99%) rename {FortranRuntime => flang}/include/flang/Common/fast-int-set.h (97%) rename {FortranRuntime => flang}/include/flang/Common/float128.h (96%) rename {FortranRuntime => flang}/include/flang/Common/format.h (99%) rename {FortranRuntime => flang}/include/flang/Common/idioms.h (99%) rename {FortranRuntime => flang}/include/flang/Common/leading-zero-bit-count.h (98%) rename {FortranRuntime => flang}/include/flang/Common/optional.h (98%) rename {FortranRuntime => flang}/include/flang/Common/real.h (99%) rename {FortranRuntime => flang}/include/flang/Common/reference-wrapper.h (96%) rename {FortranRuntime => flang}/include/flang/Common/restorer.h (97%) rename {FortranRuntime => flang}/include/flang/Common/target-rounding.h (100%) rename {FortranRuntime => flang}/include/flang/Common/uint128.h (99%) rename {FortranRuntime => flang}/include/flang/Common/variant.h (89%) rename {FortranRuntime => flang}/include/flang/Common/visit.h (98%) rename {FortranRuntime => flang}/include/flang/Common/windows-include.h (93%) rename {FortranRuntime => flang}/include/flang/Runtime/CUDA/allocator.h (93%) rename {FortranRuntime => flang}/include/flang/Runtime/CUDA/descriptor.h (91%) create mode 100644 flang/include/flang/Runtime/README.md rename {FortranRuntime => flang}/include/flang/Runtime/allocatable.h (97%) create mode 100644 flang/include/flang/Runtime/allocator-registry-consts.h create mode 100644 flang/include/flang/Runtime/array-constructor-consts.h rename {FortranRuntime => flang}/include/flang/Runtime/assign.h (98%) rename {FortranRuntime => flang}/include/flang/Runtime/c-or-cpp.h (95%) rename {FortranRuntime => flang}/include/flang/Runtime/character.h (99%) rename {FortranRuntime => flang}/include/flang/Runtime/command.h (98%) rename {FortranRuntime => flang}/include/flang/Runtime/cpp-type.h (98%) rename {FortranRuntime => flang}/include/flang/Runtime/derived-api.h (98%) create mode 100644 flang/include/flang/Runtime/descriptor-consts.h rename {FortranRuntime => flang}/include/flang/Runtime/entry-names.h (89%) rename {FortranRuntime => flang}/include/flang/Runtime/exceptions.h (86%) rename {FortranRuntime => flang}/include/flang/Runtime/execute.h (89%) rename {FortranRuntime => flang}/include/flang/Runtime/extensions.h (97%) rename {FortranRuntime => flang}/include/flang/Runtime/freestanding-tools.h (99%) rename {FortranRuntime => flang}/include/flang/Runtime/inquiry.h (91%) rename {FortranRuntime => flang}/include/flang/Runtime/io-api.h (98%) rename {FortranRuntime => flang}/include/flang/Runtime/iostat.h (96%) rename {FortranRuntime/include/flang/Common => flang/include/flang/Runtime}/magic-numbers.h (98%) rename {FortranRuntime => flang}/include/flang/Runtime/main.h (95%) rename {FortranRuntime => flang}/include/flang/Runtime/matmul-instances.inc (100%) rename {FortranRuntime => flang}/include/flang/Runtime/matmul-transpose.h (97%) rename {FortranRuntime => flang}/include/flang/Runtime/matmul.h (97%) rename {FortranRuntime => flang}/include/flang/Runtime/misc-intrinsic.h (95%) rename {FortranRuntime => flang}/include/flang/Runtime/numeric.h (99%) rename {FortranRuntime => flang}/include/flang/Runtime/pointer.h (97%) rename {FortranRuntime => flang}/include/flang/Runtime/ragged.h (96%) rename {FortranRuntime => flang}/include/flang/Runtime/random.h (100%) rename {FortranRuntime => flang}/include/flang/Runtime/reduce.h (99%) rename {FortranRuntime => flang}/include/flang/Runtime/reduction.h (99%) rename {FortranRuntime => flang}/include/flang/Runtime/stop.h (97%) rename {FortranRuntime => flang}/include/flang/Runtime/support.h (97%) rename {FortranRuntime => flang}/include/flang/Runtime/temporary-stack.h (98%) rename {FortranRuntime => flang}/include/flang/Runtime/time-intrinsic.h (97%) rename {FortranRuntime => flang}/include/flang/Runtime/transformational.h (99%) create mode 100644 flang/include/flang/Testing/README.md rename {FortranRuntime => flang}/include/flang/Testing/fp-testing.h (100%) rename {FortranRuntime => flang}/include/flang/Testing/testing.h (100%) create mode 100644 flang/lib/Common/README.md rename {FortranRuntime => flang}/lib/Common/big-radix-floating-point.h (100%) rename {FortranRuntime => flang}/lib/Common/binary-to-decimal.cpp (100%) rename {FortranRuntime => flang}/lib/Common/decimal-to-binary.cpp (100%) create mode 100644 flang/lib/Testing/README.md rename {FortranRuntime => flang}/lib/Testing/fp-testing.cpp (100%) rename {FortranRuntime => flang}/lib/Testing/testing.cpp (100%) rename {FortranRuntime/lib/Runtime => flang/module}/iso_fortran_env_impl.f90 (98%) create mode 100644 flang/unittests/Common/CMakeLists.txt rename {FortranRuntime => flang}/unittests/Common/FastIntSetTest.cpp (97%) create mode 100644 flang/unittests/Decimal/CMakeLists.txt rename {FortranRuntime => flang}/unittests/Decimal/quick-sanity-test.cpp (92%) rename {FortranRuntime => flang}/unittests/Decimal/thorough-test.cpp (86%) diff --git a/FortranRuntime/include/flang/Runtime/allocator-registry.h b/FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h similarity index 82% rename from FortranRuntime/include/flang/Runtime/allocator-registry.h rename to FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h index 4e7d9bcedfb375..30a583b88c083e 100644 --- a/FortranRuntime/include/flang/Runtime/allocator-registry.h +++ b/FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/allocator-registry.h --------------*- C++ -*-===// +//===-- include/FortranRuntime/Runtime/allocator-registry.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. @@ -10,17 +10,10 @@ #define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_ #include "flang/Common/api-attrs.h" +#include "flang/Runtime/allocator-registry-consts.h" #include #include -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; - #define MAX_ALLOCATOR 7 // 3 bits are reserved in the descriptor. namespace Fortran::runtime { diff --git a/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h b/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h new file mode 100644 index 00000000000000..314d5e56599cd3 --- /dev/null +++ b/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h @@ -0,0 +1,48 @@ +//===-- include/FortranRuntime/Runtime/array-constructor.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_H_ +#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_ + +#include "FortranRuntime/Runtime/descriptor.h" +#include "flang/Runtime/array-constructor-consts.h" +#include "flang/Runtime/entry-names.h" +#include + +namespace Fortran::runtime { + +// Runtime data structure to hold information about the storage of +// an array constructor being constructed. +struct ArrayConstructorVector { + RT_API_ATTRS ArrayConstructorVector(class Descriptor &to, + SubscriptValue nextValuePosition, SubscriptValue actualAllocationSize, + const char *sourceFile, int sourceLine, bool useValueLengthParameters) + : to{to}, nextValuePosition{nextValuePosition}, + actualAllocationSize{actualAllocationSize}, sourceFile{sourceFile}, + sourceLine{sourceLine}, + useValueLengthParameters_{useValueLengthParameters} {} + + RT_API_ATTRS bool useValueLengthParameters() const { + return useValueLengthParameters_; + } + + class Descriptor &to; + SubscriptValue nextValuePosition; + SubscriptValue actualAllocationSize; + const char *sourceFile; + int sourceLine; + +private: + unsigned char useValueLengthParameters_ : 1; +}; + +} // namespace Fortran::runtime +#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_ */ diff --git a/FortranRuntime/include/flang/Runtime/descriptor.h b/FortranRuntime/include/FortranRuntime/Runtime/descriptor.h similarity index 96% rename from FortranRuntime/include/flang/Runtime/descriptor.h rename to FortranRuntime/include/FortranRuntime/Runtime/descriptor.h index 867f4d4ee29ac0..f79ad6b9637a4a 100644 --- a/FortranRuntime/include/flang/Runtime/descriptor.h +++ b/FortranRuntime/include/FortranRuntime/Runtime/descriptor.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/descriptor.h ----------------------*- C++ -*-===// +//===-- include/FortranRuntime/Runtime/descriptor.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. @@ -18,9 +18,10 @@ // User C code is welcome to depend on that ISO_Fortran_binding.h file, // but should never reference this internal header. +#include "FortranRuntime/Runtime/memory.h" +#include "FortranRuntime/Runtime/type-code.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" -#include "flang/Runtime/memory.h" -#include "flang/Runtime/type-code.h" +#include "flang/Runtime/descriptor-consts.h" #include #include #include @@ -28,14 +29,8 @@ #include #include -namespace Fortran::runtime::typeInfo { -using TypeParameterValue = std::int64_t; -class DerivedType; -} // namespace Fortran::runtime::typeInfo - namespace Fortran::runtime { -using SubscriptValue = ISO::CFI_index_t; class Terminator; RT_VAR_GROUP_BEGIN @@ -420,13 +415,6 @@ class Descriptor { void Dump(FILE * = stdout) const; -// 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 - RT_API_ATTRS inline bool HasAddendum() const { return raw_.extra & _CFI_ADDENDUM_FLAG; } @@ -464,6 +452,8 @@ class alignas(Descriptor) StaticDescriptor { static constexpr bool hasAddendum{ADDENDUM || MAX_LEN_PARMS > 0}; static constexpr std::size_t byteSize{ Descriptor::SizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)}; + static_assert(byteSize <= + MaxDescriptorSizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)); RT_OFFLOAD_VAR_GROUP_END RT_API_ATTRS Descriptor &descriptor() { diff --git a/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h b/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h new file mode 100644 index 00000000000000..516fe25784656c --- /dev/null +++ b/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h @@ -0,0 +1,39 @@ +//===-- include/FortranRuntime/Runtime/io-api-funcs.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 API between compiled code and I/O runtime library. + +#ifndef FORTRAN_RUNTIME_IO_API_FUNCS_H_ +#define FORTRAN_RUNTIME_IO_API_FUNCS_H_ + +#include "flang/Common/uint128.h" +#include "flang/Runtime/entry-names.h" +#include "flang/Runtime/io-api.h" +#include "flang/Runtime/iostat.h" +#include "flang/Runtime/magic-numbers.h" +#include +#include + +namespace Fortran::runtime { +class Descriptor; +} // namespace Fortran::runtime + +namespace Fortran::runtime::io { + +struct NonTbpDefinedIoTable; +class NamelistGroup; +class IoStatementState; +using Cookie = IoStatementState *; +using ExternalUnit = int; +using AsynchronousId = int; + +RT_API_ATTRS const char *InquiryKeywordHashDecode( + char *buffer, std::size_t, InquiryKeywordHash); + +} // namespace Fortran::runtime::io +#endif /* FORTRAN_RUNTIME_IO_API_FUNCS_H_ */ diff --git a/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h b/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h new file mode 100644 index 00000000000000..10906afb01673c --- /dev/null +++ b/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h @@ -0,0 +1,23 @@ +//===-- include/FortranRuntime/Runtime/iostat-funcs.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 values returned by the runtime for IOSTAT= specifiers +// on I/O statements. + +#ifndef FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ +#define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ + +#include "flang/Common/api-attrs.h" +#include "flang/Runtime/iostat.h" + +namespace Fortran::runtime::io { + +RT_API_ATTRS const char *IostatErrorString(int); + +} // namespace Fortran::runtime::io +#endif /* FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ */ diff --git a/FortranRuntime/include/flang/Runtime/memory.h b/FortranRuntime/include/FortranRuntime/Runtime/memory.h similarity index 98% rename from FortranRuntime/include/flang/Runtime/memory.h rename to FortranRuntime/include/FortranRuntime/Runtime/memory.h index 84af4d7189c074..3e7fd2d9ea3e3b 100644 --- a/FortranRuntime/include/flang/Runtime/memory.h +++ b/FortranRuntime/include/FortranRuntime/Runtime/memory.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/memory.h --------------------------*- C++ -*-===// +//===-- include/FortranRuntime/Runtime/memory.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. diff --git a/FortranRuntime/include/flang/Runtime/type-code.h b/FortranRuntime/include/FortranRuntime/Runtime/type-code.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/type-code.h rename to FortranRuntime/include/FortranRuntime/Runtime/type-code.h index ec359f25dbdd12..92ff593410c12c 100644 --- a/FortranRuntime/include/flang/Runtime/type-code.h +++ b/FortranRuntime/include/FortranRuntime/Runtime/type-code.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/type-code.h -----------------------*- C++ -*-===// +//===-- include/FortranRuntime/Runtime/type-code.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. diff --git a/FortranRuntime/include/flang/Runtime/array-constructor.h b/FortranRuntime/include/flang/Runtime/array-constructor.h deleted file mode 100644 index 82367756f5dc79..00000000000000 --- a/FortranRuntime/include/flang/Runtime/array-constructor.h +++ /dev/null @@ -1,118 +0,0 @@ -//===-- include/flang/Runtime/array-constructor.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_H_ -#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_ - -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/entry-names.h" -#include - -namespace Fortran::runtime { - -// Runtime data structure to hold information about the storage of -// an array constructor being constructed. -struct ArrayConstructorVector { - RT_API_ATTRS ArrayConstructorVector(class Descriptor &to, - SubscriptValue nextValuePosition, SubscriptValue actualAllocationSize, - const char *sourceFile, int sourceLine, bool useValueLengthParameters) - : to{to}, nextValuePosition{nextValuePosition}, - actualAllocationSize{actualAllocationSize}, sourceFile{sourceFile}, - sourceLine{sourceLine}, - useValueLengthParameters_{useValueLengthParameters} {} - - RT_API_ATTRS bool useValueLengthParameters() const { - return useValueLengthParameters_; - } - - class Descriptor &to; - SubscriptValue nextValuePosition; - SubscriptValue actualAllocationSize; - const char *sourceFile; - int sourceLine; - -private: - unsigned char useValueLengthParameters_ : 1; -}; - -// This file defines an API to "push" an evaluated array constructor value -// "from" into some storage "to" of an array constructor. It can be seen as a -// form of std::vector::push_back() implementation for Fortran array -// constructors. In the APIs and ArrayConstructorVector struct above: -// -// - "to" is a ranked-1 descriptor whose declared type is already set to the -// array constructor derived type. It may be already allocated, even before the -// first call to this API, or it may be unallocated. "to" extent is increased -// every time a "from" is pushed past its current extent. At this end of the -// API calls, its extent is the extent of the array constructor. If "to" is -// unallocated and its extent is not null, it is assumed this is the final array -// constructor extent value, and the first allocation already "reserves" storage -// space accordingly to avoid reallocations. -// - "from" is a scalar or array descriptor for the evaluated array -// constructor value that must be copied into the storage of "to" at -// "nextValuePosition". -// - "useValueLengthParameters" must be set to true if the array constructor -// has length parameters and no type spec. If it is true and "to" is -// unallocated, "to" will take the length parameters of "from". If it is true -// and "to" is an allocated character array constructor, it will be checked -// that "from" length matches the one from "to". When it is false, the -// character length must already be set in "to" before the first call to this -// API and "from" character lengths are allowed to mismatch from "to". -// - "nextValuePosition" is the zero based sequence position of "from" in the -// array constructor. It is updated after this call by the number of "from" -// elements. It should be set to zero by the caller of this API before the first -// call. -// - "actualAllocationSize" is the current allocation size of "to" storage. It -// may be bigger than "to" extent for reallocation optimization purposes, but -// should never be smaller, unless this is the first call and "to" is -// unallocated. It is updated by the runtime after each successful allocation or -// reallocation. It should be set to "to" extent if "to" is allocated before the -// first call of this API, and can be left undefined otherwise. -// -// Note that this API can be used with "to" being a variable (that can be -// discontiguous). This can be done when the variable is the left hand side of -// an assignment from an array constructor as long as: -// - none of the ac-value overlaps with the variable, -// - this is an intrinsic assignment that is not a whole allocatable -// assignment, *and* for a type that has no components requiring user defined -// assignments, -// - the variable is properly finalized before using this API if its need to, -// - "useValueLengthParameters" should be set to false in this case, even if -// the array constructor has no type-spec, since the variable may have a -// different character length than the array constructor values. - -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_H_ */ diff --git a/FortranRuntime/lib/Runtime/CMakeLists.txt b/FortranRuntime/lib/Runtime/CMakeLists.txt index d09112ab8b0d5f..b7f32fe30e422a 100644 --- a/FortranRuntime/lib/Runtime/CMakeLists.txt +++ b/FortranRuntime/lib/Runtime/CMakeLists.txt @@ -45,8 +45,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) # The out of tree builds of the compiler and the Fortran runtime # must use the same setting of FLANG_RUNTIME_F128_MATH_LIB @@ -60,6 +59,8 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ) endif() +include_directories(BEFORE ../../include) + include(CheckCXXSymbolExists) include(CheckCXXSourceCompiles) check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R) diff --git a/FortranRuntime/lib/Runtime/CUDA/allocator.cpp b/FortranRuntime/lib/Runtime/CUDA/allocator.cpp index 2efd6bf0a95249..c9d62f6ea8f3bf 100644 --- a/FortranRuntime/lib/Runtime/CUDA/allocator.cpp +++ b/FortranRuntime/lib/Runtime/CUDA/allocator.cpp @@ -6,13 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/CUDA/allocator.h" +#include "FortranRuntime/Runtime/CUDA/allocator.h" +#include "FortranRuntime/Runtime/allocator-registry.h" #include "../derived.h" #include "../stat.h" #include "../terminator.h" #include "../type-info.h" #include "flang/ISO_Fortran_binding_wrapper.h" -#include "flang/Runtime/allocator-registry.h" #include "flang/Support/Fortran.h" #include "cuda_runtime.h" diff --git a/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp b/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp index 9664fea4ebc78a..94b5feca4ce4dc 100644 --- a/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp +++ b/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/CUDA/descriptor.h" -#include "flang/Runtime/CUDA/allocator.h" +#include "FortranRuntime/Runtime/CUDA/descriptor.h" +#include "FortranRuntime/Runtime/CUDA/allocator.h" namespace Fortran::runtime::cuda { extern "C" { diff --git a/FortranRuntime/lib/Runtime/Float128Math/math-entries.h b/FortranRuntime/lib/Runtime/Float128Math/math-entries.h index cb1e0130602260..1449000820f00e 100644 --- a/FortranRuntime/lib/Runtime/Float128Math/math-entries.h +++ b/FortranRuntime/lib/Runtime/Float128Math/math-entries.h @@ -8,10 +8,10 @@ #ifndef FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_ #define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_ -#include "flang/Common/float128.h" -#include "flang/Runtime/entry-names.h" #include "terminator.h" #include "tools.h" +#include "flang/Common/float128.h" +#include "flang/Runtime/entry-names.h" #include #include #include diff --git a/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp b/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp index 9711b2bcf49757..997226b08e96a6 100644 --- a/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp +++ b/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp @@ -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 namespace Fortran::ISO { diff --git a/FortranRuntime/lib/Runtime/ISO_Fortran_util.h b/FortranRuntime/lib/Runtime/ISO_Fortran_util.h index 7ab280733028af..e418266dddccc7 100644 --- a/FortranRuntime/lib/Runtime/ISO_Fortran_util.h +++ b/FortranRuntime/lib/Runtime/ISO_Fortran_util.h @@ -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 namespace Fortran::ISO { diff --git a/FortranRuntime/lib/Runtime/allocatable.cpp b/FortranRuntime/lib/Runtime/allocatable.cpp index 8b6c1a4c1477eb..4a3b89f4879c12 100644 --- a/FortranRuntime/lib/Runtime/allocatable.cpp +++ b/FortranRuntime/lib/Runtime/allocatable.cpp @@ -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" { diff --git a/FortranRuntime/lib/Runtime/allocator-registry.cpp b/FortranRuntime/lib/Runtime/allocator-registry.cpp index 68fb8b80680558..17883e5c54870d 100644 --- a/FortranRuntime/lib/Runtime/allocator-registry.cpp +++ b/FortranRuntime/lib/Runtime/allocator-registry.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/allocator-registry.h" +#include "FortranRuntime/Runtime/allocator-registry.h" #include "terminator.h" namespace Fortran::runtime { diff --git a/FortranRuntime/lib/Runtime/array-constructor.cpp b/FortranRuntime/lib/Runtime/array-constructor.cpp index db57d4fc4c3f68..002dfba2c066f5 100644 --- a/FortranRuntime/lib/Runtime/array-constructor.cpp +++ b/FortranRuntime/lib/Runtime/array-constructor.cpp @@ -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 { diff --git a/FortranRuntime/lib/Runtime/assign.cpp b/FortranRuntime/lib/Runtime/assign.cpp index cc38e55e3a9e1e..3a1486ace928a2 100644 --- a/FortranRuntime/lib/Runtime/assign.cpp +++ b/FortranRuntime/lib/Runtime/assign.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/buffer.h b/FortranRuntime/lib/Runtime/buffer.h index dd3c19fa14392f..52df0f10813c25 100644 --- a/FortranRuntime/lib/Runtime/buffer.h +++ b/FortranRuntime/lib/Runtime/buffer.h @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/character.cpp b/FortranRuntime/lib/Runtime/character.cpp index 32fc010c6c04dd..1f3edd6e80392e 100644 --- a/FortranRuntime/lib/Runtime/character.cpp +++ b/FortranRuntime/lib/Runtime/character.cpp @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/command.cpp b/FortranRuntime/lib/Runtime/command.cpp index dc57758d4f7955..3fc941ab2ef861 100644 --- a/FortranRuntime/lib/Runtime/command.cpp +++ b/FortranRuntime/lib/Runtime/command.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/connection.h b/FortranRuntime/lib/Runtime/connection.h index 92a3a9c3860a3e..e078bfb9f0f7e7 100644 --- a/FortranRuntime/lib/Runtime/connection.h +++ b/FortranRuntime/lib/Runtime/connection.h @@ -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 namespace Fortran::runtime::io { diff --git a/FortranRuntime/lib/Runtime/copy.cpp b/FortranRuntime/lib/Runtime/copy.cpp index 39c7da45172a43..1049b925f68e5c 100644 --- a/FortranRuntime/lib/Runtime/copy.cpp +++ b/FortranRuntime/lib/Runtime/copy.cpp @@ -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 namespace Fortran::runtime { diff --git a/FortranRuntime/lib/Runtime/copy.h b/FortranRuntime/lib/Runtime/copy.h index f2c5b41718b71c..3d179d0bec91a7 100644 --- a/FortranRuntime/lib/Runtime/copy.h +++ b/FortranRuntime/lib/Runtime/copy.h @@ -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 { diff --git a/FortranRuntime/lib/Runtime/derived-api.cpp b/FortranRuntime/lib/Runtime/derived-api.cpp index 4b68cdbbed7b2c..176fc0849f25cf 100644 --- a/FortranRuntime/lib/Runtime/derived-api.cpp +++ b/FortranRuntime/lib/Runtime/derived-api.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/derived.cpp b/FortranRuntime/lib/Runtime/derived.cpp index 52bf54d62c8599..cb2dca24bb4758 100644 --- a/FortranRuntime/lib/Runtime/derived.cpp +++ b/FortranRuntime/lib/Runtime/derived.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/descriptor-io.h b/FortranRuntime/lib/Runtime/descriptor-io.h index 2ccad0cea70a29..30d1bd48457728 100644 --- a/FortranRuntime/lib/Runtime/descriptor-io.h +++ b/FortranRuntime/lib/Runtime/descriptor-io.h @@ -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 diff --git a/FortranRuntime/lib/Runtime/descriptor.cpp b/FortranRuntime/lib/Runtime/descriptor.cpp index 6756134b06e7b1..96fd48eb6687a9 100644 --- a/FortranRuntime/lib/Runtime/descriptor.cpp +++ b/FortranRuntime/lib/Runtime/descriptor.cpp @@ -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" @@ -141,8 +141,10 @@ RT_API_ATTRS OwningPtr 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 { diff --git a/FortranRuntime/lib/Runtime/dot-product.cpp b/FortranRuntime/lib/Runtime/dot-product.cpp index ab1cfa58ef3d02..2992cbb1f39ad6 100644 --- a/FortranRuntime/lib/Runtime/dot-product.cpp +++ b/FortranRuntime/lib/Runtime/dot-product.cpp @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/edit-input.cpp b/FortranRuntime/lib/Runtime/edit-input.cpp index eaa9d0d7e641e7..6ebb0e7aca4ade 100644 --- a/FortranRuntime/lib/Runtime/edit-input.cpp +++ b/FortranRuntime/lib/Runtime/edit-input.cpp @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/edit-input.h b/FortranRuntime/lib/Runtime/edit-input.h index 2eda81a6d4e11d..f88f6daa47be79 100644 --- a/FortranRuntime/lib/Runtime/edit-input.h +++ b/FortranRuntime/lib/Runtime/edit-input.h @@ -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 { diff --git a/FortranRuntime/lib/Runtime/edit-output.cpp b/FortranRuntime/lib/Runtime/edit-output.cpp index 1fab7db6d3b187..ccaf8085f016fd 100644 --- a/FortranRuntime/lib/Runtime/edit-output.cpp +++ b/FortranRuntime/lib/Runtime/edit-output.cpp @@ -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 namespace Fortran::runtime::io { diff --git a/FortranRuntime/lib/Runtime/edit-output.h b/FortranRuntime/lib/Runtime/edit-output.h index cb25b68a35f05b..7e6c6cdedde3ac 100644 --- a/FortranRuntime/lib/Runtime/edit-output.h +++ b/FortranRuntime/lib/Runtime/edit-output.h @@ -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 { diff --git a/FortranRuntime/lib/Runtime/execute.cpp b/FortranRuntime/lib/Runtime/execute.cpp index 54f28d052873b4..b333c61c8a59f4 100644 --- a/FortranRuntime/lib/Runtime/execute.cpp +++ b/FortranRuntime/lib/Runtime/execute.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/extensions.cpp b/FortranRuntime/lib/Runtime/extensions.cpp index 94bfa3059e6b45..bb25fe6ee9d886 100644 --- a/FortranRuntime/lib/Runtime/extensions.cpp +++ b/FortranRuntime/lib/Runtime/extensions.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/extrema.cpp b/FortranRuntime/lib/Runtime/extrema.cpp index 0809cb1d5f2ae2..be9da63d7bd6b8 100644 --- a/FortranRuntime/lib/Runtime/extrema.cpp +++ b/FortranRuntime/lib/Runtime/extrema.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/file.cpp b/FortranRuntime/lib/Runtime/file.cpp index 80829d844881e8..de52dafd12df9a 100644 --- a/FortranRuntime/lib/Runtime/file.cpp +++ b/FortranRuntime/lib/Runtime/file.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/file.h b/FortranRuntime/lib/Runtime/file.h index 66d62756634b24..60ddf2a2741610 100644 --- a/FortranRuntime/lib/Runtime/file.h +++ b/FortranRuntime/lib/Runtime/file.h @@ -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 namespace Fortran::runtime::io { diff --git a/FortranRuntime/lib/Runtime/findloc.cpp b/FortranRuntime/lib/Runtime/findloc.cpp index 47c51fbcef4939..da5fe0c0a0a467 100644 --- a/FortranRuntime/lib/Runtime/findloc.cpp +++ b/FortranRuntime/lib/Runtime/findloc.cpp @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/format-implementation.h b/FortranRuntime/lib/Runtime/format-implementation.h index 8d0d0f3376eafc..f17f0a2cb4bfd9 100644 --- a/FortranRuntime/lib/Runtime/format-implementation.h +++ b/FortranRuntime/lib/Runtime/format-implementation.h @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/format.h b/FortranRuntime/lib/Runtime/format.h index 3e0807ee452a7e..098a251a04d568 100644 --- a/FortranRuntime/lib/Runtime/format.h +++ b/FortranRuntime/lib/Runtime/format.h @@ -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 namespace Fortran::runtime { diff --git a/FortranRuntime/lib/Runtime/inquiry.cpp b/FortranRuntime/lib/Runtime/inquiry.cpp index 172b46037d6c4b..c24492754b4f43 100644 --- a/FortranRuntime/lib/Runtime/inquiry.cpp +++ b/FortranRuntime/lib/Runtime/inquiry.cpp @@ -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 diff --git a/FortranRuntime/lib/Runtime/internal-unit.cpp b/FortranRuntime/lib/Runtime/internal-unit.cpp index 81b937ba63d4b8..4494de9dddc1a1 100644 --- a/FortranRuntime/lib/Runtime/internal-unit.cpp +++ b/FortranRuntime/lib/Runtime/internal-unit.cpp @@ -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 #include @@ -36,6 +36,8 @@ RT_API_ATTRS InternalDescriptorUnit::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; diff --git a/FortranRuntime/lib/Runtime/internal-unit.h b/FortranRuntime/lib/Runtime/internal-unit.h index c4107696810f2b..7579016f14646d 100644 --- a/FortranRuntime/lib/Runtime/internal-unit.h +++ b/FortranRuntime/lib/Runtime/internal-unit.h @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/io-api-common.h b/FortranRuntime/lib/Runtime/io-api-common.h index 427666723501a2..fed1d11d6ce6a6 100644 --- a/FortranRuntime/lib/Runtime/io-api-common.h +++ b/FortranRuntime/lib/Runtime/io-api-common.h @@ -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 { diff --git a/FortranRuntime/lib/Runtime/io-api-minimal.cpp b/FortranRuntime/lib/Runtime/io-api-minimal.cpp index 683694bd63c068..8cde2333804572 100644 --- a/FortranRuntime/lib/Runtime/io-api-minimal.cpp +++ b/FortranRuntime/lib/Runtime/io-api-minimal.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/io-api.cpp b/FortranRuntime/lib/Runtime/io-api.cpp index 102ea26b359111..fa95d68a004b51 100644 --- a/FortranRuntime/lib/Runtime/io-api.cpp +++ b/FortranRuntime/lib/Runtime/io-api.cpp @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/io-error.cpp b/FortranRuntime/lib/Runtime/io-error.cpp index 400b211c1c418e..053667462058de 100644 --- a/FortranRuntime/lib/Runtime/io-error.cpp +++ b/FortranRuntime/lib/Runtime/io-error.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/io-error.h b/FortranRuntime/lib/Runtime/io-error.h index 7388a2134ed0d3..e2018cc2ea0ab1 100644 --- a/FortranRuntime/lib/Runtime/io-error.h +++ b/FortranRuntime/lib/Runtime/io-error.h @@ -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 diff --git a/FortranRuntime/lib/Runtime/io-stmt.cpp b/FortranRuntime/lib/Runtime/io-stmt.cpp index 5be5d98ace0d8a..fe02e221671665 100644 --- a/FortranRuntime/lib/Runtime/io-stmt.cpp +++ b/FortranRuntime/lib/Runtime/io-stmt.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/io-stmt.h b/FortranRuntime/lib/Runtime/io-stmt.h index 79a8b28c8aa19f..21746ff1966218 100644 --- a/FortranRuntime/lib/Runtime/io-stmt.h +++ b/FortranRuntime/lib/Runtime/io-stmt.h @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/iostat.cpp b/FortranRuntime/lib/Runtime/iostat.cpp index f23567be4910da..8d769a09252fd6 100644 --- a/FortranRuntime/lib/Runtime/iostat.cpp +++ b/FortranRuntime/lib/Runtime/iostat.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/iostat.h" +#include "FortranRuntime/Runtime/iostat-funcs.h" namespace Fortran::runtime::io { RT_OFFLOAD_API_GROUP_BEGIN diff --git a/FortranRuntime/lib/Runtime/matmul-transpose.cpp b/FortranRuntime/lib/Runtime/matmul-transpose.cpp index 3b4b487daa335e..ec5388e3fca793 100644 --- a/FortranRuntime/lib/Runtime/matmul-transpose.cpp +++ b/FortranRuntime/lib/Runtime/matmul-transpose.cpp @@ -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 namespace { diff --git a/FortranRuntime/lib/Runtime/matmul.cpp b/FortranRuntime/lib/Runtime/matmul.cpp index 62674316bc6a57..01be7f7c75bc45 100644 --- a/FortranRuntime/lib/Runtime/matmul.cpp +++ b/FortranRuntime/lib/Runtime/matmul.cpp @@ -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 namespace { diff --git a/FortranRuntime/lib/Runtime/memory.cpp b/FortranRuntime/lib/Runtime/memory.cpp index bf2c4cd4a35470..a4cebf7edc6c64 100644 --- a/FortranRuntime/lib/Runtime/memory.cpp +++ b/FortranRuntime/lib/Runtime/memory.cpp @@ -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 namespace Fortran::runtime { diff --git a/FortranRuntime/lib/Runtime/misc-intrinsic.cpp b/FortranRuntime/lib/Runtime/misc-intrinsic.cpp index a0f41e4e3f156c..91a3b136e009a5 100644 --- a/FortranRuntime/lib/Runtime/misc-intrinsic.cpp +++ b/FortranRuntime/lib/Runtime/misc-intrinsic.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/namelist.cpp b/FortranRuntime/lib/Runtime/namelist.cpp index 1c8942fc375c43..46036549bcd316 100644 --- a/FortranRuntime/lib/Runtime/namelist.cpp +++ b/FortranRuntime/lib/Runtime/namelist.cpp @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/namelist.h b/FortranRuntime/lib/Runtime/namelist.h index 2c4d331ae05e85..04432f8a08cb97 100644 --- a/FortranRuntime/lib/Runtime/namelist.h +++ b/FortranRuntime/lib/Runtime/namelist.h @@ -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 diff --git a/FortranRuntime/lib/Runtime/numeric-templates.h b/FortranRuntime/lib/Runtime/numeric-templates.h index f0045e8ee36e20..159b8b0b9579ad 100644 --- a/FortranRuntime/lib/Runtime/numeric-templates.h +++ b/FortranRuntime/lib/Runtime/numeric-templates.h @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/numeric.cpp b/FortranRuntime/lib/Runtime/numeric.cpp index a3fcfeaa9ee266..b0f68a7fc81d29 100644 --- a/FortranRuntime/lib/Runtime/numeric.cpp +++ b/FortranRuntime/lib/Runtime/numeric.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/product.cpp b/FortranRuntime/lib/Runtime/product.cpp index 8c11bf4144919e..e4a6e81bd0c508 100644 --- a/FortranRuntime/lib/Runtime/product.cpp +++ b/FortranRuntime/lib/Runtime/product.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/random-templates.h b/FortranRuntime/lib/Runtime/random-templates.h index 801484225bc211..9faa9c7cfa7002 100644 --- a/FortranRuntime/lib/Runtime/random-templates.h +++ b/FortranRuntime/lib/Runtime/random-templates.h @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/random.cpp b/FortranRuntime/lib/Runtime/random.cpp index 8e1561960d48be..911b59b508eb4f 100644 --- a/FortranRuntime/lib/Runtime/random.cpp +++ b/FortranRuntime/lib/Runtime/random.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/reduce.cpp b/FortranRuntime/lib/Runtime/reduce.cpp index 4d33c2a714e5af..a020ffef6fe6a5 100644 --- a/FortranRuntime/lib/Runtime/reduce.cpp +++ b/FortranRuntime/lib/Runtime/reduce.cpp @@ -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" diff --git a/FortranRuntime/lib/Runtime/reduction-templates.h b/FortranRuntime/lib/Runtime/reduction-templates.h index 30ae641ba7b3ac..714584ec613ba3 100644 --- a/FortranRuntime/lib/Runtime/reduction-templates.h +++ b/FortranRuntime/lib/Runtime/reduction-templates.h @@ -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 namespace Fortran::runtime { diff --git a/FortranRuntime/lib/Runtime/reduction.cpp b/FortranRuntime/lib/Runtime/reduction.cpp index f4e1f2aa6818d5..21930fee07ead7 100644 --- a/FortranRuntime/lib/Runtime/reduction.cpp +++ b/FortranRuntime/lib/Runtime/reduction.cpp @@ -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 diff --git a/FortranRuntime/lib/Runtime/stack.h b/FortranRuntime/lib/Runtime/stack.h index dc5b6101d3da0f..36e2d0a103a887 100644 --- a/FortranRuntime/lib/Runtime/stack.h +++ b/FortranRuntime/lib/Runtime/stack.h @@ -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 { diff --git a/FortranRuntime/lib/Runtime/stat.cpp b/FortranRuntime/lib/Runtime/stat.cpp index 01ae922e080865..1af6c43102518b 100644 --- a/FortranRuntime/lib/Runtime/stat.cpp +++ b/FortranRuntime/lib/Runtime/stat.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "stat.h" -#include "flang/Runtime/descriptor.h" +#include "FortranRuntime/Runtime/descriptor.h" #include "terminator.h" #include "tools.h" diff --git a/FortranRuntime/lib/Runtime/stat.h b/FortranRuntime/lib/Runtime/stat.h index a679f9da16dd46..eccd69024d726b 100644 --- a/FortranRuntime/lib/Runtime/stat.h +++ b/FortranRuntime/lib/Runtime/stat.h @@ -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; diff --git a/FortranRuntime/lib/Runtime/sum.cpp b/FortranRuntime/lib/Runtime/sum.cpp index e33b77e20f0f11..64982b9fd53690 100644 --- a/FortranRuntime/lib/Runtime/sum.cpp +++ b/FortranRuntime/lib/Runtime/sum.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/support.cpp b/FortranRuntime/lib/Runtime/support.cpp index 0a39ff24b0cafc..798d502ba248e2 100644 --- a/FortranRuntime/lib/Runtime/support.cpp +++ b/FortranRuntime/lib/Runtime/support.cpp @@ -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 { diff --git a/FortranRuntime/lib/Runtime/temporary-stack.cpp b/FortranRuntime/lib/Runtime/temporary-stack.cpp index f944dfb7aa1471..d8ff08e51cc211 100644 --- a/FortranRuntime/lib/Runtime/temporary-stack.cpp +++ b/FortranRuntime/lib/Runtime/temporary-stack.cpp @@ -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 { diff --git a/FortranRuntime/lib/Runtime/time-intrinsic.cpp b/FortranRuntime/lib/Runtime/time-intrinsic.cpp index 4b362c90c52f25..15c42077c0afd5 100644 --- a/FortranRuntime/lib/Runtime/time-intrinsic.cpp +++ b/FortranRuntime/lib/Runtime/time-intrinsic.cpp @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/tools.h b/FortranRuntime/lib/Runtime/tools.h index 4058767ca283a9..332ffac77f2595 100644 --- a/FortranRuntime/lib/Runtime/tools.h +++ b/FortranRuntime/lib/Runtime/tools.h @@ -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 #include #include diff --git a/FortranRuntime/lib/Runtime/transformational.cpp b/FortranRuntime/lib/Runtime/transformational.cpp index 66dc5bd4939bae..28dd02a28036de 100644 --- a/FortranRuntime/lib/Runtime/transformational.cpp +++ b/FortranRuntime/lib/Runtime/transformational.cpp @@ -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 { diff --git a/FortranRuntime/lib/Runtime/type-code.cpp b/FortranRuntime/lib/Runtime/type-code.cpp index 2709ca1be75a53..16f5497bc7a709 100644 --- a/FortranRuntime/lib/Runtime/type-code.cpp +++ b/FortranRuntime/lib/Runtime/type-code.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/type-code.h" +#include "FortranRuntime/Runtime/type-code.h" #include namespace Fortran::runtime { diff --git a/FortranRuntime/lib/Runtime/type-info.cpp b/FortranRuntime/lib/Runtime/type-info.cpp index 24fc9c33d92819..19e9211fc063f4 100644 --- a/FortranRuntime/lib/Runtime/type-info.cpp +++ b/FortranRuntime/lib/Runtime/type-info.cpp @@ -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; } } diff --git a/FortranRuntime/lib/Runtime/type-info.h b/FortranRuntime/lib/Runtime/type-info.h index ff3523bcb2b8eb..150942547c2ee8 100644 --- a/FortranRuntime/lib/Runtime/type-info.h +++ b/FortranRuntime/lib/Runtime/type-info.h @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/unit-map.h b/FortranRuntime/lib/Runtime/unit-map.h index 4e61246f9a2d86..f37e2df7f3b15a 100644 --- a/FortranRuntime/lib/Runtime/unit-map.h +++ b/FortranRuntime/lib/Runtime/unit-map.h @@ -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 #include diff --git a/FortranRuntime/lib/Runtime/unit.h b/FortranRuntime/lib/Runtime/unit.h index 993fbf2977cebf..4a7444aedbe5b6 100644 --- a/FortranRuntime/lib/Runtime/unit.h +++ b/FortranRuntime/lib/Runtime/unit.h @@ -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 #include #include diff --git a/FortranRuntime/unittests/Common/CMakeLists.txt b/FortranRuntime/unittests/Common/CMakeLists.txt deleted file mode 100644 index 72f2c50d14162d..00000000000000 --- a/FortranRuntime/unittests/Common/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -#===-- unittests/Common/CMakeLists.txt -------------------------------------===# -# -# 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 -# -#===------------------------------------------------------------------------===# - -add_flang_unittest(FlangCommonTests - FastIntSetTest.cpp -) diff --git a/FortranRuntime/unittests/Decimal/CMakeLists.txt b/FortranRuntime/unittests/Decimal/CMakeLists.txt deleted file mode 100644 index 40b89b48e1adeb..00000000000000 --- a/FortranRuntime/unittests/Decimal/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -#===-- unittests/Decimal/CMakeLists.txt ------------------------------------===# -# -# 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 -# -#===------------------------------------------------------------------------===# - -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 -) diff --git a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp index d2546e0c22d2d6..fd7073ca1d7db0 100644 --- a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp +++ b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp @@ -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 @@ -28,6 +28,7 @@ template class Test_CFI_CDESC_T { MATCH(false, std::is_const::value); MATCH(false, std::is_volatile::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. diff --git a/FortranRuntime/unittests/Evaluate/reshape.cpp b/FortranRuntime/unittests/Evaluate/reshape.cpp index a93afd2a3c90cd..0233ab37e25c6e 100644 --- a/FortranRuntime/unittests/Evaluate/reshape.cpp +++ b/FortranRuntime/unittests/Evaluate/reshape.cpp @@ -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 diff --git a/FortranRuntime/unittests/Runtime/AccessTest.cpp b/FortranRuntime/unittests/Runtime/AccessTest.cpp index 3e9feaf945b66d..e72386cc9ac247 100644 --- a/FortranRuntime/unittests/Runtime/AccessTest.cpp +++ b/FortranRuntime/unittests/Runtime/AccessTest.cpp @@ -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 #include diff --git a/FortranRuntime/unittests/Runtime/Allocatable.cpp b/FortranRuntime/unittests/Runtime/Allocatable.cpp index c01f85598d21ed..8e10dc408ceae8 100644 --- a/FortranRuntime/unittests/Runtime/Allocatable.cpp +++ b/FortranRuntime/unittests/Runtime/Allocatable.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/allocatable.h" -#include "tools.h" #include "gtest/gtest.h" +#include "tools.h" using namespace Fortran::runtime; diff --git a/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp b/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp index 9011da304b6bc3..9d9a4ddae8689f 100644 --- a/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp +++ b/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp @@ -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 diff --git a/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp b/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp index d2c1600af8c631..d2a2e5a11abf80 100644 --- a/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp +++ b/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp @@ -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" diff --git a/FortranRuntime/unittests/Runtime/CharacterTest.cpp b/FortranRuntime/unittests/Runtime/CharacterTest.cpp index 8829f5e43265b0..610061e2122cd5 100644 --- a/FortranRuntime/unittests/Runtime/CharacterTest.cpp +++ b/FortranRuntime/unittests/Runtime/CharacterTest.cpp @@ -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 #include diff --git a/FortranRuntime/unittests/Runtime/CommandTest.cpp b/FortranRuntime/unittests/Runtime/CommandTest.cpp index aa79ce381ba8d0..a7d68508c5abca 100644 --- a/FortranRuntime/unittests/Runtime/CommandTest.cpp +++ b/FortranRuntime/unittests/Runtime/CommandTest.cpp @@ -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 #include diff --git a/FortranRuntime/unittests/Runtime/Derived.cpp b/FortranRuntime/unittests/Runtime/Derived.cpp index 11b732fe10b790..22361352fdf5d9 100644 --- a/FortranRuntime/unittests/Runtime/Derived.cpp +++ b/FortranRuntime/unittests/Runtime/Derived.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp b/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp index 00c2fd76ce0c04..7ff4aa3c14bdc5 100644 --- a/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp +++ b/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp @@ -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 #include diff --git a/FortranRuntime/unittests/Runtime/Inquiry.cpp b/FortranRuntime/unittests/Runtime/Inquiry.cpp index 204a97a1088ac0..3e5f0037177f1c 100644 --- a/FortranRuntime/unittests/Runtime/Inquiry.cpp +++ b/FortranRuntime/unittests/Runtime/Inquiry.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/ListInputTest.cpp b/FortranRuntime/unittests/Runtime/ListInputTest.cpp index 4c30d6ed750141..e0fe4dfeac3949 100644 --- a/FortranRuntime/unittests/Runtime/ListInputTest.cpp +++ b/FortranRuntime/unittests/Runtime/ListInputTest.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp b/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp index 928fddec50c874..9fa0c2f4260edb 100644 --- a/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp +++ b/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp @@ -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 #include #include diff --git a/FortranRuntime/unittests/Runtime/Matmul.cpp b/FortranRuntime/unittests/Runtime/Matmul.cpp index cfa5d18cc36d33..6eb4012e785ff1 100644 --- a/FortranRuntime/unittests/Runtime/Matmul.cpp +++ b/FortranRuntime/unittests/Runtime/Matmul.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp b/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp index 146c2283fb1aca..199062f820c303 100644 --- a/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp +++ b/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp b/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp index 08229b5e48f0dd..1033dda9d636f7 100644 --- a/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp +++ b/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/Namelist.cpp b/FortranRuntime/unittests/Runtime/Namelist.cpp index 7b834dec49c3c4..544ab85234fd65 100644 --- a/FortranRuntime/unittests/Runtime/Namelist.cpp +++ b/FortranRuntime/unittests/Runtime/Namelist.cpp @@ -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 #include diff --git a/FortranRuntime/unittests/Runtime/Numeric.cpp b/FortranRuntime/unittests/Runtime/Numeric.cpp index fb595ae262c324..d15919b972bca7 100644 --- a/FortranRuntime/unittests/Runtime/Numeric.cpp +++ b/FortranRuntime/unittests/Runtime/Numeric.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/numeric.h" -#include "flang/Common/float128.h" #include "gtest/gtest.h" +#include "flang/Common/float128.h" #include #include diff --git a/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp b/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp index 8a1dd6de1449b9..c588c739686bed 100644 --- a/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp +++ b/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp @@ -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 #include #include diff --git a/FortranRuntime/unittests/Runtime/Pointer.cpp b/FortranRuntime/unittests/Runtime/Pointer.cpp index a05bd70a64bb9f..733cd42232875f 100644 --- a/FortranRuntime/unittests/Runtime/Pointer.cpp +++ b/FortranRuntime/unittests/Runtime/Pointer.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/Random.cpp b/FortranRuntime/unittests/Runtime/Random.cpp index 4e4b59cbcf40e7..81497a682660a8 100644 --- a/FortranRuntime/unittests/Runtime/Random.cpp +++ b/FortranRuntime/unittests/Runtime/Random.cpp @@ -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 diff --git a/FortranRuntime/unittests/Runtime/Reduction.cpp b/FortranRuntime/unittests/Runtime/Reduction.cpp index c35f6e2fa6a41b..a382f4b7a71770 100644 --- a/FortranRuntime/unittests/Runtime/Reduction.cpp +++ b/FortranRuntime/unittests/Runtime/Reduction.cpp @@ -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 #include #include diff --git a/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp b/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp index 61580a8d46792f..7ce1ee796d739b 100644 --- a/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp +++ b/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp @@ -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 using namespace Fortran::runtime; diff --git a/FortranRuntime/unittests/Runtime/Stop.cpp b/FortranRuntime/unittests/Runtime/Stop.cpp index 5fd8deaad21d6b..c12ec097068438 100644 --- a/FortranRuntime/unittests/Runtime/Stop.cpp +++ b/FortranRuntime/unittests/Runtime/Stop.cpp @@ -10,8 +10,8 @@ // //===----------------------------------------------------------------------===// #include "flang/Runtime/stop.h" -#include "../../lib/Runtime/environment.h" #include "CrashHandlerFixture.h" +#include "../../lib/Runtime/environment.h" #include #include diff --git a/FortranRuntime/unittests/Runtime/Support.cpp b/FortranRuntime/unittests/Runtime/Support.cpp index 38c0d6efaf9db7..05328e6baa411c 100644 --- a/FortranRuntime/unittests/Runtime/Support.cpp +++ b/FortranRuntime/unittests/Runtime/Support.cpp @@ -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; diff --git a/FortranRuntime/unittests/Runtime/TemporaryStack.cpp b/FortranRuntime/unittests/Runtime/TemporaryStack.cpp index 63d99416ea64cb..b0b1041f0f09e7 100644 --- a/FortranRuntime/unittests/Runtime/TemporaryStack.cpp +++ b/FortranRuntime/unittests/Runtime/TemporaryStack.cpp @@ -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 using namespace Fortran::runtime; diff --git a/FortranRuntime/unittests/Runtime/Time.cpp b/FortranRuntime/unittests/Runtime/Time.cpp index 6fd00d669a9575..548c0834e34a36 100644 --- a/FortranRuntime/unittests/Runtime/Time.cpp +++ b/FortranRuntime/unittests/Runtime/Time.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/time-intrinsic.h" #include "gtest/gtest.h" +#include "flang/Runtime/time-intrinsic.h" #include #include #include diff --git a/FortranRuntime/unittests/Runtime/Transformational.cpp b/FortranRuntime/unittests/Runtime/Transformational.cpp index b5a4e0e8e9588b..6b8903750d0aec 100644 --- a/FortranRuntime/unittests/Runtime/Transformational.cpp +++ b/FortranRuntime/unittests/Runtime/Transformational.cpp @@ -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 using namespace Fortran::runtime; diff --git a/FortranRuntime/unittests/Runtime/tools.h b/FortranRuntime/unittests/Runtime/tools.h index 702103d225ab72..8000d83fc0c394 100644 --- a/FortranRuntime/unittests/Runtime/tools.h +++ b/FortranRuntime/unittests/Runtime/tools.h @@ -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 #include #include diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 009eed8a085a9a..733a2ba1ed7ccc 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -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 diff --git a/FortranRuntime/include/flang/Common/Fortran-consts.h b/flang/include/flang/Common/Fortran-consts.h similarity index 100% rename from FortranRuntime/include/flang/Common/Fortran-consts.h rename to flang/include/flang/Common/Fortran-consts.h diff --git a/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h similarity index 97% rename from FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h rename to flang/include/flang/Common/ISO_Fortran_binding_wrapper.h index 2c0fdc123c8759..ccfc360dfc820c 100644 --- a/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h +++ b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h @@ -22,7 +22,7 @@ /* clang-format off */ #include -#include "flang/Common/api-attrs.h" +#include "flang/Common/api-attrs.h" #ifdef __cplusplus namespace Fortran { namespace ISO { diff --git a/flang/include/flang/Common/README.md b/flang/include/flang/Common/README.md new file mode 100644 index 00000000000000..a722732fb76407 --- /dev/null +++ b/flang/include/flang/Common/README.md @@ -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`; `fortran::common::optional` 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 ` can help to support C++ and C. + + * Global declarations may need to be annotated using definitions from + `api-attrs.h`. diff --git a/FortranRuntime/include/flang/Common/api-attrs.h b/flang/include/flang/Common/api-attrs.h similarity index 97% rename from FortranRuntime/include/flang/Common/api-attrs.h rename to flang/include/flang/Common/api-attrs.h index 9a3001fb255c11..d73e60996bc81f 100644 --- a/FortranRuntime/include/flang/Common/api-attrs.h +++ b/flang/include/flang/Common/api-attrs.h @@ -1,10 +1,11 @@ -/*===-- 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 @@ -12,8 +13,8 @@ * 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 @@ -177,4 +178,4 @@ #define RT_DEVICE_NOINLINE_HOST_INLINE inline #endif -#endif /* FORTRAN_COMMON_API_ATTRS_H_ */ +#endif /* !FORTRAN_RUNTIME_API_ATTRS_H_ */ diff --git a/FortranRuntime/include/flang/Common/binary-floating-point.h b/flang/include/flang/Common/binary-floating-point.h similarity index 100% rename from FortranRuntime/include/flang/Common/binary-floating-point.h rename to flang/include/flang/Common/binary-floating-point.h diff --git a/FortranRuntime/include/flang/Common/bit-population-count.h b/flang/include/flang/Common/bit-population-count.h similarity index 98% rename from FortranRuntime/include/flang/Common/bit-population-count.h rename to flang/include/flang/Common/bit-population-count.h index 59ade914d14d85..e1aeb78f9a3765 100644 --- a/FortranRuntime/include/flang/Common/bit-population-count.h +++ b/flang/include/flang/Common/bit-population-count.h @@ -93,4 +93,4 @@ template inline constexpr int TrailingZeroBitCount(INT x) { } } } // namespace Fortran::common -#endif /* FORTRAN_COMMON_BIT_POPULATION_COUNT_H_ */ +#endif // FORTRAN_COMMON_BIT_POPULATION_COUNT_H_ diff --git a/FortranRuntime/include/flang/Common/constexpr-bitset.h b/flang/include/flang/Common/constexpr-bitset.h similarity index 98% rename from FortranRuntime/include/flang/Common/constexpr-bitset.h rename to flang/include/flang/Common/constexpr-bitset.h index 093b247b5f4eff..1aafb6eff84c61 100644 --- a/FortranRuntime/include/flang/Common/constexpr-bitset.h +++ b/flang/include/flang/Common/constexpr-bitset.h @@ -144,4 +144,4 @@ template class BitSet { Word bits_{0}; }; } // namespace Fortran::common -#endif /* FORTRAN_COMMON_CONSTEXPR_BITSET_H_ */ +#endif // FORTRAN_COMMON_CONSTEXPR_BITSET_H_ diff --git a/FortranRuntime/include/flang/Common/decimal.h b/flang/include/flang/Common/decimal.h similarity index 100% rename from FortranRuntime/include/flang/Common/decimal.h rename to flang/include/flang/Common/decimal.h diff --git a/FortranRuntime/include/flang/Common/enum-class.h b/flang/include/flang/Common/enum-class.h similarity index 98% rename from FortranRuntime/include/flang/Common/enum-class.h rename to flang/include/flang/Common/enum-class.h index 787648ffec48e8..41575d45091a8d 100644 --- a/FortranRuntime/include/flang/Common/enum-class.h +++ b/flang/include/flang/Common/enum-class.h @@ -69,4 +69,4 @@ constexpr std::array EnumNames(const char *p) { } } // namespace Fortran::common -#endif /* FORTRAN_COMMON_ENUM_CLASS_H_ */ +#endif // FORTRAN_COMMON_ENUM_CLASS_H_ diff --git a/FortranRuntime/include/flang/Common/enum-set.h b/flang/include/flang/Common/enum-set.h similarity index 99% rename from FortranRuntime/include/flang/Common/enum-set.h rename to flang/include/flang/Common/enum-set.h index 6100fc5e2e31c5..5290b76debee88 100644 --- a/FortranRuntime/include/flang/Common/enum-set.h +++ b/flang/include/flang/Common/enum-set.h @@ -228,4 +228,4 @@ struct std::hash> { return std::hash(x.bitset()); } }; -#endif /* FORTRAN_COMMON_ENUM_SET_H_ */ +#endif // FORTRAN_COMMON_ENUM_SET_H_ diff --git a/FortranRuntime/include/flang/Common/fast-int-set.h b/flang/include/flang/Common/fast-int-set.h similarity index 97% rename from FortranRuntime/include/flang/Common/fast-int-set.h rename to flang/include/flang/Common/fast-int-set.h index 323ee4dc7e94d9..d1c9c756a44a65 100644 --- a/FortranRuntime/include/flang/Common/fast-int-set.h +++ b/flang/include/flang/Common/fast-int-set.h @@ -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. @@ -103,4 +103,4 @@ template 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_ diff --git a/FortranRuntime/include/flang/Common/float128.h b/flang/include/flang/Common/float128.h similarity index 96% rename from FortranRuntime/include/flang/Common/float128.h rename to flang/include/flang/Common/float128.h index a7036bf679e5ae..2e76bc0a162e61 100644 --- a/FortranRuntime/include/flang/Common/float128.h +++ b/flang/include/flang/Common/float128.h @@ -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. diff --git a/FortranRuntime/include/flang/Common/format.h b/flang/include/flang/Common/format.h similarity index 99% rename from FortranRuntime/include/flang/Common/format.h rename to flang/include/flang/Common/format.h index 6f4dfc8d2376b7..138e84b72b733d 100644 --- a/FortranRuntime/include/flang/Common/format.h +++ b/flang/include/flang/Common/format.h @@ -901,4 +901,4 @@ template bool FormatValidator::Check() { } } // namespace Fortran::common -#endif /* FORTRAN_COMMON_FORMAT_H_ */ +#endif // FORTRAN_COMMON_FORMAT_H_ diff --git a/FortranRuntime/include/flang/Common/idioms.h b/flang/include/flang/Common/idioms.h similarity index 99% rename from FortranRuntime/include/flang/Common/idioms.h rename to flang/include/flang/Common/idioms.h index 1ae0c0b35112e9..99f383ec75b999 100644 --- a/FortranRuntime/include/flang/Common/idioms.h +++ b/flang/include/flang/Common/idioms.h @@ -150,4 +150,4 @@ template using IfNoLvalue = std::enable_if_t<(... && !std::is_lvalue_reference_v), A>; template using NoLvalue = IfNoLvalue; } // namespace Fortran::common -#endif /* FORTRAN_COMMON_IDIOMS_H_ */ +#endif // FORTRAN_COMMON_IDIOMS_H_ diff --git a/FortranRuntime/include/flang/Common/leading-zero-bit-count.h b/flang/include/flang/Common/leading-zero-bit-count.h similarity index 98% rename from FortranRuntime/include/flang/Common/leading-zero-bit-count.h rename to flang/include/flang/Common/leading-zero-bit-count.h index e788bfa9bcfd08..a296e0b446917f 100644 --- a/FortranRuntime/include/flang/Common/leading-zero-bit-count.h +++ b/flang/include/flang/Common/leading-zero-bit-count.h @@ -93,4 +93,4 @@ template 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_ diff --git a/FortranRuntime/include/flang/Common/optional.h b/flang/include/flang/Common/optional.h similarity index 98% rename from FortranRuntime/include/flang/Common/optional.h rename to flang/include/flang/Common/optional.h index c3db3b1329a2fd..c0f4278009f40a 100644 --- a/FortranRuntime/include/flang/Common/optional.h +++ b/flang/include/flang/Common/optional.h @@ -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 @@ -240,4 +240,4 @@ using std::optional; } // namespace Fortran::common -#endif /* FORTRAN_COMMON_OPTIONAL_H_ */ +#endif // FORTRAN_COMMON_OPTIONAL_H diff --git a/FortranRuntime/include/flang/Common/real.h b/flang/include/flang/Common/real.h similarity index 99% rename from FortranRuntime/include/flang/Common/real.h rename to flang/include/flang/Common/real.h index dc9a2404731e70..b527deda0e3b4f 100644 --- a/FortranRuntime/include/flang/Common/real.h +++ b/flang/include/flang/Common/real.h @@ -141,4 +141,4 @@ class RealCharacteristics { }; } // namespace Fortran::common -#endif /* FORTRAN_COMMON_REAL_H_ */ +#endif // FORTRAN_COMMON_REAL_H_ diff --git a/FortranRuntime/include/flang/Common/reference-wrapper.h b/flang/include/flang/Common/reference-wrapper.h similarity index 96% rename from FortranRuntime/include/flang/Common/reference-wrapper.h rename to flang/include/flang/Common/reference-wrapper.h index 6822fb335f398c..2983754108f95a 100644 --- a/FortranRuntime/include/flang/Common/reference-wrapper.h +++ b/flang/include/flang/Common/reference-wrapper.h @@ -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 @@ -111,4 +111,4 @@ using std::reference_wrapper; } // namespace Fortran::common -#endif /* FORTRAN_COMMON_REFERENCE_WRAPPER_H_ */ +#endif // FORTRAN_COMMON_REFERENCE_WRAPPER_H diff --git a/FortranRuntime/include/flang/Common/restorer.h b/flang/include/flang/Common/restorer.h similarity index 97% rename from FortranRuntime/include/flang/Common/restorer.h rename to flang/include/flang/Common/restorer.h index a5c5ebe7344a1b..0f1bc48620d37e 100644 --- a/FortranRuntime/include/flang/Common/restorer.h +++ b/flang/include/flang/Common/restorer.h @@ -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 class Restorer { public: @@ -53,4 +53,4 @@ RT_API_ATTRS common::IfNoLvalue, B> ScopedSet( return Restorer{to, std::move(original)}; } } // namespace Fortran::common -#endif /* FORTRAN_COMMON_RESTORER_H_ */ +#endif // FORTRAN_COMMON_RESTORER_H_ diff --git a/FortranRuntime/include/flang/Common/target-rounding.h b/flang/include/flang/Common/target-rounding.h similarity index 100% rename from FortranRuntime/include/flang/Common/target-rounding.h rename to flang/include/flang/Common/target-rounding.h diff --git a/FortranRuntime/include/flang/Common/uint128.h b/flang/include/flang/Common/uint128.h similarity index 99% rename from FortranRuntime/include/flang/Common/uint128.h rename to flang/include/flang/Common/uint128.h index 1b2ee6a2c14b87..821c8c3b08a52f 100644 --- a/FortranRuntime/include/flang/Common/uint128.h +++ b/flang/include/flang/Common/uint128.h @@ -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 #include @@ -303,4 +303,4 @@ template using HostSignedIntType = typename HostSignedIntTypeHelper::type; } // namespace Fortran::common -#endif /* FORTRAN_COMMON_UINT128_H_ */ +#endif diff --git a/FortranRuntime/include/flang/Common/variant.h b/flang/include/flang/Common/variant.h similarity index 89% rename from FortranRuntime/include/flang/Common/variant.h rename to flang/include/flang/Common/variant.h index ff9b1aed4eba91..1af85876afac00 100644 --- a/FortranRuntime/include/flang/Common/variant.h +++ b/flang/include/flang/Common/variant.h @@ -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 @@ -27,4 +27,4 @@ using cuda::std::visit; #include #endif // !RT_USE_LIBCUDACXX -#endif /* FORTRAN_COMMON_VARIANT_H_ */ +#endif // FORTRAN_COMMON_VARIANT_H diff --git a/FortranRuntime/include/flang/Common/visit.h b/flang/include/flang/Common/visit.h similarity index 98% rename from FortranRuntime/include/flang/Common/visit.h rename to flang/include/flang/Common/visit.h index 8030ac9be173c3..ad66297650b093 100644 --- a/FortranRuntime/include/flang/Common/visit.h +++ b/flang/include/flang/Common/visit.h @@ -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 namespace Fortran::common { @@ -100,4 +100,4 @@ using Fortran::common::log2visit::visit; #endif } // namespace Fortran::common -#endif /* FORTRAN_COMMON_VISIT_H_ */ +#endif // FORTRAN_COMMON_VISIT_H_ diff --git a/FortranRuntime/include/flang/Common/windows-include.h b/flang/include/flang/Common/windows-include.h similarity index 93% rename from FortranRuntime/include/flang/Common/windows-include.h rename to flang/include/flang/Common/windows-include.h index bee79d4fceb3ba..75ef4974251ff9 100644 --- a/FortranRuntime/include/flang/Common/windows-include.h +++ b/flang/include/flang/Common/windows-include.h @@ -22,4 +22,4 @@ #endif // _WIN32 -#endif /* FORTRAN_COMMON_WINDOWS_INCLUDE_H_ */ +#endif // FORTRAN_COMMON_WINDOWS_INCLUDE_H_ diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h index 516355c01ec7d0..89a10ce69a2ba2 100644 --- a/flang/include/flang/ISO_Fortran_binding.h +++ b/flang/include/flang/ISO_Fortran_binding.h @@ -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 #define FORTRAN_ISO_NAMESPACE_ #endif @@ -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_ */ diff --git a/flang/include/flang/Lower/Allocatable.h b/flang/include/flang/Lower/Allocatable.h index 1209b157ed1f41..0e89af94af40f6 100644 --- a/flang/include/flang/Lower/Allocatable.h +++ b/flang/include/flang/Lower/Allocatable.h @@ -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 { diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h index 3fc4201bd16c6c..78bb82b17d4050 100644 --- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h +++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h @@ -397,7 +397,6 @@ struct IntrinsicLibrary { fir::ExtendedValue genUbound(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genUnpack(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genVerify(mlir::Type, llvm::ArrayRef); - fir::ExtendedValue genNumericStorageSize(mlir::Type, llvm::ArrayRef); /// Implement all conversion functions like DBLE, the first argument is /// the value to convert. There may be an additional KIND arguments that diff --git a/flang/include/flang/Optimizer/Builder/MutableBox.h b/flang/include/flang/Optimizer/Builder/MutableBox.h index fea7c7204837b4..39657ddaf6e03a 100644 --- a/flang/include/flang/Optimizer/Builder/MutableBox.h +++ b/flang/include/flang/Optimizer/Builder/MutableBox.h @@ -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 { diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h index 31d1416846d0c9..b9a8a670d07938 100644 --- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h +++ b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h @@ -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" diff --git a/FortranRuntime/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h similarity index 93% rename from FortranRuntime/include/flang/Runtime/CUDA/allocator.h rename to flang/include/flang/Runtime/CUDA/allocator.h index 48185e8f34eaf6..cc88896b1f0bd6 100644 --- a/FortranRuntime/include/flang/Runtime/CUDA/allocator.h +++ b/flang/include/flang/Runtime/CUDA/allocator.h @@ -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) \ @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/CUDA/descriptor.h b/flang/include/flang/Runtime/CUDA/descriptor.h similarity index 91% rename from FortranRuntime/include/flang/Runtime/CUDA/descriptor.h rename to flang/include/flang/Runtime/CUDA/descriptor.h index 68ad0987d9aecd..501a834f43bd42 100644 --- a/FortranRuntime/include/flang/Runtime/CUDA/descriptor.h +++ b/flang/include/flang/Runtime/CUDA/descriptor.h @@ -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 @@ -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_ diff --git a/flang/include/flang/Runtime/README.md b/flang/include/flang/Runtime/README.md new file mode 100644 index 00000000000000..a722732fb76407 --- /dev/null +++ b/flang/include/flang/Runtime/README.md @@ -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`; `fortran::common::optional` 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 ` can help to support C++ and C. + + * Global declarations may need to be annotated using definitions from + `api-attrs.h`. diff --git a/FortranRuntime/include/flang/Runtime/allocatable.h b/flang/include/flang/Runtime/allocatable.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/allocatable.h rename to flang/include/flang/Runtime/allocatable.h index d7f3910074a760..480e987ed5ec6b 100644 --- a/FortranRuntime/include/flang/Runtime/allocatable.h +++ b/flang/include/flang/Runtime/allocatable.h @@ -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" { @@ -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_ diff --git a/flang/include/flang/Runtime/allocator-registry-consts.h b/flang/include/flang/Runtime/allocator-registry-consts.h new file mode 100644 index 00000000000000..70735c2fc7a71c --- /dev/null +++ b/flang/include/flang/Runtime/allocator-registry-consts.h @@ -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_ */ diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h new file mode 100644 index 00000000000000..da058874e50487 --- /dev/null +++ b/flang/include/flang/Runtime/array-constructor-consts.h @@ -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 + +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_ */ diff --git a/FortranRuntime/include/flang/Runtime/assign.h b/flang/include/flang/Runtime/assign.h similarity index 98% rename from FortranRuntime/include/flang/Runtime/assign.h rename to flang/include/flang/Runtime/assign.h index 55d15a5c046868..a1cc9eaf4355f6 100644 --- a/FortranRuntime/include/flang/Runtime/assign.h +++ b/flang/include/flang/Runtime/assign.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/c-or-cpp.h b/flang/include/flang/Runtime/c-or-cpp.h similarity index 95% rename from FortranRuntime/include/flang/Runtime/c-or-cpp.h rename to flang/include/flang/Runtime/c-or-cpp.h index 3c0c0be643cbc3..8bac523907750c 100644 --- a/FortranRuntime/include/flang/Runtime/c-or-cpp.h +++ b/flang/include/flang/Runtime/c-or-cpp.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/character.h b/flang/include/flang/Runtime/character.h similarity index 99% rename from FortranRuntime/include/flang/Runtime/character.h rename to flang/include/flang/Runtime/character.h index a842c30cd8120c..dd47686fe858fd 100644 --- a/FortranRuntime/include/flang/Runtime/character.h +++ b/flang/include/flang/Runtime/character.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/command.h b/flang/include/flang/Runtime/command.h similarity index 98% rename from FortranRuntime/include/flang/Runtime/command.h rename to flang/include/flang/Runtime/command.h index 2bbdfca7631163..7ab3f6442dcf92 100644 --- a/FortranRuntime/include/flang/Runtime/command.h +++ b/flang/include/flang/Runtime/command.h @@ -62,4 +62,4 @@ std::int32_t RTNAME(GetCwd)( } } // namespace Fortran::runtime -#endif /* FORTRAN_RUNTIME_COMMAND_H_ */ +#endif // FORTRAN_RUNTIME_COMMAND_H_ diff --git a/FortranRuntime/include/flang/Runtime/cpp-type.h b/flang/include/flang/Runtime/cpp-type.h similarity index 98% rename from FortranRuntime/include/flang/Runtime/cpp-type.h rename to flang/include/flang/Runtime/cpp-type.h index 7de1ea4f45f224..27b43de7d0f0f6 100644 --- a/FortranRuntime/include/flang/Runtime/cpp-type.h +++ b/flang/include/flang/Runtime/cpp-type.h @@ -110,4 +110,4 @@ template <> struct CppTypeForHelper { }; } // namespace Fortran::runtime -#endif /* FORTRAN_RUNTIME_CPP_TYPE_H_ */ +#endif // FORTRAN_RUNTIME_CPP_TYPE_H_ diff --git a/FortranRuntime/include/flang/Runtime/derived-api.h b/flang/include/flang/Runtime/derived-api.h similarity index 98% rename from FortranRuntime/include/flang/Runtime/derived-api.h rename to flang/include/flang/Runtime/derived-api.h index ca1681e974051c..79aa7d82de8819 100644 --- a/FortranRuntime/include/flang/Runtime/derived-api.h +++ b/flang/include/flang/Runtime/derived-api.h @@ -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_ diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h new file mode 100644 index 00000000000000..2d746c6337b518 --- /dev/null +++ b/flang/include/flang/Runtime/descriptor-consts.h @@ -0,0 +1,72 @@ +//===-- 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 +#include + +// 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; + +/// 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(lengthTypeParameters) * 8u; + } + return bytes; +} + +} // namespace Fortran::runtime +#endif /* FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ */ diff --git a/FortranRuntime/include/flang/Runtime/entry-names.h b/flang/include/flang/Runtime/entry-names.h similarity index 89% rename from FortranRuntime/include/flang/Runtime/entry-names.h rename to flang/include/flang/Runtime/entry-names.h index 25134771bf9185..68582b92b54941 100644 --- a/FortranRuntime/include/flang/Runtime/entry-names.h +++ b/flang/include/flang/Runtime/entry-names.h @@ -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 @@ -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" @@ -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 */ diff --git a/FortranRuntime/include/flang/Runtime/exceptions.h b/flang/include/flang/Runtime/exceptions.h similarity index 86% rename from FortranRuntime/include/flang/Runtime/exceptions.h rename to flang/include/flang/Runtime/exceptions.h index f2c67325b34d92..1ab22da103a50f 100644 --- a/FortranRuntime/include/flang/Runtime/exceptions.h +++ b/flang/include/flang/Runtime/exceptions.h @@ -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. @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/execute.h b/flang/include/flang/Runtime/execute.h similarity index 89% rename from FortranRuntime/include/flang/Runtime/execute.h rename to flang/include/flang/Runtime/execute.h index d1958a82594ffd..ca137b9d1823c4 100644 --- a/FortranRuntime/include/flang/Runtime/execute.h +++ b/flang/include/flang/Runtime/execute.h @@ -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. @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/extensions.h b/flang/include/flang/Runtime/extensions.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/extensions.h rename to flang/include/flang/Runtime/extensions.h index f46ccdd7d9528d..fef651f3b2eedb 100644 --- a/FortranRuntime/include/flang/Runtime/extensions.h +++ b/flang/include/flang/Runtime/extensions.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/freestanding-tools.h b/flang/include/flang/Runtime/freestanding-tools.h similarity index 99% rename from FortranRuntime/include/flang/Runtime/freestanding-tools.h rename to flang/include/flang/Runtime/freestanding-tools.h index 8aeef54ba0af3d..e94cb0a6c938cd 100644 --- a/FortranRuntime/include/flang/Runtime/freestanding-tools.h +++ b/flang/include/flang/Runtime/freestanding-tools.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/inquiry.h b/flang/include/flang/Runtime/inquiry.h similarity index 91% rename from FortranRuntime/include/flang/Runtime/inquiry.h rename to flang/include/flang/Runtime/inquiry.h index 83b07cf2f31a47..c7a7487f1a1b18 100644 --- a/FortranRuntime/include/flang/Runtime/inquiry.h +++ b/flang/include/flang/Runtime/inquiry.h @@ -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. @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/io-api.h b/flang/include/flang/Runtime/io-api.h similarity index 98% rename from FortranRuntime/include/flang/Runtime/io-api.h rename to flang/include/flang/Runtime/io-api.h index be948061c241a0..e588b46dc4b3a1 100644 --- a/FortranRuntime/include/flang/Runtime/io-api.h +++ b/flang/include/flang/Runtime/io-api.h @@ -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 #include @@ -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) @@ -369,4 +366,4 @@ enum Iostat IODECL(EndIoStatement)(Cookie); } // extern "C" } // namespace Fortran::runtime::io -#endif /* FORTRAN_RUNTIME_IO_API_H_ */ +#endif diff --git a/FortranRuntime/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat.h similarity index 96% rename from FortranRuntime/include/flang/Runtime/iostat.h rename to flang/include/flang/Runtime/iostat.h index 9a52990045ee13..0565718f6c103d 100644 --- a/FortranRuntime/include/flang/Runtime/iostat.h +++ b/flang/include/flang/Runtime/iostat.h @@ -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, @@ -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_ diff --git a/FortranRuntime/include/flang/Common/magic-numbers.h b/flang/include/flang/Runtime/magic-numbers.h similarity index 98% rename from FortranRuntime/include/flang/Common/magic-numbers.h rename to flang/include/flang/Runtime/magic-numbers.h index 931df690766219..bab0e9ae05299a 100644 --- a/FortranRuntime/include/flang/Common/magic-numbers.h +++ b/flang/include/flang/Runtime/magic-numbers.h @@ -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. diff --git a/FortranRuntime/include/flang/Runtime/main.h b/flang/include/flang/Runtime/main.h similarity index 95% rename from FortranRuntime/include/flang/Runtime/main.h rename to flang/include/flang/Runtime/main.h index 98fcf1250d0ad6..88232ea64fa6ab 100644 --- a/FortranRuntime/include/flang/Runtime/main.h +++ b/flang/include/flang/Runtime/main.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/matmul-instances.inc b/flang/include/flang/Runtime/matmul-instances.inc similarity index 100% rename from FortranRuntime/include/flang/Runtime/matmul-instances.inc rename to flang/include/flang/Runtime/matmul-instances.inc diff --git a/FortranRuntime/include/flang/Runtime/matmul-transpose.h b/flang/include/flang/Runtime/matmul-transpose.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/matmul-transpose.h rename to flang/include/flang/Runtime/matmul-transpose.h index 077277fae2da86..2d79ca10e08958 100644 --- a/FortranRuntime/include/flang/Runtime/matmul-transpose.h +++ b/flang/include/flang/Runtime/matmul-transpose.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/matmul.h b/flang/include/flang/Runtime/matmul.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/matmul.h rename to flang/include/flang/Runtime/matmul.h index cd375ac43d77f2..a72d4a06ee4594 100644 --- a/FortranRuntime/include/flang/Runtime/matmul.h +++ b/flang/include/flang/Runtime/matmul.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/misc-intrinsic.h b/flang/include/flang/Runtime/misc-intrinsic.h similarity index 95% rename from FortranRuntime/include/flang/Runtime/misc-intrinsic.h rename to flang/include/flang/Runtime/misc-intrinsic.h index 1d4163c2e1e751..3fb3aaed49c0fb 100644 --- a/FortranRuntime/include/flang/Runtime/misc-intrinsic.h +++ b/flang/include/flang/Runtime/misc-intrinsic.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/numeric.h b/flang/include/flang/Runtime/numeric.h similarity index 99% rename from FortranRuntime/include/flang/Runtime/numeric.h rename to flang/include/flang/Runtime/numeric.h index 5fbab2e069b739..84a5a7cd7a361c 100644 --- a/FortranRuntime/include/flang/Runtime/numeric.h +++ b/flang/include/flang/Runtime/numeric.h @@ -455,4 +455,4 @@ CppTypeFor RTDECL(FPow16k)( } // extern "C" } // namespace Fortran::runtime -#endif /* FORTRAN_RUNTIME_NUMERIC_H_ */ +#endif // FORTRAN_RUNTIME_NUMERIC_H_ diff --git a/FortranRuntime/include/flang/Runtime/pointer.h b/flang/include/flang/Runtime/pointer.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/pointer.h rename to flang/include/flang/Runtime/pointer.h index b7322ad92bd583..c6d29db7218376 100644 --- a/FortranRuntime/include/flang/Runtime/pointer.h +++ b/flang/include/flang/Runtime/pointer.h @@ -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(). diff --git a/FortranRuntime/include/flang/Runtime/ragged.h b/flang/include/flang/Runtime/ragged.h similarity index 96% rename from FortranRuntime/include/flang/Runtime/ragged.h rename to flang/include/flang/Runtime/ragged.h index 8574bc1fa110c8..f52a619c55b43e 100644 --- a/FortranRuntime/include/flang/Runtime/ragged.h +++ b/flang/include/flang/Runtime/ragged.h @@ -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. @@ -57,4 +57,4 @@ void RTDECL(RaggedArrayDeallocate)(void *raggedArrayHeader); } // extern "C" } // namespace Fortran::runtime -#endif /* FORTRAN_RUNTIME_RAGGED_H_ */ +#endif // FORTRAN_RUNTIME_RAGGED_H_ diff --git a/FortranRuntime/include/flang/Runtime/random.h b/flang/include/flang/Runtime/random.h similarity index 100% rename from FortranRuntime/include/flang/Runtime/random.h rename to flang/include/flang/Runtime/random.h diff --git a/FortranRuntime/include/flang/Runtime/reduce.h b/flang/include/flang/Runtime/reduce.h similarity index 99% rename from FortranRuntime/include/flang/Runtime/reduce.h rename to flang/include/flang/Runtime/reduce.h index ae2828f04bf7c0..60f54c393b4bbd 100644 --- a/FortranRuntime/include/flang/Runtime/reduce.h +++ b/flang/include/flang/Runtime/reduce.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/reduction.h b/flang/include/flang/Runtime/reduction.h similarity index 99% rename from FortranRuntime/include/flang/Runtime/reduction.h rename to flang/include/flang/Runtime/reduction.h index e00593fbc9f75e..97986c12e8a10e 100644 --- a/FortranRuntime/include/flang/Runtime/reduction.h +++ b/flang/include/flang/Runtime/reduction.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/stop.h b/flang/include/flang/Runtime/stop.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/stop.h rename to flang/include/flang/Runtime/stop.h index 9ba41343c6f964..f7c4ffe7403e8e 100644 --- a/FortranRuntime/include/flang/Runtime/stop.h +++ b/flang/include/flang/Runtime/stop.h @@ -37,4 +37,4 @@ NORETURN void RTNAME(ReportFatalUserError)( FORTRAN_EXTERN_C_END -#endif /* FORTRAN_RUNTIME_STOP_H_ */ +#endif // FORTRAN_RUNTIME_STOP_H_ diff --git a/FortranRuntime/include/flang/Runtime/support.h b/flang/include/flang/Runtime/support.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/support.h rename to flang/include/flang/Runtime/support.h index 9c9b067a18f2e4..4a6d4357e87103 100644 --- a/FortranRuntime/include/flang/Runtime/support.h +++ b/flang/include/flang/Runtime/support.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/temporary-stack.h b/flang/include/flang/Runtime/temporary-stack.h similarity index 98% rename from FortranRuntime/include/flang/Runtime/temporary-stack.h rename to flang/include/flang/Runtime/temporary-stack.h index f83fab7b0ac811..3c1a4ea11a4352 100644 --- a/FortranRuntime/include/flang/Runtime/temporary-stack.h +++ b/flang/include/flang/Runtime/temporary-stack.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/time-intrinsic.h b/flang/include/flang/Runtime/time-intrinsic.h similarity index 97% rename from FortranRuntime/include/flang/Runtime/time-intrinsic.h rename to flang/include/flang/Runtime/time-intrinsic.h index 0e63fc6a4647a4..80490a17e45597 100644 --- a/FortranRuntime/include/flang/Runtime/time-intrinsic.h +++ b/flang/include/flang/Runtime/time-intrinsic.h @@ -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_ diff --git a/FortranRuntime/include/flang/Runtime/transformational.h b/flang/include/flang/Runtime/transformational.h similarity index 99% rename from FortranRuntime/include/flang/Runtime/transformational.h rename to flang/include/flang/Runtime/transformational.h index 266dd9d7aebc24..a39b872f376a69 100644 --- a/FortranRuntime/include/flang/Runtime/transformational.h +++ b/flang/include/flang/Runtime/transformational.h @@ -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_ diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h index 718ce680afeeab..1423d2c83d22cc 100644 --- a/flang/include/flang/Support/Fortran-features.h +++ b/flang/include/flang/Support/Fortran-features.h @@ -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" @@ -191,4 +191,4 @@ class LanguageFeatureControl { bool warnAllUsage_{false}; }; } // namespace Fortran::common -#endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_ +#endif /* FORTRAN_SUPPORT_FORTRAN_FEATURES_H_ */ diff --git a/flang/include/flang/Support/Fortran.h b/flang/include/flang/Support/Fortran.h index 343a0b30d2ba9c..7a9b0d56d6b2ac 100644 --- a/flang/include/flang/Support/Fortran.h +++ b/flang/include/flang/Support/Fortran.h @@ -1,4 +1,4 @@ -//===-- 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. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#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. @@ -107,4 +107,4 @@ inline std::string GetExternalAssemblyName( } } // namespace Fortran::common -#endif // FORTRAN_COMMON_FORTRAN_H_ +#endif /* FORTRAN_SUPPORT_FORTRAN_H_ */ diff --git a/flang/include/flang/Support/MathOptionsBase.h b/flang/include/flang/Support/MathOptionsBase.h index a739ba3e066599..072aed20da4708 100644 --- a/flang/include/flang/Support/MathOptionsBase.h +++ b/flang/include/flang/Support/MathOptionsBase.h @@ -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 { @@ -41,4 +41,4 @@ class MathOptionsBase { } // namespace Fortran::common -#endif // FORTRAN_COMMON_MATHOPTIONSBASE_H +#endif /* FORTRAN_SUPPORT_MATHOPTIONSBASE_H_ */ diff --git a/flang/include/flang/Support/Version.h b/flang/include/flang/Support/Version.h index 643ddd2e27f69a..4ceb19e7f4d714 100644 --- a/flang/include/flang/Support/Version.h +++ b/flang/include/flang/Support/Version.h @@ -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" @@ -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_ */ diff --git a/flang/include/flang/Support/default-kinds.h b/flang/include/flang/Support/default-kinds.h index e78a08dfae6cc3..92f06e6fe2d272 100644 --- a/flang/include/flang/Support/default-kinds.h +++ b/flang/include/flang/Support/default-kinds.h @@ -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 @@ -58,4 +58,4 @@ class IntrinsicTypeDefaultKinds { int defaultLogicalKind_{defaultIntegerKind_}; }; } // namespace Fortran::common -#endif // FORTRAN_COMMON_DEFAULT_KINDS_H_ +#endif /* FORTRAN_SUPPORT_DEFAULT_KINDS_H_ */ diff --git a/flang/include/flang/Support/indirection.h b/flang/include/flang/Support/indirection.h index 1221a659323503..aeb1698516bae9 100644 --- a/flang/include/flang/Support/indirection.h +++ b/flang/include/flang/Support/indirection.h @@ -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 @@ -171,4 +171,4 @@ template class ForwardOwningPointer { void (*deleter_)(A *){nullptr}; }; } // namespace Fortran::common -#endif // FORTRAN_COMMON_INDIRECTION_H_ +#endif /* FORTRAN_SUPPORT_INDIRECTION_H_ */ diff --git a/flang/include/flang/Support/interval.h b/flang/include/flang/Support/interval.h index 2918cc54de3926..99c0784f006a80 100644 --- a/flang/include/flang/Support/interval.h +++ b/flang/include/flang/Support/interval.h @@ -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 to represent // the half-open interval [x .. x+n). @@ -126,4 +126,4 @@ template class Interval { std::size_t size_{0}; }; } // namespace Fortran::common -#endif // FORTRAN_COMMON_INTERVAL_H_ +#endif /* FORTRAN_SUPPORT_INTERVAL_H_ */ diff --git a/flang/include/flang/Support/template.h b/flang/include/flang/Support/template.h index 58c9b0a5628e8a..36fa6f7072b40c 100644 --- a/flang/include/flang/Support/template.h +++ b/flang/include/flang/Support/template.h @@ -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" @@ -322,4 +322,4 @@ common::IfNoLvalue SearchTypes( std::move(visitor), std::move(defaultResult)); } } // namespace Fortran::common -#endif // FORTRAN_COMMON_TEMPLATE_H_ +#endif /* FORTRAN_SUPPORT_TEMPLATE_H_ */ diff --git a/flang/include/flang/Support/unwrap.h b/flang/include/flang/Support/unwrap.h index d8fa553dedda3f..e890753499d1a1 100644 --- a/flang/include/flang/Support/unwrap.h +++ b/flang/include/flang/Support/unwrap.h @@ -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" @@ -155,4 +155,4 @@ template std::optional UnwrapCopy(const B &x) { } } } // namespace Fortran::common -#endif // FORTRAN_COMMON_UNWRAP_H_ +#endif /* FORTRAN_SUPPORT_UNWRAP_H_ */ diff --git a/flang/include/flang/Testing/README.md b/flang/include/flang/Testing/README.md new file mode 100644 index 00000000000000..a722732fb76407 --- /dev/null +++ b/flang/include/flang/Testing/README.md @@ -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`; `fortran::common::optional` 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 ` can help to support C++ and C. + + * Global declarations may need to be annotated using definitions from + `api-attrs.h`. diff --git a/FortranRuntime/include/flang/Testing/fp-testing.h b/flang/include/flang/Testing/fp-testing.h similarity index 100% rename from FortranRuntime/include/flang/Testing/fp-testing.h rename to flang/include/flang/Testing/fp-testing.h diff --git a/FortranRuntime/include/flang/Testing/testing.h b/flang/include/flang/Testing/testing.h similarity index 100% rename from FortranRuntime/include/flang/Testing/testing.h rename to flang/include/flang/Testing/testing.h diff --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt index ff7c186bff866b..04b719861a86cb 100644 --- a/flang/lib/Common/CMakeLists.txt +++ b/flang/lib/Common/CMakeLists.txt @@ -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 diff --git a/flang/lib/Common/README.md b/flang/lib/Common/README.md new file mode 100644 index 00000000000000..a722732fb76407 --- /dev/null +++ b/flang/lib/Common/README.md @@ -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`; `fortran::common::optional` 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 ` can help to support C++ and C. + + * Global declarations may need to be annotated using definitions from + `api-attrs.h`. diff --git a/FortranRuntime/lib/Common/big-radix-floating-point.h b/flang/lib/Common/big-radix-floating-point.h similarity index 100% rename from FortranRuntime/lib/Common/big-radix-floating-point.h rename to flang/lib/Common/big-radix-floating-point.h diff --git a/FortranRuntime/lib/Common/binary-to-decimal.cpp b/flang/lib/Common/binary-to-decimal.cpp similarity index 100% rename from FortranRuntime/lib/Common/binary-to-decimal.cpp rename to flang/lib/Common/binary-to-decimal.cpp diff --git a/FortranRuntime/lib/Common/decimal-to-binary.cpp b/flang/lib/Common/decimal-to-binary.cpp similarity index 100% rename from FortranRuntime/lib/Common/decimal-to-binary.cpp rename to flang/lib/Common/decimal-to-binary.cpp diff --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt index 6b058e4a0ae2fa..5dd82e10a66556 100644 --- a/flang/lib/Decimal/CMakeLists.txt +++ b/flang/lib/Decimal/CMakeLists.txt @@ -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) @@ -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) @@ -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) diff --git a/flang/lib/Evaluate/common.cpp b/flang/lib/Evaluate/common.cpp index ed040b0728c4db..c633bff57b1ecd 100644 --- a/flang/lib/Evaluate/common.cpp +++ b/flang/lib/Evaluate/common.cpp @@ -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( diff --git a/flang/lib/Evaluate/fold-logical.cpp b/flang/lib/Evaluate/fold-logical.cpp index a7e1aad38f3586..ee6655f8387177 100644 --- a/flang/lib/Evaluate/fold-logical.cpp +++ b/flang/lib/Evaluate/fold-logical.cpp @@ -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 { diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index f76d44f5479d32..82bedca7bd41dd 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -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" diff --git a/flang/lib/Optimizer/Builder/CMakeLists.txt b/flang/lib/Optimizer/Builder/CMakeLists.txt index 05164d41a4cb55..1d63401f36a616 100644 --- a/flang/lib/Optimizer/Builder/CMakeLists.txt +++ b/flang/lib/Optimizer/Builder/CMakeLists.txt @@ -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 diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp index c786bef5cb1c4c..b7c6dc5fb2bf6c 100644 --- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp @@ -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; @@ -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); diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 88293bcf36a780..eed389380f7cca 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -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" @@ -1273,16 +1273,12 @@ struct EmboxCommonConversion : public fir::FIROpConversion { 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) { diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index 08d75c46faee4b..ca0b50de9bdb93 100644 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -1467,4 +1467,4 @@ fir::getTypeSizeAndAlignmentOrCrash(mlir::Location loc, mlir::Type ty, if (result) return *result; TODO(loc, "computing size of a component"); -} \ No newline at end of file +} diff --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp index b5a58ddca0ecdd..c5774ed30de748 100644 --- a/flang/lib/Semantics/compute-offsets.cpp +++ b/flang/lib/Semantics/compute-offsets.cpp @@ -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" @@ -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)) { diff --git a/flang/lib/Testing/README.md b/flang/lib/Testing/README.md new file mode 100644 index 00000000000000..a722732fb76407 --- /dev/null +++ b/flang/lib/Testing/README.md @@ -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`; `fortran::common::optional` 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 ` can help to support C++ and C. + + * Global declarations may need to be annotated using definitions from + `api-attrs.h`. diff --git a/FortranRuntime/lib/Testing/fp-testing.cpp b/flang/lib/Testing/fp-testing.cpp similarity index 100% rename from FortranRuntime/lib/Testing/fp-testing.cpp rename to flang/lib/Testing/fp-testing.cpp diff --git a/FortranRuntime/lib/Testing/testing.cpp b/flang/lib/Testing/testing.cpp similarity index 100% rename from FortranRuntime/lib/Testing/testing.cpp rename to flang/lib/Testing/testing.cpp diff --git a/flang/module/__fortran_builtins.f90 b/flang/module/__fortran_builtins.f90 index fe91305c836ff4..d1d4a639e70d72 100644 --- a/flang/module/__fortran_builtins.f90 +++ b/flang/module/__fortran_builtins.f90 @@ -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 diff --git a/flang/module/__fortran_ieee_exceptions.f90 b/flang/module/__fortran_ieee_exceptions.f90 index 56f79a473b556a..6691012eda238a 100644 --- a/flang/module/__fortran_ieee_exceptions.f90 +++ b/flang/module/__fortran_ieee_exceptions.f90 @@ -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: & diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90 index dd487f6ed1ffee..0224ecfdde7c60 100644 --- a/flang/module/cudadevice.f90 +++ b/flang/module/cudadevice.f90 @@ -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. diff --git a/flang/module/ieee_arithmetic.f90 b/flang/module/ieee_arithmetic.f90 index 667374d0660806..7eaa7db55af9f8 100644 --- a/flang/module/ieee_arithmetic.f90 +++ b/flang/module/ieee_arithmetic.f90 @@ -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: diff --git a/flang/module/iso_fortran_env.f90 b/flang/module/iso_fortran_env.f90 index d1f956b6b86408..4e575b422c2a04 100644 --- a/flang/module/iso_fortran_env.f90 +++ b/flang/module/iso_fortran_env.f90 @@ -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 diff --git a/FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90 b/flang/module/iso_fortran_env_impl.f90 similarity index 98% rename from FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90 rename to flang/module/iso_fortran_env_impl.f90 index 1a4da69266c55b..4de54dda7bab1c 100644 --- a/FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90 +++ b/flang/module/iso_fortran_env_impl.f90 @@ -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. diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index 228bbb7e313d82..4acbc0606d1977 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -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) diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index f4ebc784a26cc8..9d7b8633958cb7 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -105,12 +105,10 @@ 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}) @@ -118,8 +116,8 @@ if (NOT CMAKE_CROSSCOMPILING) 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") diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt index 2d86e991aee610..a3fed6c27d125b 100644 --- a/flang/unittests/CMakeLists.txt +++ b/flang/unittests/CMakeLists.txt @@ -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) @@ -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) diff --git a/flang/unittests/Common/CMakeLists.txt b/flang/unittests/Common/CMakeLists.txt new file mode 100644 index 00000000000000..bda02ed29a5efa --- /dev/null +++ b/flang/unittests/Common/CMakeLists.txt @@ -0,0 +1,3 @@ +add_flang_unittest(FlangCommonTests + FastIntSetTest.cpp +) diff --git a/FortranRuntime/unittests/Common/FastIntSetTest.cpp b/flang/unittests/Common/FastIntSetTest.cpp similarity index 97% rename from FortranRuntime/unittests/Common/FastIntSetTest.cpp rename to flang/unittests/Common/FastIntSetTest.cpp index a36a334e370eb9..bd1b953fa16631 100644 --- a/FortranRuntime/unittests/Common/FastIntSetTest.cpp +++ b/flang/unittests/Common/FastIntSetTest.cpp @@ -1,4 +1,4 @@ -//===-- 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. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "flang/Common/fast-int-set.h" #include "gtest/gtest.h" +#include "flang/Common/fast-int-set.h" #include TEST(FastIntSetTests, Sanity) { diff --git a/flang/unittests/Decimal/CMakeLists.txt b/flang/unittests/Decimal/CMakeLists.txt new file mode 100644 index 00000000000000..d301a9d3628c56 --- /dev/null +++ b/flang/unittests/Decimal/CMakeLists.txt @@ -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 +) diff --git a/FortranRuntime/unittests/Decimal/quick-sanity-test.cpp b/flang/unittests/Decimal/quick-sanity-test.cpp similarity index 92% rename from FortranRuntime/unittests/Decimal/quick-sanity-test.cpp rename to flang/unittests/Decimal/quick-sanity-test.cpp index 0e8ff0ce48b3c6..c36c73b817e1f9 100644 --- a/FortranRuntime/unittests/Decimal/quick-sanity-test.cpp +++ b/flang/unittests/Decimal/quick-sanity-test.cpp @@ -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 diff --git a/FortranRuntime/unittests/Decimal/thorough-test.cpp b/flang/unittests/Decimal/thorough-test.cpp similarity index 86% rename from FortranRuntime/unittests/Decimal/thorough-test.cpp rename to flang/unittests/Decimal/thorough-test.cpp index 0648b61d7c1cda..0f7a2d4b33e764 100644 --- a/FortranRuntime/unittests/Decimal/thorough-test.cpp +++ b/flang/unittests/Decimal/thorough-test.cpp @@ -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 diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt index 35bd7b0f18a90d..c80c04b18035e5 100644 --- a/flang/unittests/Evaluate/CMakeLists.txt +++ b/flang/unittests/Evaluate/CMakeLists.txt @@ -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) @@ -76,4 +76,4 @@ add_flang_nongtest_unittest(folding FortranSemantics ) -add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime) \ No newline at end of file +add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime) diff --git a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp index 1db43cacc90f07..f618e72d7b7f3c 100644 --- a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp +++ b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp @@ -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; From 3beb59b881182def71e991c6fa7dcd382ccb5314 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 14 Oct 2024 17:14:45 +0200 Subject: [PATCH 4/5] build fix --- flang/include/flang/Runtime/descriptor-consts.h | 1 + 1 file changed, 1 insertion(+) diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h index 2d746c6337b518..aa5e2e4ee8b45f 100644 --- a/flang/include/flang/Runtime/descriptor-consts.h +++ b/flang/include/flang/Runtime/descriptor-consts.h @@ -28,6 +28,7 @@ class DerivedType; 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 From b3f9e91d6d362cde01062f06c079de0854c47cd8 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 15 Oct 2024 11:22:50 +0200 Subject: [PATCH 5/5] Re-add ISO-Fortran-binding unittest & cleanup --- FortranRuntime/cmake/config.h.cmake.in | 8 ++++++++ FortranRuntime/lib/Runtime/command.cpp | 2 +- FortranRuntime/unittests/Evaluate/CMakeLists.txt | 7 +++++++ FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp | 4 +++- flang/include/flang/Runtime/README.md | 2 ++ flang/unittests/Evaluate/CMakeLists.txt | 4 ++-- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/FortranRuntime/cmake/config.h.cmake.in b/FortranRuntime/cmake/config.h.cmake.in index 0a1d1394b9bc49..8a4668b90addda 100644 --- a/FortranRuntime/cmake/config.h.cmake.in +++ b/FortranRuntime/cmake/config.h.cmake.in @@ -1,3 +1,11 @@ +/*===-- cmake/config.cmake.in ---------------------------------------*- 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_CONFIG_H #define FORTRAN_RUNTIME_CONFIG_H diff --git a/FortranRuntime/lib/Runtime/command.cpp b/FortranRuntime/lib/Runtime/command.cpp index 3fc941ab2ef861..64b2e62461dd58 100644 --- a/FortranRuntime/lib/Runtime/command.cpp +++ b/FortranRuntime/lib/Runtime/command.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime//command.h" +#include "flang/Runtime/command.h" #include "FortranRuntime/Runtime/descriptor.h" #include "environment.h" #include "stat.h" diff --git a/FortranRuntime/unittests/Evaluate/CMakeLists.txt b/FortranRuntime/unittests/Evaluate/CMakeLists.txt index e0a284b9d39f3b..ceb9e178d34ec1 100644 --- a/FortranRuntime/unittests/Evaluate/CMakeLists.txt +++ b/FortranRuntime/unittests/Evaluate/CMakeLists.txt @@ -12,3 +12,10 @@ add_flang_nongtest_unittest(reshape FortranEvaluate FortranRuntime ) + +add_flang_nongtest_unittest(ISO-Fortran-binding + FortranEvaluateTesting + FortranEvaluate + FortranSemantics + FortranRuntime +) diff --git a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp index fd7073ca1d7db0..b68dfbcbd5b335 100644 --- a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp +++ b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp @@ -28,7 +28,9 @@ template class Test_CFI_CDESC_T { MATCH(false, std::is_const::value); MATCH(false, std::is_volatile::value); // suitable in size - MATCH(true, Descriptor::SizeInBytes(rank_, false) <= Fortran::common::MaxDescriptorSizeInBytes( rank_, false)); + MATCH(true, + Descriptor::SizeInBytes(rank_, false) <= + MaxDescriptorSizeInBytes(rank_, false)); if (rank > 0) { MATCH(sizeof(dvStorage_), Descriptor::SizeInBytes(rank_, false)); } else { // C++ implementation over-allocates for rank=0 by 24bytes. diff --git a/flang/include/flang/Runtime/README.md b/flang/include/flang/Runtime/README.md index a722732fb76407..a13a7e23162e98 100644 --- a/flang/include/flang/Runtime/README.md +++ b/flang/include/flang/Runtime/README.md @@ -23,3 +23,5 @@ The requirements for common code include: * Global declarations may need to be annotated using definitions from `api-attrs.h`. + + * The `Runtime` component is header-only. diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt index c80c04b18035e5..5694f5a144c4c5 100644 --- a/flang/unittests/Evaluate/CMakeLists.txt +++ b/flang/unittests/Evaluate/CMakeLists.txt @@ -1,7 +1,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_library(FortranEvaluateTesting - ../../lib/Testing/testing.cpp - ../../lib/Testing/fp-testing.cpp + ${FLANG_SOURCE_DIR}/lib/Testing/testing.cpp + ${FLANG_SOURCE_DIR}/lib/Testing/fp-testing.cpp ) set_target_properties(FortranEvaluateTesting PROPERTIES FOLDER "Flang/Tests") if (LLVM_LINK_LLVM_DYLIB)