summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPLexerChange.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2013-06-12 21:20:57 +0000
committerRichard Trieu <rtrieu@google.com>2013-06-12 21:20:57 +0000
commit33a4b3db0de5fbba06264a46f560220b5f8f11a8 (patch)
treebe7f0fa608cba875aadb51581141eb56cff06290 /clang/lib/Lex/PPLexerChange.cpp
parent2bb2aa27bfe729aa6d60b17cfafeaa959c7ea050 (diff)
downloadbcm5719-llvm-33a4b3db0de5fbba06264a46f560220b5f8f11a8.tar.gz
bcm5719-llvm-33a4b3db0de5fbba06264a46f560220b5f8f11a8.zip
Introducing -Wheader-guard, a warning that checks header guards actually work
properly. This warning checks that the #ifndef and #define directives at the beginning of a header refer to the same macro name. Includes a fix-it hint to correct the header guard. llvm-svn: 183867
Diffstat (limited to 'clang/lib/Lex/PPLexerChange.cpp')
-rw-r--r--clang/lib/Lex/PPLexerChange.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 64373362461..e521032bca3 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -244,8 +244,29 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
CurPPLexer->MIOpt.GetControllingMacroAtEndOfFile()) {
// Okay, this has a controlling macro, remember in HeaderFileInfo.
if (const FileEntry *FE =
- SourceMgr.getFileEntryForID(CurPPLexer->getFileID()))
+ SourceMgr.getFileEntryForID(CurPPLexer->getFileID())) {
HeaderInfo.SetFileControllingMacro(FE, ControllingMacro);
+ if (const IdentifierInfo *DefinedMacro =
+ CurPPLexer->MIOpt.GetDefinedMacro()) {
+ if (!ControllingMacro->hasMacroDefinition() &&
+ DefinedMacro != ControllingMacro &&
+ HeaderInfo.FirstTimeLexingFile(FE)) {
+ // Emit a warning for a bad header guard.
+ Diag(CurPPLexer->MIOpt.GetMacroLocation(),
+ diag::warn_header_guard)
+ << CurPPLexer->MIOpt.GetMacroLocation()
+ << ControllingMacro;
+ Diag(CurPPLexer->MIOpt.GetDefinedLocation(),
+ diag::note_header_guard)
+ << CurPPLexer->MIOpt.GetDefinedLocation()
+ << DefinedMacro
+ << ControllingMacro
+ << FixItHint::CreateReplacement(
+ CurPPLexer->MIOpt.GetDefinedLocation(),
+ ControllingMacro->getName());
+ }
+ }
+ }
}
}
OpenPOWER on IntegriCloud