[flang-commits] [flang] 9b1915c - [flang] Allow compiler directives for collapsed loops in OpenACC
Daniil Dudkin via flang-commits
flang-commits at lists.llvm.org
Mon Aug 29 08:19:41 PDT 2022
Author: Daniil Dudkin
Date: 2022-08-29T18:17:56+03:00
New Revision: 9b1915cd0a52e785b29021dc3329265345d2b068
URL: https://github.com/llvm/llvm-project/commit/9b1915cd0a52e785b29021dc3329265345d2b068
DIFF: https://github.com/llvm/llvm-project/commit/9b1915cd0a52e785b29021dc3329265345d2b068.diff
LOG: [flang] Allow compiler directives for collapsed loops in OpenACC
If one tries to compile the attached test case code with flan,
the one will get an internal compiler error on `CHECK(level == 0)`
at the end of `PrivatizeAssociatedLoopIndex` function.
Other compilers (gfortran and nvfortran) build this code just fine.
This change fixes the ICE.
Reviewed By: clementval
Differential Revision: https://reviews.llvm.org/D132846
Added:
flang/test/Semantics/OpenACC/acc-resolve03.f90
Modified:
flang/lib/Semantics/resolve-directives.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 5926dd0c5d149..5f34061e9a3b6 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -868,6 +868,21 @@ void AccAttributeVisitor::PrivatizeAssociatedLoopIndex(
}
Symbol::Flag ivDSA{Symbol::Flag::AccPrivate};
+ const auto getNextDoConstruct =
+ [this](const parser::Block &block) -> const parser::DoConstruct * {
+ for (const auto &entry : block) {
+ if (const auto *doConstruct = GetDoConstructIf(entry)) {
+ return doConstruct;
+ } else if (parser::Unwrap<parser::CompilerDirective>(entry)) {
+ // It is allowed to have a compiler directive associated with the loop.
+ continue;
+ } else {
+ break;
+ }
+ }
+ return nullptr;
+ };
+
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0; --level) {
// go through all the nested do-loops and resolve index variables
@@ -879,8 +894,7 @@ void AccAttributeVisitor::PrivatizeAssociatedLoopIndex(
}
const auto &block{std::get<parser::Block>(loop->t)};
- const auto it{block.begin()};
- loop = it != block.end() ? GetDoConstructIf(*it) : nullptr;
+ loop = getNextDoConstruct(block);
}
CHECK(level == 0);
}
diff --git a/flang/test/Semantics/OpenACC/acc-resolve03.f90 b/flang/test/Semantics/OpenACC/acc-resolve03.f90
new file mode 100644
index 0000000000000..341e9d2ce68b2
--- /dev/null
+++ b/flang/test/Semantics/OpenACC/acc-resolve03.f90
@@ -0,0 +1,21 @@
+! RUN: %flang_fc1 -fopenacc %s
+! A regression test to check that
+! arbitrary compiler directives do not generate errors
+! inside OpenACC collapsed loops
+subroutine foo
+ integer, parameter :: loop_bound = 42
+ integer :: a
+ integer :: b
+ integer :: c
+
+ !$acc parallel
+ do a = 0, loop_bound
+ !$acc loop collapse(2)
+ do b = 0, loop_bound
+ !dir$ ivdep
+ do c = 0, loop_bound
+ enddo
+ enddo
+ enddo
+ !$acc end parallel
+end subroutine foo
More information about the flang-commits
mailing list