From: Argyrios Kyrtzidis Date: Fri, 24 Dec 2010 02:53:53 +0000 (+0000) Subject: Handle locations coming from macro instantiations properly in SourceManager::isBefore... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee933e1cc2718bd829c4649d060fc9f686005990;p=clang Handle locations coming from macro instantiations properly in SourceManager::isBeforeInTranslationUnit(). Fixes rdar://8790245 and http://llvm.org/PR8821. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122536 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 54bdfd3166..409851f108 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -1198,6 +1198,13 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, if (LHS == RHS) return false; + // If both locations are macro instantiations, the order of their offsets + // reflect the order that the tokens, pointed to by these locations, were + // instantiated (during parsing each token that is instantiated by a macro, + // expands the SLocEntries). + if (LHS.isMacroID() && RHS.isMacroID()) + return LHS.getOffset() < RHS.getOffset(); + std::pair LOffs = getDecomposedLoc(LHS); std::pair ROffs = getDecomposedLoc(RHS); diff --git a/test/Preprocessor/pragma_diagnostic_sections.cpp b/test/Preprocessor/pragma_diagnostic_sections.cpp index 00163938cc..3349bdcf08 100644 --- a/test/Preprocessor/pragma_diagnostic_sections.cpp +++ b/test/Preprocessor/pragma_diagnostic_sections.cpp @@ -68,3 +68,13 @@ struct S2 { }; //------------------------------------------------------------------------------ + +// rdar://8790245 +#define MYMACRO \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") \ + _Pragma("clang diagnostic pop") +MYMACRO +#undef MYMACRO + +//------------------------------------------------------------------------------