[cfe-commits] r80883 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td include/clang/Basic/LangOptions.h lib/Basic/Targets.cpp lib/Driver/Tools.cpp lib/Frontend/PCHReader.cpp tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Wed Sep 2 21:54:29 PDT 2009
Author: ddunbar
Date: Wed Sep 2 23:54:28 2009
New Revision: 80883
URL: http://llvm.org/viewvc/llvm-project?rev=80883&view=rev
Log:
Add basic support for -pthread.
- Patch by David Chisnall, with PCH and Darwin support mixed in.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=80883&r1=80882&r2=80883&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Wed Sep 2 23:54:28 2009
@@ -87,8 +87,11 @@
"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">;
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=80883&r1=80882&r2=80883&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Wed Sep 2 23:54:28 2009
@@ -54,6 +54,8 @@
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 @@
// FIXME: The default should be 1.
ThreadsafeStatics = 0;
+ POSIXThreads = 0;
Blocks = 0;
EmitAllDecls = 0;
MathErrno = 1;
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=80883&r1=80882&r2=80883&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Sep 2 23:54:28 2009
@@ -102,6 +102,9 @@
Define(Defs, "__STATIC__");
else
Define(Defs, "__DYNAMIC__");
+
+ if (Opts.POSIXThreads)
+ Define(Defs, "_REENTRANT", "1");
}
static void getDarwinOSXDefines(std::vector<char> &Defs,
@@ -272,6 +275,8 @@
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 @@
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 @@
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)
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=80883&r1=80882&r2=80883&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep 2 23:54:28 2009
@@ -517,6 +517,8 @@
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,
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=80883&r1=80882&r2=80883&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Sep 2 23:54:28 2009
@@ -78,6 +78,7 @@
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);
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=80883&r1=80882&r2=80883&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Sep 2 23:54:28 2009
@@ -397,6 +397,10 @@
llvm::cl::init(false));
static llvm::cl::opt<bool>
+PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
+ llvm::cl::init(false));
+
+static llvm::cl::opt<bool>
ObjCSenderDispatch("fobjc-sender-dependent-dispatch",
llvm::cl::desc("Enable sender-dependent dispatch for"
"Objective-C messages"), llvm::cl::init(false));
@@ -514,6 +518,9 @@
if (AltiVec)
Options.AltiVec = 1;
+
+ if (PThread)
+ Options.POSIXThreads = 1;
Options.setVisibilityMode(SymbolVisibility);
Options.OverflowChecking = OverflowChecking;
More information about the cfe-commits
mailing list