diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-03-06 00:46:00 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-03-06 00:46:00 +0000 |
commit | 7b24254e91a0984b57278ddc5e84cf8ed194074e (patch) | |
tree | 1bcf9f518b574faf00ab162d3d072bef7359568e /clang/lib/Lex/PPDirectives.cpp | |
parent | 47ef466b0fcd5d8add0d2fd2f2430dee16a03ce5 (diff) | |
download | bcm5719-llvm-7b24254e91a0984b57278ddc5e84cf8ed194074e.tar.gz bcm5719-llvm-7b24254e91a0984b57278ddc5e84cf8ed194074e.zip |
After issuing a diagnostic for undefining or redefining a builtin macro,
continue parsing the directive rather than silently discarding it.
Allowing undef or redef of __TIME__ and __DATE__ is important to folks
who want stable, reproducible builds.
llvm-svn: 176540
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 07f24c8200b..8379ca8719c 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -143,15 +143,14 @@ void Preprocessor::ReadMacroName(Token &MacroNameTok, char isDefineUndef) { Diag(MacroNameTok, diag::err_pp_macro_not_identifier); // Fall through on error. } else if (isDefineUndef && II->getPPKeywordID() == tok::pp_defined) { - // Error if defining "defined": C99 6.10.8.4. + // Error if defining "defined": C99 6.10.8/4, C++ [cpp.predefined]p4. Diag(MacroNameTok, diag::err_defined_macro_name); - } else if (isDefineUndef && II->hasMacroDefinition() && + } else if (isDefineUndef == 2 && II->hasMacroDefinition() && getMacroInfo(II)->isBuiltinMacro()) { - // Error if defining "__LINE__" and other builtins: C99 6.10.8.4. - if (isDefineUndef == 1) - Diag(MacroNameTok, diag::pp_redef_builtin_macro); - else - Diag(MacroNameTok, diag::pp_undef_builtin_macro); + // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 + // and C++ [cpp.predefined]p4], but allow it as an extension. + Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro); + return; } else { // Okay, we got a good identifier node. Return it. return; @@ -1925,10 +1924,14 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { if (!OtherMI->isUsed() && OtherMI->isWarnIfUnused()) Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used); + // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and + // C++ [cpp.predefined]p4, but allow it as an extension. + if (OtherMI->isBuiltinMacro()) + Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro); // Macros must be identical. This means all tokens and whitespace // separation must be the same. C99 6.10.3.2. - if (!OtherMI->isAllowRedefinitionsWithoutWarning() && - !MI->isIdenticalTo(*OtherMI, *this)) { + else if (!OtherMI->isAllowRedefinitionsWithoutWarning() && + !MI->isIdenticalTo(*OtherMI, *this)) { Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef) << MacroNameTok.getIdentifierInfo(); Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition); |