[cfe-commits] r38679 - in /cfe/cfe/trunk: Lex/MacroInfo.cpp Lex/Preprocessor.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/DiagnosticKinds.def include/clang/Lex/MacroInfo.h include/clang/Lex/Preprocessor.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:23:45 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:45 2007
New Revision: 38679
URL: http://llvm.org/viewvc/llvm-project?rev=38679&view=rev
Log:
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.
Modified:
cfe/cfe/trunk/Lex/MacroInfo.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/cfe/trunk/include/clang/Lex/MacroInfo.h
cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
Modified: cfe/cfe/trunk/Lex/MacroInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/MacroInfo.cpp?rev=38679&r1=38678&r2=38679&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/MacroInfo.cpp (original)
+++ cfe/cfe/trunk/Lex/MacroInfo.cpp Wed Jul 11 11:23:45 2007
@@ -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;
+}
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38679&r1=38678&r2=38679&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:45 2007
@@ -839,10 +839,10 @@
/// 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 @@
} 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 @@
++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 @@
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 @@
++NumUndefined;
LexerToken MacroNameTok;
- ReadMacroName(MacroNameTok, true);
+ ReadMacroName(MacroNameTok, 2);
// Error reading macro name? If so, diagnostic already issued.
if (MacroNameTok.getKind() == tok::eom)
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=38679&r1=38678&r2=38679&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:23:45 2007
@@ -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>"; };
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=38679&r1=38678&r2=38679&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:23:45 2007
@@ -115,7 +115,11 @@
"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,
Modified: cfe/cfe/trunk/include/clang/Lex/MacroInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=38679&r1=38678&r2=38679&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/MacroInfo.h Wed Jul 11 11:23:45 2007
@@ -57,6 +57,11 @@
///
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) {
Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38679&r1=38678&r2=38679&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:45 2007
@@ -421,7 +421,7 @@
/// 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
More information about the cfe-commits
mailing list