File tree Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Original file line number Diff line number Diff line change @@ -1695,17 +1695,23 @@ void AccAttributeVisitor::Post(const parser::Name &name) {
16951695
16961696Symbol *AccAttributeVisitor::ResolveAccCommonBlockName (
16971697    const  parser::Name *name) {
1698-   if  (auto  *prev{name
1699-               ? GetContext ().scope .parent ().FindCommonBlock (name->source )
1700-               : nullptr }) {
1701-     name->symbol  = prev;
1702-     return  prev;
1703-   }
1704-   //  Check if the Common Block is declared in the current scope
1705-   if  (auto  *commonBlockSymbol{
1706-           name ? GetContext ().scope .FindCommonBlock (name->source ) : nullptr }) {
1707-     name->symbol  = commonBlockSymbol;
1708-     return  commonBlockSymbol;
1698+   if  (!name) {
1699+     return  nullptr ;
1700+   }
1701+   //  Check the local and surrounding scopes first
1702+   if  (auto  *cb{GetProgramUnitOrBlockConstructContaining (GetContext ().scope )
1703+               .FindCommonBlock (name->source )}) {
1704+     name->symbol  = cb;
1705+     return  cb;
1706+   }
1707+   //  Look for COMMON block in the modules
1708+   for  (const  Scope &childScope : context_.globalScope ().children ()) {
1709+     if  (childScope.kind () == Scope::Kind::Module) {
1710+       if  (auto  *cb{childScope.FindCommonBlock (name->source )}) {
1711+         name->symbol  = cb;
1712+         return  cb;
1713+       }
1714+     }
17091715  }
17101716  return  nullptr ;
17111717}
@@ -1755,8 +1761,8 @@ void AccAttributeVisitor::ResolveAccObject(
17551761              }
17561762            } else  {
17571763              context_.Say (name.source ,
1758-                   " COMMON block must be declared  in the same scoping unit  " 
1759-                   " in which the OpenACC directive or clause appears " _err_en_US );
1764+                   " Could not find  COMMON block '%s' used  in OpenACC directive " _err_en_US, 
1765+                   name. ToString () );
17601766            }
17611767          },
17621768      },
Original file line number Diff line number Diff line change 1+ !  RUN: %python %S/../test_errors.py %s %flang -fopenacc
2+ module  acc_common_decl
3+   implicit none 
4+   integer  a
5+   common  / a_common/  a
6+ ! $acc declare create (/a_common/)
7+   data  a/ 42 / 
8+ end module  acc_common_decl
9+ 
10+ program  acc_decl_test
11+   use  acc_common_decl
12+   implicit none 
13+ 
14+   a =  1 
15+ ! $acc update device (/a_common/)
16+   a =  2 
17+ ! ERROR: Could not find COMMON block 'a_common_bad' used in OpenACC directive
18+ ! $acc update device (/a_common_bad/)
19+ end program 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments