[PATCH] D61509: [PragmaHandler][OpenMP] Expose `#pragma` location

Joel E. Denny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 07:40:53 PDT 2019


jdenny created this revision.
jdenny added reviewers: ABataev, rnk, Eugene.Zelenko, akyrtzi, rsmith.
Herald added subscribers: jdoerfert, dexonsmith, guansong.
Herald added a project: clang.

Currently, an OpenMP AST node's recorded location starts at the `omp`
token after the `#pragma` token, and the `#pragma` location isn't
available anywhere that I have found.  However, the `#pragma` location
can be useful when, for example, rewriting a directive using Clang's
Rewrite facility.

This patch makes `#pragma` locations available in any `PragmaHandler`.
However, this patch is incomplete as it does not actually use those
locations.  I'd like to extend the OpenMP implementation to use it, 
but I see two possible approaches, and I need feedback to choose one:

1. Extend `PragmaOpenMPHandler` to set the location of `tok::annot_pragma_openmp` to the `#pragma` location so that the `#pragma` location then becomes the start location of the OpenMP AST node.  The drawback here is that locations in many tests, especially `-ast-dump` tests, will need to be updated, and it's not clear to me if any external AST user depends on the existing locations.

2. Extend `PragmaOpenMPHandler` to insert a new token, perhaps named `tok::annot_pragma_openmp_intro`, before `tok::annot_pragma_openmp` and store both their locations in each OpenMP AST node.  The new location would be accessed by new member functions so that users of the old location wouldn't see a change.  The drawback here is that a lot of the OpenMP AST node construction code will need to be updated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61509

Files:
  clang/include/clang/Lex/Pragma.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Parse/ParsePragma.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61509.198000.patch
Type: text/x-patch
Size: 33449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190503/ffe3e263/attachment-0001.bin>


More information about the cfe-commits mailing list