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 | eed55e6061768c0faff62dda22c6edad9d286501 (patch) | |
tree | 2345984f87f42765e533be165639d8905efe95ed /lib/Lex | |
parent | 75525c4cce5e1e097d3fab4391b11619d87cedfd (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176540 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex')
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 07f24c8200..8379ca8719 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/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); |