]> granicus.if.org Git - clang/commitdiff
Handle locations coming from macro instantiations properly in SourceManager::isBefore...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 24 Dec 2010 02:53:53 +0000 (02:53 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 24 Dec 2010 02:53:53 +0000 (02:53 +0000)
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

lib/Basic/SourceManager.cpp
test/Preprocessor/pragma_diagnostic_sections.cpp

index 54bdfd316604814e7a5cd6dff7b1806475289c5a..409851f108c8ced297702a1f98b0e95b1e2dac6e 100644 (file)
@@ -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<FileID, unsigned> LOffs = getDecomposedLoc(LHS);
   std::pair<FileID, unsigned> ROffs = getDecomposedLoc(RHS);
 
index 00163938cc52f9d43deac0a452580d085abe84ca..3349bdcf0835c0365d98148f0d112b441ece0145 100644 (file)
@@ -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
+
+//------------------------------------------------------------------------------