Predefine __weak attribute when doing objective-c

rewriting for any target. (refixes radar 7530235).

llvm-svn: 93331
This commit is contained in:
Fariborz Jahanian 2010-01-13 18:51:17 +00:00
parent 95ae5e16b9
commit 3f7b8b274d
5 changed files with 15 additions and 9 deletions

View File

@ -488,6 +488,7 @@ public:
const HeaderSearchOptions &,
const DependencyOutputOptions &,
const TargetInfo &,
const FrontendOptions &,
SourceManager &, FileManager &);
/// Create the AST context.

View File

@ -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.

View File

@ -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

View File

@ -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())

View File

@ -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.