[cfe-commits] r123767 - in /cfe/trunk: lib/Lex/PPDirectives.cpp test/Preprocessor/warn-macro-unused.c
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Jan 18 11:50:16 PST 2011
Author: akirtzidis
Date: Tue Jan 18 13:50:15 2011
New Revision: 123767
URL: http://llvm.org/viewvc/llvm-project?rev=123767&view=rev
Log:
When redefining a macro don't warn twice if it's not used and don't warn for duplicate
definition by command line options. Fixes rdar://8875916.
Added:
cfe/trunk/test/Preprocessor/warn-macro-unused.c
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=123767&r1=123766&r2=123767&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Jan 18 13:50:15 2011
@@ -1527,7 +1527,7 @@
// then don't bother calling MacroInfo::isIdenticalTo.
if (!getDiagnostics().getSuppressSystemWarnings() ||
!SourceMgr.isInSystemHeader(DefineTok.getLocation())) {
- if (!OtherMI->isUsed())
+ if (!OtherMI->isUsed() && OtherMI->isWarnIfUnused())
Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used);
// Macros must be identical. This means all tokens and whitespace
@@ -1539,6 +1539,8 @@
Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
}
}
+ if (OtherMI->isWarnIfUnused())
+ WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
ReleaseMacroInfo(OtherMI);
}
Added: cfe/trunk/test/Preprocessor/warn-macro-unused.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/warn-macro-unused.c?rev=123767&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/warn-macro-unused.c (added)
+++ cfe/trunk/test/Preprocessor/warn-macro-unused.c Tue Jan 18 13:50:15 2011
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -Wunused-macros -Dfoo -Dfoo -verify
+
+#define unused // expected-warning {{macro is not used}}
+#define unused
+unused
More information about the cfe-commits
mailing list