1 //===-- flang/unittests/Runtime/Pointer.cpp--------- -------------*- C++-*-===// 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/pointer.h" 10 #include "gtest/gtest.h" 11 #include "tools.h" 12 #include "flang/Runtime/descriptor.h" 13 14 using namespace Fortran::runtime; 15 16 TEST(Pointer, BasicAllocateDeallocate) { 17 // REAL(4), POINTER :: p(:) 18 auto p{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, 4, 19 nullptr, 1, nullptr, CFI_attribute_pointer)}; 20 // ALLOCATE(p(2:11)) 21 RTNAME(PointerSetBounds)(*p, 0, 2, 11); 22 RTNAME(PointerAllocate) 23 (*p, /*hasStat=*/false, /*errMsg=*/nullptr, __FILE__, __LINE__); 24 EXPECT_TRUE(RTNAME(PointerIsAssociated)(*p)); 25 EXPECT_EQ(p->Elements(), 10u); 26 EXPECT_EQ(p->GetDimension(0).LowerBound(), 2); 27 EXPECT_EQ(p->GetDimension(0).UpperBound(), 11); 28 // DEALLOCATE(p) 29 RTNAME(PointerDeallocate) 30 (*p, /*hasStat=*/false, /*errMsg=*/nullptr, __FILE__, __LINE__); 31 EXPECT_FALSE(RTNAME(PointerIsAssociated)(*p)); 32 } 33