[cfe-dev] RFC: [PragmaHandler] Break HandlePragma API to fix location problem?

Joel E. Denny via cfe-dev cfe-dev at lists.llvm.org
Tue May 14 08:35:07 PDT 2019


Hi,

# Problem #

Currently, a pragma AST node's recorded location starts at the
namespace token (such as `omp` in the case of OpenMP) after the
`#pragma` token, and the `#pragma` location isn't available. However,
the `#pragma` location can be useful when, for example, rewriting a
directive using Clang's Rewrite facility.

# Proposed Solution #

As a first step in addressing this issue, I have proposed a patch to
make `#pragma` locations available to any `PragmaHandler` [1].  I have
also proposed a patch to make use of those locations to fix the start
locations of OpenMP AST nodes [2].  Other pragmas can be adjusted in a
similar manner in later patches.

# Question #

The first patch makes a backward-incompatible change in the
`PragmaHandler` API: it alters the parameter list of the
`HandlePragma` callback function.  While the patch also adjusts all
upstream callers, any external plugins using `HandlePragma` would
break, as suggested by documentation for `HandlePragma` in
`clang/docs/ClangPlugins.rst`.

Is that a real concern?  Are there external projects that would not
easily be adjusted?  If so, there are ways we can support both
interfaces [3], but we shouldn't complicate the code otherwise.

Thanks.

Joel

[1]: https://reviews.llvm.org/D61643
[2]: https://reviews.llvm.org/D61509
[3]: https://reviews.llvm.org/D61643#1493864



More information about the cfe-dev mailing list