End location of OpenMP Clauses

Hello everybody,

I have question regarding the source location of an OpenMP clause. Given the following code:

int main() {
  int n = 42;
  int m = 23;
  float f = 42.23;

  #pragma omp target parallel map(n) num_threads(2) if(1) shared(n,m) private(f) default(shared) proc_bind(spread)
  {
    f = n / m;
  }

  return 0;
}

I get the following AST (snippet):

    >-OMPTargetParallelDirective 0x77aaf0 <line:6:11, col:116>
    > >-OMPMapClause 0x7643a0 <col:31, col:38>
    > > `-DeclRefExpr 0x764378 <col:35> 'int' lvalue Var 0x764168 'n' 'int'
    > >-OMPNum_threadsClause 0x764420 <col:38, col:51>
    > > `-IntegerLiteral 0x764400 <col:50> 'int' 2
    > >-OMPIfClause 0x764468 <col:53, col:57>
    > > `-IntegerLiteral 0x764448 <col:56> 'int' 1
    > >-OMPSharedClause 0x7644f0 <col:59, col:71>
    > > >-DeclRefExpr 0x7644a0 <col:66> 'int' lvalue Var 0x764168 'n' 'int'
    > > `-DeclRefExpr 0x7644c8 <col:68> 'int' lvalue Var 0x764218 'm' 'int'
    > >-OMPPrivateClause 0x7645e0 <col:71, col:83>
    > > `-DeclRefExpr 0x764518 <col:79> 'float' lvalue Var 0x7642c8 'f' 'float'
    > >-OMPDefaultClause 0x764608 <col:83, col:99>
    > >-OMPProc_bindClause 0x764620 <col:99, col:116>

As you can see, the end of the clauses 'map', 'num_threads', 'shared', 'private' point just before the start of the next token (clause). In contrast, the end of the clauses 'if', 'default' and 'proc_bind' points just before the right paren. The problem is that "clang::OMPClause::getLocEnd()" returns different locations, depending on the clause kind. I guess this does not look like intended.

My question is: Where should "clang::OMPClause::getLocEnd()" point to? After or before the left paren?

A quick look into "lib/Parse/ParseOpenMP.cpp" shows that in one case "Tok.getLocation()" is used and in the other cases "T.getCloseLocation()". What is correct?

Best regards,

Tim Cramer

Hi, ‘if’ etc. clauses are correct, ‘map’ etc are not. I’ll fix that, thanks for the report.

Hi, thank you!

Fixed in r336460