From cfe-commits Sun Jun 30 06:59:23 2013 From: Lubos Lunak Date: Sun, 30 Jun 2013 06:59:23 +0000 To: cfe-commits Subject: [PATCH] PR15610 : -Wunused-macros warns despite line markers Message-Id: <201306300859.23923.l.lunak () suse ! cz> X-MARC-Message: https://marc.info/?l=cfe-commits&m=137257572722050 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_Ld9zRVaH2rc57gB" --Boundary-00=_Ld9zRVaH2rc57gB Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, could somebody please review and commit the atached patch for pr15610? Thank you. -- Lubos Lunak l.lunak@suse.cz --Boundary-00=_Ld9zRVaH2rc57gB Content-Type: text/x-diff; charset="iso 8859-15"; name="pr15610.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pr15610.patch" 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 + --Boundary-00=_Ld9zRVaH2rc57gB Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits --Boundary-00=_Ld9zRVaH2rc57gB--