diff options
author | John McCall <rjmccall@apple.com> | 2015-12-10 23:31:01 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2015-12-10 23:31:01 +0000 |
commit | 83760378617dfa9670ce9439e9bfdcf2a5c81b90 (patch) | |
tree | 3001c116d3d00bbc1df3fe26a74d4568f85a68c4 /clang/lib | |
parent | 07206ea19dd55c8180d443a0d55a25bd67fb0858 (diff) | |
download | bcm5719-llvm-83760378617dfa9670ce9439e9bfdcf2a5c81b90.tar.gz bcm5719-llvm-83760378617dfa9670ce9439e9bfdcf2a5c81b90.zip |
In Objective-C, ignore attempts to redefine the ARC/GC qualifier macros.
This works around existing system headers which unconditionally
redefine these macros.
This is reasonably safe to do because we used to warn about it anyway
(outside of system headers). Continue to warn if the redefinition
would have changed the expansion. Still permit redefinition if the
macro is explicitly #undef'ed first.
rdar://23788307
llvm-svn: 255311
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index fd16168203a..298543e2e95 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -2266,6 +2266,30 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok, // Finally, if this identifier already had a macro defined for it, verify that // the macro bodies are identical, and issue diagnostics if they are not. if (const MacroInfo *OtherMI=getMacroInfo(MacroNameTok.getIdentifierInfo())) { + // In Objective-C, ignore attempts to directly redefine the builtin + // definitions of the ownership qualifiers. It's still possible to + // #undef them. + auto isObjCProtectedMacro = [](const IdentifierInfo *II) -> bool { + return II->isStr("__strong") || + II->isStr("__weak") || + II->isStr("__unsafe_unretained") || + II->isStr("__autoreleasing"); + }; + if (getLangOpts().ObjC1 && + SourceMgr.getFileID(OtherMI->getDefinitionLoc()) + == getPredefinesFileID() && + isObjCProtectedMacro(MacroNameTok.getIdentifierInfo())) { + // Warn if it changes the tokens. + if ((!getDiagnostics().getSuppressSystemWarnings() || + !SourceMgr.isInSystemHeader(DefineTok.getLocation())) && + !MI->isIdenticalTo(*OtherMI, *this, + /*Syntactic=*/LangOpts.MicrosoftExt)) { + Diag(MI->getDefinitionLoc(), diag::warn_pp_objc_macro_redef_ignored); + } + assert(!OtherMI->isWarnIfUnused()); + return; + } + // It is very common for system headers to have tons of macro redefinitions // and for warnings to be disabled in system headers. If this is the case, // then don't bother calling MacroInfo::isIdenticalTo. |