Hello,

 could somebody please review and commit the atached patch for pr15610? Thank 
you.

-- 
 Lubos Lunak
 [email protected]
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 026a7e7..09016a8 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -2028,8 +2028,13 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok,
   if (isInPrimaryFile() && // don't warn for include'd macros.
       Diags->getDiagnosticLevel(diag::pp_macro_not_used,
           MI->getDefinitionLoc()) != DiagnosticsEngine::Ignored) {
-    MI->setIsWarnIfUnused(true);
-    WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
+    SourceManager &SM = getSourceManager();
+    PresumedLoc PLoc = SM.getPresumedLoc(MI->getDefinitionLoc());
+    // Do not warn if #line markers say it is not the main file.
+    if (PLoc.isValid() && !PLoc.getIncludeLoc().isValid()) {
+      MI->setIsWarnIfUnused(true);
+      WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
+    }
   }
 
   // If the callbacks want to know, tell them about the macro definition.
diff --git a/test/Preprocessor/warn-macro-unused.c b/test/Preprocessor/warn-macro-unused.c
index c33aeb5..30c8800 100644
--- a/test/Preprocessor/warn-macro-unused.c
+++ b/test/Preprocessor/warn-macro-unused.c
@@ -8,3 +8,7 @@ unused
 
 // rdar://9745065
 #undef unused_from_header // no warning
+
+# 1 "other.c" 1
+#define unused_but_not_main_file // no warning
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to