1 //===-- runtime/support.cpp -----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "flang/Runtime/support.h" 10 #include "ISO_Fortran_util.h" 11 #include "type-info.h" 12 #include "flang/Runtime/descriptor.h" 13 14 namespace Fortran::runtime { 15 extern "C" { 16 RT_EXT_API_GROUP_BEGIN 17 RTDEF(IsContiguous)18bool RTDEF(IsContiguous)(const Descriptor &descriptor) { 19 return descriptor.IsContiguous(); 20 } 21 RTDEF(IsAssumedSize)22bool RTDEF(IsAssumedSize)(const Descriptor &descriptor) { 23 return ISO::IsAssumedSize(&descriptor.raw()); 24 } 25 RTDEF(CopyAndUpdateDescriptor)26void RTDEF(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from, 27 const typeInfo::DerivedType *newDynamicType, 28 ISO::CFI_attribute_t newAttribute, enum LowerBoundModifier newLowerBounds) { 29 to = from; 30 if (newDynamicType) { 31 DescriptorAddendum *toAddendum{to.Addendum()}; 32 INTERNAL_CHECK(toAddendum); 33 toAddendum->set_derivedType(newDynamicType); 34 to.raw().elem_len = newDynamicType->sizeInBytes(); 35 } 36 to.raw().attribute = newAttribute; 37 if (newLowerBounds != LowerBoundModifier::Preserve) { 38 const ISO::CFI_index_t newLowerBound{ 39 newLowerBounds == LowerBoundModifier::SetToOnes ? 1 : 0}; 40 const int rank{to.rank()}; 41 for (int i = 0; i < rank; ++i) { 42 to.GetDimension(i).SetLowerBound(newLowerBound); 43 } 44 } 45 } 46 47 RT_EXT_API_GROUP_END 48 } // extern "C" 49 } // namespace Fortran::runtime 50