diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 35a983dbd782..edafe623a4f6 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -488,6 +488,7 @@ public: const HeaderSearchOptions &, const DependencyOutputOptions &, const TargetInfo &, + const FrontendOptions &, SourceManager &, FileManager &); /// Create the AST context. diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 2a214663bd1d..c8df4941cc21 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -39,6 +39,7 @@ class PreprocessorOutputOptions; class SourceManager; class Stmt; class TargetInfo; +class FrontendOptions; class MacroBuilder { llvm::raw_ostream &Out; @@ -76,7 +77,8 @@ void ApplyHeaderSearchOptions(HeaderSearch &HS, /// environment ready to process a single file. void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, - const HeaderSearchOptions &HSOpts); + const HeaderSearchOptions &HSOpts, + const FrontendOptions &FEOpts); /// ProcessWarningOptions - Initialize the diagnostic client and process the /// warning options specified on the command line. diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index ef3cf89299e4..ac13b950752f 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -994,10 +994,6 @@ public: DefineStd(Builder, "WIN32", Opts); DefineStd(Builder, "WINNT", Opts); Builder.defineMacro("_X86_"); - if (Opts.ObjC1) - // __weak is always defined, for use in blocks and with objc pointers, - // even for i686-pc-win32 targets. - Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))"); } }; } // end anonymous namespace diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 9f71ec6b2356..19c740d17a83 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -158,7 +158,8 @@ void CompilerInstance::createPreprocessor() { PP.reset(createPreprocessor(getDiagnostics(), getLangOpts(), getPreprocessorOpts(), getHeaderSearchOpts(), getDependencyOutputOpts(), getTarget(), - getSourceManager(), getFileManager())); + getFrontendOpts(), getSourceManager(), + getFileManager())); } Preprocessor * @@ -168,6 +169,7 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags, const HeaderSearchOptions &HSOpts, const DependencyOutputOptions &DepOpts, const TargetInfo &Target, + const FrontendOptions &FEOpts, SourceManager &SourceMgr, FileManager &FileMgr) { // Create a PTH manager if we are using some form of a token cache. @@ -189,7 +191,7 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags, PP->setPTHManager(PTHMgr); } - InitializePreprocessor(*PP, PPOpts, HSOpts); + InitializePreprocessor(*PP, PPOpts, HSOpts, FEOpts); // Handle generating dependencies, if requested. if (!DepOpts.OutputFile.empty()) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 841463c8e981..e4c380ae0edd 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -14,6 +14,7 @@ #include "clang/Frontend/Utils.h" #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Frontend/FrontendOptions.h" #include "clang/Frontend/PreprocessorOptions.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/FileManager.h" @@ -202,6 +203,7 @@ static void DefineExactWidthIntType(TargetInfo::IntType Ty, static void InitializePredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, + const FrontendOptions &FEOpts, MacroBuilder &Builder) { // Compiler version introspection macros. Builder.defineMacro("__llvm__"); // LLVM Backend @@ -406,6 +408,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI, else if (LangOpts.getStackProtectorMode() == LangOptions::SSPReq) Builder.defineMacro("__SSP_ALL__", "2"); + if (FEOpts.ProgramAction == frontend::RewriteObjC) + Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))"); // Get other target #defines. TI.getTargetDefines(LangOpts, Builder); } @@ -461,7 +465,8 @@ static void InitializeFileRemapping(Diagnostic &Diags, /// void clang::InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &InitOpts, - const HeaderSearchOptions &HSOpts) { + const HeaderSearchOptions &HSOpts, + const FrontendOptions &FEOpts) { std::string PredefineBuffer; PredefineBuffer.reserve(4080); llvm::raw_string_ostream Predefines(PredefineBuffer); @@ -475,7 +480,7 @@ void clang::InitializePreprocessor(Preprocessor &PP, // Install things like __POWERPC__, __GNUC__, etc into the macro table. if (InitOpts.UsePredefines) InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(), - Builder); + FEOpts, Builder); // Add on the predefines from the driver. Wrap in a #line directive to report // that they come from the command line.