From: Daniel Dunbar Date: Thu, 3 Sep 2009 04:54:28 +0000 (+0000) Subject: Add basic support for -pthread. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5345c391c65d1780a0d7b0102b7f735cc3f82732;p=clang Add basic support for -pthread. - Patch by David Chisnall, with PCH and Darwin support mixed in. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80883 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td index ab6e2bcfae..a06042ed4b 100644 --- a/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/include/clang/Basic/DiagnosticFrontendKinds.td @@ -87,8 +87,11 @@ def warn_pch_builtins : Error< "PCH file was compiled with builtins %select{enabled|disabled}0 but " "builtins are currently %select{enabled|disabled}1">; def warn_pch_thread_safe_statics : Error< - "PCH file was compiled %select{without|with}0 thread-safe statics but" + "PCH file was compiled %select{without|with}0 thread-safe statics but " "thread-safe statics are currently %select{disabled|enabled}1">; +def warn_pch_posix_threads : Error< + "PCH file was compiled %select{without|with}0 POSIX thread support but " + "POSIX threads are currently %select{disabled|enabled}1">; def warn_pch_blocks : Error< "blocks were %select{disabled|enabled}0 in PCH file but " "are currently %select{disabled|enabled}1">; diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index f162f2eace..da702a8ab3 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -54,6 +54,8 @@ public: unsigned ThreadsafeStatics : 1; // Whether static initializers are protected // by locks. + unsigned POSIXThreads : 1; // Compiling with POSIX thread support + // (-pthread) unsigned Blocks : 1; // block extension to C unsigned EmitAllDecls : 1; // Emit all declarations, even if // they are unused. @@ -135,6 +137,7 @@ public: // FIXME: The default should be 1. ThreadsafeStatics = 0; + POSIXThreads = 0; Blocks = 0; EmitAllDecls = 0; MathErrno = 1; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 305ca2d8d2..d9cd42c323 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -102,6 +102,9 @@ static void getDarwinDefines(std::vector &Defs, const LangOptions &Opts) { Define(Defs, "__STATIC__"); else Define(Defs, "__DYNAMIC__"); + + if (Opts.POSIXThreads) + Define(Defs, "_REENTRANT", "1"); } static void getDarwinOSXDefines(std::vector &Defs, @@ -272,6 +275,8 @@ protected: DefineStd(Defs, "linux", Opts); Define(Defs, "__gnu_linux__"); Define(Defs, "__ELF__", "1"); + if (Opts.POSIXThreads) + Define(Defs, "_REENTRANT", "1"); } public: LinuxTargetInfo(const std::string& triple) @@ -290,6 +295,8 @@ protected: Define(Defs, "__NetBSD__", "1"); Define(Defs, "__unix__", "1"); Define(Defs, "__ELF__", "1"); + if (Opts.POSIXThreads) + Define(Defs, "_POSIX_THREADS", "1"); } public: NetBSDTargetInfo(const std::string &triple) @@ -309,6 +316,8 @@ protected: Define(Defs, "__OpenBSD__", "1"); DefineStd(Defs, "unix", Opts); Define(Defs, "__ELF__", "1"); + if (Opts.POSIXThreads) + Define(Defs, "_POSIX_THREADS", "1"); } public: OpenBSDTargetInfo(const std::string &triple) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index e93e6429eb..b7357ec13a 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -517,6 +517,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fvisibility_EQ); Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); + Args.AddLastArg(CmdArgs, options::OPT_pthread); + // Forward stack protector flags. if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, options::OPT_fstack_protector_all, diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index cb008c0ea2..55dbd978f1 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -78,6 +78,7 @@ PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, diag::warn_pch_thread_safe_statics); + PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); PARSE_LANGOPT_BENIGN(EmitAllDecls); PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index f664854074..241cc11915 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -396,6 +396,10 @@ static llvm::cl::opt AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"), llvm::cl::init(false)); +static llvm::cl::opt +PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"), + llvm::cl::init(false)); + static llvm::cl::opt ObjCSenderDispatch("fobjc-sender-dependent-dispatch", llvm::cl::desc("Enable sender-dependent dispatch for" @@ -514,6 +518,9 @@ static void InitializeLangOptions(LangOptions &Options, LangKind LK){ if (AltiVec) Options.AltiVec = 1; + + if (PThread) + Options.POSIXThreads = 1; Options.setVisibilityMode(SymbolVisibility); Options.OverflowChecking = OverflowChecking;