-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang] Align same_type_as result to other compilers
Unallocated unlimited polymorphic entities do not have a dynamic type set and do not have declared type. The standard notes that the result is processor dependent when one of the arguments of same_type_as is in this case. Align the result to other compiler (gfortran, nvfortran). Reviewed By: jeanPerier, PeteSteinfeld Differential Revision: https://reviews.llvm.org/D145384
- Loading branch information
1 parent
78e4897
commit 173e54c
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===-- flang/unittests/Runtime/Pointer.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 "gtest/gtest.h" | ||
#include "tools.h" | ||
#include "flang/Runtime/derived-api.h" | ||
#include "flang/Runtime/descriptor.h" | ||
|
||
using namespace Fortran::runtime; | ||
|
||
TEST(Derived, SameTypeAs) { | ||
// INTEGER, POINTER :: i1 | ||
auto i1{ | ||
Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Integer, 4}, 4, | ||
nullptr, 0, nullptr, CFI_attribute_pointer)}; | ||
EXPECT_TRUE(RTNAME(SameTypeAs)(*i1, *i1)); | ||
|
||
auto r1{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, | ||
4, nullptr, 0, nullptr, CFI_attribute_pointer)}; | ||
EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *r1)); | ||
|
||
// CLASS(*), ALLOCATABLE :: p1 | ||
auto p1{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, | ||
4, nullptr, 0, nullptr, CFI_attribute_allocatable)}; | ||
p1->raw().elem_len = 0; | ||
p1->raw().type = CFI_type_other; | ||
|
||
EXPECT_TRUE(RTNAME(SameTypeAs)(*i1, *p1)); | ||
EXPECT_TRUE(RTNAME(SameTypeAs)(*p1, *i1)); | ||
EXPECT_TRUE(RTNAME(SameTypeAs)(*r1, *p1)); | ||
|
||
// CLASS(*), ALLOCATABLE :: p2 | ||
auto p2{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, | ||
4, nullptr, 0, nullptr, CFI_attribute_allocatable)}; | ||
p2->raw().elem_len = 0; | ||
p2->raw().type = CFI_type_other; | ||
|
||
EXPECT_TRUE(RTNAME(SameTypeAs)(*p1, *p2)); | ||
} |