diff options
author | dim <dim@FreeBSD.org> | 2014-03-21 17:53:59 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-03-21 17:53:59 +0000 |
commit | 9cedb8bb69b89b0f0c529937247a6a80cabdbaec (patch) | |
tree | c978f0e9ec1ab92dc8123783f30b08a7fd1e2a39 /contrib/llvm/tools/clang/lib/Driver/Compilation.cpp | |
parent | 03fdc2934eb61c44c049a02b02aa974cfdd8a0eb (diff) | |
download | FreeBSD-src-9cedb8bb69b89b0f0c529937247a6a80cabdbaec.zip FreeBSD-src-9cedb8bb69b89b0f0c529937247a6a80cabdbaec.tar.gz |
MFC 261991:
Upgrade our copy of llvm/clang to 3.4 release. This version supports
all of the features in the current working draft of the upcoming C++
standard, provisionally named C++1y.
The code generator's performance is greatly increased, and the loop
auto-vectorizer is now enabled at -Os and -O2 in addition to -O3. The
PowerPC backend has made several major improvements to code generation
quality and compile time, and the X86, SPARC, ARM32, Aarch64 and SystemZ
backends have all seen major feature work.
Release notes for llvm and clang can be found here:
<http://llvm.org/releases/3.4/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html>
MFC 262121 (by emaste):
Update lldb for clang/llvm 3.4 import
This commit largely restores the lldb source to the upstream r196259
snapshot with the addition of threaded inferior support and a few bug
fixes.
Specific upstream lldb revisions restored include:
SVN git
181387 779e6ac
181703 7bef4e2
182099 b31044e
182650 f2dcf35
182683 0d91b80
183862 15c1774
183929 99447a6
184177 0b2934b
184948 4dc3761
184954 007e7bc
186990 eebd175
Sponsored by: DARPA, AFRL
MFC 262186 (by emaste):
Fix mismerge in r262121
A break statement was lost in the merge. The error had no functional
impact, but restore it to reduce the diff against upstream.
MFC 262303:
Pull in r197521 from upstream clang trunk (by rdivacky):
Use the integrated assembler by default on FreeBSD/ppc and ppc64.
Requested by: jhibbits
MFC 262611:
Pull in r196874 from upstream llvm trunk:
Fix a crash that occurs when PWD is invalid.
MCJIT needs to be able to run in hostile environments, even when PWD
is invalid. There's no need to crash MCJIT in this case.
The obvious fix is to simply leave MCContext's CompilationDir empty
when PWD can't be determined. This way, MCJIT clients,
and other clients that link with LLVM don't need a valid working directory.
If we do want to guarantee valid CompilationDir, that should be done
only for clients of getCompilationDir(). This is as simple as checking
for an empty string.
The only current use of getCompilationDir is EmitGenDwarfInfo, which
won't conceivably run with an invalid working dir. However, in the
purely hypothetically and untestable case that this happens, the
AT_comp_dir will be omitted from the compilation_unit DIE.
This should help fix assertions occurring with ports-mgmt/tinderbox,
when it is using jails, and sometimes invalidates clang's current
working directory.
Reported by: decke
MFC 262809:
Pull in r203007 from upstream clang trunk:
Don't produce an alias between destructors with different calling conventions.
Fixes pr19007.
(Please note that is an LLVM PR identifier, not a FreeBSD one.)
This should fix Firefox and/or libxul crashes (due to problems with
regparm/stdcall calling conventions) on i386.
Reported by: multiple users on freebsd-current
PR: bin/187103
MFC 263048:
Repair recognition of "CC" as an alias for the C++ compiler, since it
was silently broken by upstream for a Windows-specific use-case.
Apparently some versions of CMake still rely on this archaic feature...
Reported by: rakuco
MFC 263049:
Garbage collect the old way of adding the libstdc++ include directories
in clang's InitHeaderSearch.cpp. This has been superseded by David
Chisnall's commit in r255321.
Moreover, if libc++ is used, the libstdc++ include directories should
not be in the search path at all. These directories are now only used
if you pass -stdlib=libstdc++.
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Driver/Compilation.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Driver/Compilation.cpp | 199 |
1 files changed, 31 insertions, 168 deletions
diff --git a/contrib/llvm/tools/clang/lib/Driver/Compilation.cpp b/contrib/llvm/tools/clang/lib/Driver/Compilation.cpp index 1bff4a3..f077fd6 100644 --- a/contrib/llvm/tools/clang/lib/Driver/Compilation.cpp +++ b/contrib/llvm/tools/clang/lib/Driver/Compilation.cpp @@ -9,20 +9,20 @@ #include "clang/Driver/Compilation.h" #include "clang/Driver/Action.h" -#include "clang/Driver/ArgList.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/Support/Program.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" #include <errno.h> #include <sys/stat.h> using namespace clang::driver; using namespace clang; +using namespace llvm::opt; Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain, InputArgList *_Args, DerivedArgList *_TranslatedArgs) @@ -69,160 +69,34 @@ const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC, return *Entry; } -void Compilation::PrintJob(raw_ostream &OS, const Job &J, - const char *Terminator, bool Quote) const { - if (const Command *C = dyn_cast<Command>(&J)) { - OS << " \"" << C->getExecutable() << '"'; - for (ArgStringList::const_iterator it = C->getArguments().begin(), - ie = C->getArguments().end(); it != ie; ++it) { - OS << ' '; - if (!Quote && !std::strpbrk(*it, " \"\\$")) { - OS << *it; - continue; - } - - // Quote the argument and escape shell special characters; this isn't - // really complete but is good enough. - OS << '"'; - for (const char *s = *it; *s; ++s) { - if (*s == '"' || *s == '\\' || *s == '$') - OS << '\\'; - OS << *s; - } - OS << '"'; - } - OS << Terminator; - } else { - const JobList *Jobs = cast<JobList>(&J); - for (JobList::const_iterator - it = Jobs->begin(), ie = Jobs->end(); it != ie; ++it) - PrintJob(OS, **it, Terminator, Quote); - } -} - -static bool skipArg(const char *Flag, bool &SkipNextArg) { - StringRef FlagRef(Flag); - - // Assume we're going to see -Flag <Arg>. - SkipNextArg = true; - - // These flags are all of the form -Flag <Arg> and are treated as two - // arguments. Therefore, we need to skip the flag and the next argument. - bool Res = llvm::StringSwitch<bool>(Flag) - .Cases("-I", "-MF", "-MT", "-MQ", true) - .Cases("-o", "-coverage-file", "-dependency-file", true) - .Cases("-fdebug-compilation-dir", "-idirafter", true) - .Cases("-include", "-include-pch", "-internal-isystem", true) - .Cases("-internal-externc-isystem", "-iprefix", "-iwithprefix", true) - .Cases("-iwithprefixbefore", "-isysroot", "-isystem", "-iquote", true) - .Cases("-resource-dir", "-serialize-diagnostic-file", true) - .Case("-dwarf-debug-flags", true) - .Default(false); - - // Match found. - if (Res) - return Res; - - // The remaining flags are treated as a single argument. - SkipNextArg = false; - - // These flags are all of the form -Flag and have no second argument. - Res = llvm::StringSwitch<bool>(Flag) - .Cases("-M", "-MM", "-MG", "-MP", "-MD", true) - .Case("-MMD", true) - .Default(false); - - // Match found. - if (Res) - return Res; - - // These flags are treated as a single argument (e.g., -F<Dir>). - if (FlagRef.startswith("-F") || FlagRef.startswith("-I")) - return true; - - return false; -} - -static bool quoteNextArg(const char *flag) { - return llvm::StringSwitch<bool>(flag) - .Case("-D", true) - .Default(false); -} - -void Compilation::PrintDiagnosticJob(raw_ostream &OS, const Job &J) const { - if (const Command *C = dyn_cast<Command>(&J)) { - OS << C->getExecutable(); - unsigned QuoteNextArg = 0; - for (ArgStringList::const_iterator it = C->getArguments().begin(), - ie = C->getArguments().end(); it != ie; ++it) { - - bool SkipNext; - if (skipArg(*it, SkipNext)) { - if (SkipNext) ++it; - continue; - } - - if (!QuoteNextArg) - QuoteNextArg = quoteNextArg(*it) ? 2 : 0; - - OS << ' '; - - if (QuoteNextArg == 1) - OS << '"'; - - if (!std::strpbrk(*it, " \"\\$")) { - OS << *it; - } else { - // Quote the argument and escape shell special characters; this isn't - // really complete but is good enough. - OS << '"'; - for (const char *s = *it; *s; ++s) { - if (*s == '"' || *s == '\\' || *s == '$') - OS << '\\'; - OS << *s; - } - OS << '"'; - } +bool Compilation::CleanupFile(const char *File, bool IssueErrors) const { + std::string P(File); - if (QuoteNextArg) { - if (QuoteNextArg == 1) - OS << '"'; - --QuoteNextArg; - } - } - OS << '\n'; - } else { - const JobList *Jobs = cast<JobList>(&J); - for (JobList::const_iterator - it = Jobs->begin(), ie = Jobs->end(); it != ie; ++it) - PrintDiagnosticJob(OS, **it); - } -} + // FIXME: Why are we trying to remove files that we have not created? For + // example we should only try to remove a temporary assembly file if + // "clang -cc1" succeed in writing it. Was this a workaround for when + // clang was writing directly to a .s file and sometimes leaving it behind + // during a failure? -bool Compilation::CleanupFile(const char *File, bool IssueErrors) const { - llvm::sys::Path P(File); - std::string Error; + // FIXME: If this is necessary, we can still try to split + // llvm::sys::fs::remove into a removeFile and a removeDir and avoid the + // duplicated stat from is_regular_file. // Don't try to remove files which we don't have write access to (but may be // able to remove), or non-regular files. Underlying tools may have // intentionally not overwritten them. - if (!P.canWrite() || !P.isRegularFile()) + if (!llvm::sys::fs::can_write(File) || !llvm::sys::fs::is_regular_file(File)) return true; - if (P.eraseFromDisk(false, &Error)) { - // Failure is only failure if the file exists and is "regular". There is - // a race condition here due to the limited interface of - // llvm::sys::Path, we want to know if the removal gave ENOENT. + if (llvm::error_code EC = llvm::sys::fs::remove(File)) { + // Failure is only failure if the file exists and is "regular". We checked + // for it being regular before, and llvm::sys::fs::remove ignores ENOENT, + // so we don't need to check again. - // FIXME: Grumble, P.exists() is broken. PR3837. - struct stat buf; - if (::stat(P.c_str(), &buf) == 0 ? (buf.st_mode & S_IFMT) == S_IFREG : - (errno != ENOENT)) { - if (IssueErrors) - getDriver().Diag(clang::diag::err_drv_unable_to_remove_file) - << Error; - return false; - } + if (IssueErrors) + getDriver().Diag(clang::diag::err_drv_unable_to_remove_file) + << EC.message(); + return false; } return true; } @@ -254,13 +128,7 @@ bool Compilation::CleanupFileMap(const ArgStringMap &Files, int Compilation::ExecuteCommand(const Command &C, const Command *&FailingCommand) const { - llvm::sys::Path Prog(C.getExecutable()); - const char **Argv = new const char*[C.getArguments().size() + 2]; - Argv[0] = C.getExecutable(); - std::copy(C.getArguments().begin(), C.getArguments().end(), Argv+1); - Argv[C.getArguments().size() + 1] = 0; - - if ((getDriver().CCCEcho || getDriver().CCPrintOptions || + if ((getDriver().CCPrintOptions || getArgs().hasArg(options::OPT_v)) && !getDriver().CCGenDiagnostics) { raw_ostream *OS = &llvm::errs(); @@ -268,9 +136,8 @@ int Compilation::ExecuteCommand(const Command &C, // output stream. if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) { std::string Error; - OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, - Error, - llvm::raw_fd_ostream::F_Append); + OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, Error, + llvm::sys::fs::F_Append); if (!Error.empty()) { getDriver().Diag(clang::diag::err_drv_cc_print_options_failure) << Error; @@ -283,7 +150,7 @@ int Compilation::ExecuteCommand(const Command &C, if (getDriver().CCPrintOptions) *OS << "[Logging clang options]"; - PrintJob(*OS, C, "\n", /*Quote=*/getDriver().CCPrintOptions); + C.Print(*OS, "\n", /*Quote=*/getDriver().CCPrintOptions); if (OS != &llvm::errs()) delete OS; @@ -291,11 +158,7 @@ int Compilation::ExecuteCommand(const Command &C, std::string Error; bool ExecutionFailed; - int Res = - llvm::sys::Program::ExecuteAndWait(Prog, Argv, - /*env*/0, Redirects, - /*secondsToWait*/0, /*memoryLimit*/0, - &Error, &ExecutionFailed); + int Res = C.Execute(Redirects, &Error, &ExecutionFailed); if (!Error.empty()) { assert(Res && "Error string set with 0 result code!"); getDriver().Diag(clang::diag::err_drv_command_failure) << Error; @@ -304,7 +167,6 @@ int Compilation::ExecuteCommand(const Command &C, if (Res) FailingCommand = &C; - delete[] Argv; return ExecutionFailed ? 1 : Res; } @@ -370,9 +232,10 @@ void Compilation::initCompilationForDiagnostics() { TranslatedArgs->ClaimAllArgs(); // Redirect stdout/stderr to /dev/null. - Redirects = new const llvm::sys::Path*[3](); - Redirects[1] = new const llvm::sys::Path(); - Redirects[2] = new const llvm::sys::Path(); + Redirects = new const StringRef*[3](); + Redirects[0] = 0; + Redirects[1] = new const StringRef(); + Redirects[2] = new const StringRef(); } StringRef Compilation::getSysRoot() const { |