diff options
author | Serge Guelton <sguelton@redhat.com> | 2019-02-01 06:11:44 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@redhat.com> | 2019-02-01 06:11:44 +0000 |
commit | 375167e36f900483c5ab28d86cb57b703f90fee2 (patch) | |
tree | 1246a5a8614e619059b85b8d1874968f10d2d466 /include/clang/Basic/SourceManager.h | |
parent | 5e9410946b21b33b3a947a91d5da342a6a14b680 (diff) | |
download | clang-375167e36f900483c5ab28d86cb57b703f90fee2.tar.gz |
Fix isInSystemMacro to handle pasted macros
Token pasted by the preprocessor (through ##) have a Spelling pointing to scratch buffer.
As a result they are not recognized at system macro, even though the pasting happened in
a system macro. Fix that by looking into the parent macro if the original lookup finds a
scratch buffer.
Differential Revision: https://reviews.llvm.org/D55782
This effectively fixes https://bugs.llvm.org/show_bug.cgi?id=35268,
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352838 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index ba829a8773..b45357e645 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -1440,6 +1440,12 @@ public: return Filename.equals("<command line>"); } + /// Returns whether \p Loc is located in a <scratch space> file. + bool isWrittenInScratchSpace(SourceLocation Loc) const { + StringRef Filename(getPresumedLoc(Loc).getFilename()); + return Filename.equals("<scratch space>"); + } + /// Returns if a SourceLocation is in a system header. bool isInSystemHeader(SourceLocation Loc) const { return isSystem(getFileCharacteristic(Loc)); @@ -1452,7 +1458,17 @@ public: /// Returns whether \p Loc is expanded from a macro in a system header. bool isInSystemMacro(SourceLocation loc) const { - return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc)); + if(!loc.isMacroID()) + return false; + + // 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. + if (isWrittenInScratchSpace(getSpellingLoc(loc))) { + return isInSystemHeader(getSpellingLoc(getImmediateMacroCallerLoc(loc))); + } + else { + return isInSystemHeader(getSpellingLoc(loc)); + } } /// The size of the SLocEntry that \p FID represents. |