Skip to content

Commit bd89b72

Browse files
committed
simplify
1 parent 5569917 commit bd89b72

File tree

5 files changed

+31
-89
lines changed

5 files changed

+31
-89
lines changed

flang/include/flang/Evaluate/variable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct DataRef {
289289
const Symbol &GetLastSymbol() const;
290290
std::optional<Expr<SubscriptInteger>> LEN() const;
291291
llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
292-
bool IsPathFrom(const DataRef &) const;
292+
293293
std::variant<SymbolRef, Component, ArrayRef, CoarrayRef> u;
294294
};
295295

@@ -400,7 +400,7 @@ template <typename T> class Designator {
400400
const Symbol *GetLastSymbol() const;
401401
std::optional<Expr<SubscriptInteger>> LEN() const;
402402
llvm::raw_ostream &AsFortran(llvm::raw_ostream &o) const;
403-
bool IsPathFrom(const Designator<T> &) const;
403+
404404
Variant u;
405405
};
406406

flang/lib/Evaluate/variable.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -751,70 +751,6 @@ bool DescriptorInquiry::operator==(const DescriptorInquiry &that) const {
751751
return field_ == that.field_ && base_ == that.base_ &&
752752
dimension_ == that.dimension_;
753753
}
754-
#include <type_traits>
755-
#include <utility>
756-
template <typename T, typename = void> struct has_union : std::false_type {};
757-
template <typename T>
758-
struct has_union<T, std::void_t<decltype(T::u)>> : std::true_type {};
759-
template <typename T, typename = void> struct has_base : std::false_type {};
760-
template <typename T>
761-
struct has_base<T, std::void_t<decltype(std::declval<T>().base())>>
762-
: std::true_type {};
763-
template <typename T, typename = void>
764-
struct has_GetFirstSymbol : std::false_type {};
765-
template <typename T>
766-
struct has_GetFirstSymbol<T,
767-
std::void_t<decltype(std::declval<T>().GetFirstSymbol())>>
768-
: std::true_type {};
769-
770-
template <typename P, typename R>
771-
bool TestVariableIsPathFromRoot(const P &path, const R &root) {
772-
const SymbolRef *pathSym{nullptr}, *rootSym{nullptr};
773-
if constexpr (has_union<P>::value) {
774-
pathSym = std::get_if<SymbolRef>(&path.u);
775-
}
776-
if constexpr (has_union<R>::value) {
777-
rootSym = std::get_if<SymbolRef>(&root.u);
778-
}
779-
if (pathSym) {
780-
return rootSym && AreSameSymbol(*rootSym, *pathSym);
781-
}
782-
if constexpr (has_GetFirstSymbol<P>::value) {
783-
if (rootSym) {
784-
return AreSameSymbol(path.GetFirstSymbol(), *rootSym);
785-
}
786-
}
787-
if constexpr (std::is_same_v<P, R>) {
788-
if (path == root) {
789-
return true;
790-
}
791-
}
792-
if constexpr (has_base<P>::value) {
793-
return TestVariableIsPathFromRoot(path.base(), root);
794-
}
795-
if constexpr (has_union<P>::value) {
796-
return common::visit(
797-
common::visitors{
798-
[&](const auto &x) { return TestVariableIsPathFromRoot(x, root); },
799-
},
800-
path.u);
801-
}
802-
return false;
803-
}
804-
805-
bool DataRef::IsPathFrom(const DataRef &that) const {
806-
return TestVariableIsPathFromRoot(*this, that);
807-
}
808-
809-
template <typename T>
810-
bool Designator<T>::IsPathFrom(const Designator<T> &that) const {
811-
return TestVariableIsPathFromRoot(*this, that);
812-
}
813-
814-
template <typename T, typename U>
815-
optional<bool> Designator<T>::IsSameEntity(const Designator<U> &that) const {
816-
return std::nullopt;
817-
}
818754

819755
#ifdef _MSC_VER // disable bogus warning about missing definitions
820756
#pragma warning(disable : 4661)

flang/lib/Semantics/check-allocate.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -471,26 +471,13 @@ static bool HaveCompatibleLengths(
471471
}
472472

473473
bool IsSameAllocation(const SomeExpr *root, const SomeExpr *path) {
474-
if (root) {
475-
if (std::optional<evaluate::DataRef> rootRef{ExtractDataRef(root)}) {
476-
if (path) {
477-
if (std::optional<evaluate::DataRef> pathRef{ExtractDataRef(path)}) {
478-
if (pathRef->IsPathFrom(*rootRef)) {
479-
return true;
480-
}
481-
} else {
482-
if (*root == *path) {
483-
return true;
484-
}
485-
}
486-
}
487-
} else {
488-
if (path && *root == *path) {
489-
return true;
490-
}
491-
}
474+
if (root && path) {
475+
// For now we just use equality of expressions. If we implement a more
476+
// sophisticated alias analysis we should use it here.
477+
return *root == *path;
478+
} else {
479+
return false;
492480
}
493-
return false;
494481
}
495482

496483
bool AllocationCheckerHelper::RunChecks(SemanticsContext &context) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenacc -pedantic
2+
3+
module mm_acc_rout_function
4+
contains
5+
integer function dosomething(res)
6+
!$acc routine seq
7+
integer :: res
8+
dosomething = res + 1
9+
end function
10+
end module
11+
12+
program main
13+
use mm_acc_rout_function
14+
implicit none
15+
integer :: res = 1
16+
!$acc serial default(none) copy(res)
17+
res = dosomething(res)
18+
!$acc end serial
19+
end program

flang/test/Semantics/allocate14.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ program allocate14
4646
!ERROR: ERRMSG variable in DEALLOCATE must not be the variable being deallocated
4747
deallocate(tt(2)%msg, stat=tt(2)%i, errmsg=tt(2)%msg)
4848

49-
!ERROR: STAT variable in ALLOCATE must not be the variable being allocated
50-
!ERROR: ERRMSG variable in ALLOCATE must not be the variable being allocated
49+
!TODO: STAT variable in ALLOCATE must not be the variable being allocated
50+
!TODO: ERRMSG variable in ALLOCATE must not be the variable being allocated
5151
allocate(ts(10), stat=ts(1)%i, errmsg=ts(1)%msg)
52-
!ERROR: STAT variable in DEALLOCATE must not be the variable being deallocated
53-
!ERROR: ERRMSG variable in DEALLOCATE must not be the variable being deallocated
52+
!TODO: STAT variable in DEALLOCATE must not be the variable being deallocated
53+
!TODO: ERRMSG variable in DEALLOCATE must not be the variable being deallocated
5454
deallocate(ts, stat=ts(1)%i, errmsg=ts(1)%msg)
5555
end program
5656

0 commit comments

Comments
 (0)