[PATCH] D55782: Fix isInSystemMacro to handle pasted token

serge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 30 04:42:21 PST 2019


serge-sans-paille marked 2 inline comments as done.
serge-sans-paille added inline comments.


================
Comment at: include/clang/Basic/SourceManager.h:1458-1460
+	    // This happens when the macro is the result of a paste, in that case
+	    // its spelling is the scratch memory, so we take the parent context.
+            isInSystemHeader(getSpellingLoc(getImmediateMacroCallerLoc(loc))));
----------------
rsmith wrote:
> I think this also matches things like:
> 
> ```
> // system header
> #define BAR FOO
> 
> // user code
> #define FOO x
> BAR
> ```
> 
> ... where the location of `x` token produced by the `BAR` macro will now be considered to be in a system macro. Can you make this more targeted? (Maybe we could change the `SLocEntry` for the token-paste scratch buffer to be considered a system header if the `##` token is in a system macro -- that'll need the preprocessor to store two `ScratchBuffer`s, one for system headers and one for user code, but that seems acceptable.)
Thanks for the advice! This approach should be more efficient and avoid the situation you point out - I've added a test case to illustrate that.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55782/new/

https://reviews.llvm.org/D55782





More information about the cfe-commits mailing list