File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -335,6 +335,10 @@ void AccStructureChecker::Enter(const parser::OpenACCCacheConstruct &x) {
335335 const auto &verbatim = std::get<parser::Verbatim>(x.t );
336336 PushContextAndClauseSets (verbatim.source , llvm::acc::Directive::ACCD_cache);
337337 SetContextDirectiveSource (verbatim.source );
338+ if (loopNestLevel == 0 ) {
339+ context_.Say (verbatim.source ,
340+ " The CACHE directive must be inside a loop" _err_en_US);
341+ }
338342}
339343void AccStructureChecker::Leave (const parser::OpenACCCacheConstruct &x) {
340344 dirContext_.pop_back ();
@@ -655,6 +659,14 @@ void AccStructureChecker::Enter(const parser::SeparateModuleSubprogram &) {
655659 declareSymbols.clear ();
656660}
657661
662+ void AccStructureChecker::Enter (const parser::DoConstruct &) {
663+ ++loopNestLevel;
664+ }
665+
666+ void AccStructureChecker::Leave (const parser::DoConstruct &) {
667+ --loopNestLevel;
668+ }
669+
658670llvm::StringRef AccStructureChecker::getDirectiveName (
659671 llvm::acc::Directive directive) {
660672 return llvm::acc::getOpenACCDirectiveName (directive);
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ class AccStructureChecker
7171 void Enter (const parser::SubroutineSubprogram &);
7272 void Enter (const parser::FunctionSubprogram &);
7373 void Enter (const parser::SeparateModuleSubprogram &);
74+ void Enter (const parser::DoConstruct &);
75+ void Leave (const parser::DoConstruct &);
7476
7577#define GEN_FLANG_CLAUSE_CHECK_ENTER
7678#include " llvm/Frontend/OpenACC/ACC.inc"
@@ -88,6 +90,7 @@ class AccStructureChecker
8890 llvm::StringRef getDirectiveName (llvm::acc::Directive directive) override ;
8991
9092 llvm::SmallDenseSet<Symbol *> declareSymbols;
93+ unsigned loopNestLevel = 0 ;
9194};
9295
9396} // namespace Fortran::semantics
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ program openacc_cache_validity
1919 type (atype), dimension (10 ) :: ta
2020 real (8 ), dimension (N) :: a
2121
22+ do i = 1 , N
23+
2224 ! $acc cache(a(i))
2325 ! $acc cache(a(1:2,3:4))
2426 ! $acc cache(a)
@@ -40,4 +42,9 @@ program openacc_cache_validity
4042 ! ERROR: Only array element or subarray are allowed in CACHE directive
4143 ! $acc cache(/i/)
4244
45+ end do
46+
47+ ! ERROR: The CACHE directive must be inside a loop
48+ ! $acc cache(a)
49+
4350end program openacc_cache_validity
You can’t perform that action at this time.
0 commit comments