[cfe-dev] libclang's cursors not visiting body of openmp directives

jandres742 jandres742 at gmail.com
Sat Jan 31 16:20:26 PST 2015


Hi

I'm implementing an AST visitor with cursors and libclang for OpenMP
programs. However, the body of any openmp directive is not being visited.
The compound statement, which should appear as the body of the omp
directive, is identified as an unexposed statement. However, when I remove
the omp directive (or alternatively, when I execute w/o -fopenmp), the body
is identified correctly.

This is my visitor code:

CXChildVisitResult visitor_function(CXCursor cursor, CXCursor parent,
CXClientData client_data) 
{       
	if (clang_Location_isFromMainFile (clang_getCursorLocation (cursor)) != 0) 
	{
		cout << "clang_getCursorKind(cursor) = " << clang_getCursorKind(cursor) <<
endl; 

		  if(clang_getCursorKind(cursor) == CXCursor_FunctionDecl)
		  {
			cout << "Function: " << endl;
		  }

		 else if(clang_getCursorKind(cursor) == CXCursor_VarDecl)
		  {
			cout << "VarDecl: " << endl;
		  }

		 else if(clang_getCursorKind(cursor) == CXCursor_OMPParallelDirective )
	         {
			cout << "CXCursor_OMPParallelDirective: " << endl;
		 }

		 else if(clang_getCursorKind(cursor) == CXCursor_OMPSingleDirective )
		 {
			cout << "CXCursor_OMPSingleDirective: " << endl;
		 }

		 else if(clang_getCursorKind(cursor) == CXCursor_CompoundStmt )
		 {
			cout << "CompoundStmt: " << endl;
		 }
	}

    return CXChildVisit_Recurse;
}

This is my test file:

#include <omp.h>
#include <stdio.h>

int main()
{
  int c = 0;

  #pragma omp parallel
  {
     int a = 9;
     c = 1 + a;
  }

  return c;
}

When executing the visitor using the -fopenmp flag, this is the output:

clang_getCursorKind(cursor) = 8
Function: 
clang_getCursorKind(cursor) = 202
CompoundStmt: 
clang_getCursorKind(cursor) = 231
clang_getCursorKind(cursor) = 9
VarDecl: 
clang_getCursorKind(cursor) = 106
clang_getCursorKind(cursor) = 232
CXCursor_OMPParallelDirective: 
clang_getCursorKind(cursor) = 200
CXCursor_UnexposedStmt 
clang_getCursorKind(cursor) = 101
clang_getCursorKind(cursor) = 214
clang_getCursorKind(cursor) = 100
clang_getCursorKind(cursor) = 101

When executing without the -fopenmp flag, this is the output, which shows
the compound statement belonging to the parallel directive:

clang_getCursorKind(cursor) = 8
Function: 
clang_getCursorKind(cursor) = 202
CompoundStmt: 
clang_getCursorKind(cursor) = 231
clang_getCursorKind(cursor) = 9
VarDecl: 
clang_getCursorKind(cursor) = 106
clang_getCursorKind(cursor) = 202
CompoundStmt: 
clang_getCursorKind(cursor) = 231
clang_getCursorKind(cursor) = 9
VarDecl: 
clang_getCursorKind(cursor) = 106
clang_getCursorKind(cursor) = 114
clang_getCursorKind(cursor) = 101
clang_getCursorKind(cursor) = 114
clang_getCursorKind(cursor) = 106
clang_getCursorKind(cursor) = 100
clang_getCursorKind(cursor) = 101
clang_getCursorKind(cursor) = 214
clang_getCursorKind(cursor) = 100
clang_getCursorKind(cursor) = 101

I'm using the OpenMP/Clang implementation from http://clang-omp.github.io/. 

Any suggestions would be appreciated. Thanks.



--
View this message in context: http://clang-developers.42468.n3.nabble.com/libclang-s-cursors-not-visiting-body-of-openmp-directives-tp4043754.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list