[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: [PATCH] PR15610 : -Wunused-macros warns despite line markers
From: Lubos Lunak <l.lunak () suse ! cz>
Date: 2013-06-30 6:59:23
Message-ID: 201306300859.23923.l.lunak () suse ! cz
[Download RAW message or body]
Hello,
could somebody please review and commit the atached patch for pr15610? Thank
you.
--
Lubos Lunak
l.lunak@suse.cz
["pr15610.patch" (text/x-diff)]
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
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic