mirror of
https://github.com/intel/llvm.git
synced 2026-01-31 07:27:33 +08:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>"; };
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user