diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-07-08 07:01:00 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-07-08 07:01:00 +0000 |
| commit | e8eef3207bfbc5de2fcca22d6172544d9e13ca6c (patch) | |
| tree | 0d92ca4c1cc667d4da48ced30f65c8085ba98c01 /clang | |
| parent | 8ff7199e4b9fed8c4c5b75e8931974fce0dc084c (diff) | |
| download | bcm5719-llvm-e8eef3207bfbc5de2fcca22d6172544d9e13ca6c.tar.gz bcm5719-llvm-e8eef3207bfbc5de2fcca22d6172544d9e13ca6c.zip | |
add infrastructure for warning if redef'd macro bodies differ, but don't
fully implement it.
Fix warning on #define __LINE__ to warn about redefinition, not #undef.
llvm-svn: 38679
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/Lex/MacroInfo.cpp | 7 | ||||
| -rw-r--r-- | clang/Lex/Preprocessor.cpp | 21 | ||||
| -rw-r--r-- | clang/clang.xcodeproj/project.pbxproj | 2 | ||||
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticKinds.def | 6 | ||||
| -rw-r--r-- | clang/include/clang/Lex/MacroInfo.h | 5 | ||||
| -rw-r--r-- | clang/include/clang/Lex/Preprocessor.h | 2 |
6 files changed, 33 insertions, 10 deletions
diff --git a/clang/Lex/MacroInfo.cpp b/clang/Lex/MacroInfo.cpp index 9cd46dbdaec..28579a46bc0 100644 --- a/clang/Lex/MacroInfo.cpp +++ b/clang/Lex/MacroInfo.cpp @@ -15,3 +15,10 @@ #include <iostream> using namespace llvm; using namespace clang; + +/// isEqualTo - Return true if the specified macro definition is equal to this +/// macro in spelling, arguments, and whitespace. This is used to emit +/// duplicate definition warnings. +bool MacroInfo::isEqualTo(const MacroInfo &Other) const { + return true; +} diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp index 86b9d9c1bdc..66acd6c7bd5 100644 --- a/clang/Lex/Preprocessor.cpp +++ b/clang/Lex/Preprocessor.cpp @@ -839,10 +839,10 @@ void Preprocessor::DiscardUntilEndOfDirective() { /// ReadMacroName - Lex and validate a macro name, which occurs after a /// #define or #undef. This sets the token kind to eom and discards the rest -/// of the macro line if the macro name is invalid. isDefineUndef is true if -/// this is due to a a #define or #undef directive, false if it is something +/// of the macro line if the macro name is invalid. isDefineUndef is 1 if +/// this is due to a a #define, 2 if #undef directive, 0 if it is something /// else (e.g. #ifdef). -void Preprocessor::ReadMacroName(LexerToken &MacroNameTok, bool isDefineUndef) { +void Preprocessor::ReadMacroName(LexerToken &MacroNameTok, char isDefineUndef) { // Read the token, don't allow macro expansion on it. LexUnexpandedToken(MacroNameTok); @@ -864,7 +864,10 @@ void Preprocessor::ReadMacroName(LexerToken &MacroNameTok, bool isDefineUndef) { } else if (isDefineUndef && II->getMacroInfo() && II->getMacroInfo()->isBuiltinMacro()) { // Error if defining "__LINE__" and other builtins: C99 6.10.8.4. - Diag(MacroNameTok, diag::pp_undef_builtin_macro); + if (isDefineUndef == 1) + Diag(MacroNameTok, diag::pp_redef_builtin_macro); + else + Diag(MacroNameTok, diag::pp_undef_builtin_macro); } else { // Okay, we got a good identifier node. Return it. return; @@ -1322,7 +1325,7 @@ void Preprocessor::HandleDefineDirective(LexerToken &DefineTok) { ++NumDefined; LexerToken MacroNameTok; - ReadMacroName(MacroNameTok, true); + ReadMacroName(MacroNameTok, 1); // Error reading macro name? If so, diagnostic already issued. if (MacroNameTok.getKind() == tok::eom) @@ -1396,9 +1399,13 @@ void Preprocessor::HandleDefineDirective(LexerToken &DefineTok) { if (!OtherMI->isUsed()) Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used); - // FIXME: Verify the definition is the same. // Macros must be identical. This means all tokes and whitespace separation // must be the same. + if (!MI->isEqualTo(*OtherMI)) { + Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef, + MacroNameTok.getIdentifierInfo()->getName()); + Diag(OtherMI->getDefinitionLoc(), diag::ext_pp_macro_redef2); + } delete OtherMI; } @@ -1412,7 +1419,7 @@ void Preprocessor::HandleUndefDirective(LexerToken &UndefTok) { ++NumUndefined; LexerToken MacroNameTok; - ReadMacroName(MacroNameTok, true); + ReadMacroName(MacroNameTok, 2); // Error reading macro name? If so, diagnostic already issued. if (MacroNameTok.getKind() == tok::eom) diff --git a/clang/clang.xcodeproj/project.pbxproj b/clang/clang.xcodeproj/project.pbxproj index 81c366b830f..dbc9d513ac9 100644 --- a/clang/clang.xcodeproj/project.pbxproj +++ b/clang/clang.xcodeproj/project.pbxproj @@ -92,7 +92,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; }; + 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; }; DEAEE98A0A5A2B970045101B /* MultipleIncludeOpt.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MultipleIncludeOpt.h; sourceTree = "<group>"; }; DEAEECAC0A5AF0E30045101B /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = clang.h; sourceTree = "<group>"; }; DEAEECD40A5AF1FE0045101B /* PrintPreprocessedOutput.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PrintPreprocessedOutput.cpp; sourceTree = "<group>"; }; diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def index fbf2c7c813a..df5c32e1756 100644 --- a/clang/include/clang/Basic/DiagnosticKinds.def +++ b/clang/include/clang/Basic/DiagnosticKinds.def @@ -115,7 +115,11 @@ DIAG(ext_pp_comma_expr, EXTENSION, "comma operator in operand of #if") DIAG(ext_pp_bad_vaargs_use, EXTENSION, "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro") - +DIAG(ext_pp_macro_redef, EXTENSION, + "\"%s\" macro redefined") +DIAG(ext_pp_macro_redef2, EXTENSION, + "this is previous definition") + DIAG(ext_pp_base_file, EXTENSION, "__BASE_FILE__ is a language extension") DIAG(ext_pp_include_level, EXTENSION, diff --git a/clang/include/clang/Lex/MacroInfo.h b/clang/include/clang/Lex/MacroInfo.h index bb92ec965d9..ca668a5ae6a 100644 --- a/clang/include/clang/Lex/MacroInfo.h +++ b/clang/include/clang/Lex/MacroInfo.h @@ -57,6 +57,11 @@ public: /// SourceLocation getDefinitionLoc() const { return Location; } + /// isEqualTo - Return true if the specified macro definition is equal to this + /// macro in spelling, arguments, and whitespace. This is used to emit + /// duplicate definition warnings. + bool isEqualTo(const MacroInfo &Other) const; + /// setIsBuiltinMacro - Set or clear the isBuiltinMacro flag. /// void setIsBuiltinMacro(bool Val = true) { diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 7a65c82cad2..ef2b662c730 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -421,7 +421,7 @@ private: /// ReadMacroName - Lex and validate a macro name, which occurs after a /// #define or #undef. This emits a diagnostic, sets the token kind to eom, /// and discards the rest of the macro line if the macro name is invalid. - void ReadMacroName(LexerToken &MacroNameTok, bool isDefineUndef = false); + void ReadMacroName(LexerToken &MacroNameTok, char isDefineUndef = 0); /// SkipExcludedConditionalBlock - We just read a #if or related directive and /// decided that the subsequent tokens are in the #if'd out portion of the |

