diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-11-19 09:00:00 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-11-19 09:00:00 +0000 |
commit | 6df2408694f81a03eb8b0e3b013272042233c061 (patch) | |
tree | c7f5a7b6fd212399d821b83b22c1e6a42e8c4a0d /tools | |
parent | 741c13ecc20fb35b836ad690aeecd402f002d654 (diff) | |
download | FreeBSD-src-6df2408694f81a03eb8b0e3b013272042233c061.zip FreeBSD-src-6df2408694f81a03eb8b0e3b013272042233c061.tar.gz |
Update clang to r89337.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CIndex/CIndex.cpp | 2 | ||||
-rw-r--r-- | tools/clang-cc/Options.cpp | 94 | ||||
-rw-r--r-- | tools/driver/CMakeLists.txt | 12 | ||||
-rw-r--r-- | tools/driver/Makefile | 3 | ||||
-rw-r--r-- | tools/driver/cc1_main.cpp | 88 | ||||
-rw-r--r-- | tools/driver/driver.cpp | 8 |
6 files changed, 154 insertions, 53 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index ebdba29..46732de 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -1219,7 +1219,7 @@ void clang_codeComplete(CXIndex CIdx, argv.push_back("-Xclang"); argv.push_back(code_complete_at.c_str()); argv.push_back("-Xclang"); - argv.push_back("-code-completion-debug-printer=0"); + argv.push_back("-no-code-completion-debug-printer"); // Add the source file name (FIXME: later, we'll want to build temporary // file from the buffer, or just feed the source text via standard input). diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index b5190eb..584f957 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -100,14 +100,12 @@ AnalyzeSpecificFunction("analyze-function", static llvm::cl::opt<bool> EagerlyAssume("analyzer-eagerly-assume", - llvm::cl::init(false), llvm::cl::desc("Eagerly assume the truth/falseness of some " "symbolic constraints")); static llvm::cl::opt<bool> -PurgeDead("analyzer-purge-dead", - llvm::cl::init(true), - llvm::cl::desc("Remove dead symbols, bindings, and constraints before" +NoPurgeDead("analyzer-no-purge-dead", + llvm::cl::desc("Don't remove dead symbols, bindings, and constraints before" " processing a statement")); static llvm::cl::opt<bool> @@ -136,8 +134,7 @@ DisableLLVMOptimizations("disable-llvm-optzns", static llvm::cl::opt<bool> DisableRedZone("disable-red-zone", - llvm::cl::desc("Do not emit code that uses the red zone."), - llvm::cl::init(false)); + llvm::cl::desc("Do not emit code that uses the red zone.")); static llvm::cl::opt<bool> GenerateDebugInfo("g", @@ -150,8 +147,7 @@ NoCommon("fno-common", static llvm::cl::opt<bool> NoImplicitFloat("no-implicit-float", - llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"), - llvm::cl::init(false)); + llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)")); static llvm::cl::opt<bool> NoMergeConstants("fno-merge-all-constants", @@ -170,8 +166,7 @@ struct OptLevelParser : public llvm::cl::parser<unsigned> { }; static llvm::cl::opt<unsigned, false, OptLevelParser> OptLevel("O", llvm::cl::Prefix, - llvm::cl::desc("Optimization level"), - llvm::cl::init(0)); + llvm::cl::desc("Optimization level")); static llvm::cl::opt<bool> OptSize("Os", llvm::cl::desc("Optimize for size")); @@ -264,7 +259,7 @@ PrintColorDiagnostic("fcolor-diagnostics", llvm::cl::desc("Use colors in diagnostics")); static llvm::cl::opt<bool> -SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false), +SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::desc("Silence ObjC rewriting warnings")); static llvm::cl::opt<bool> @@ -287,9 +282,8 @@ CodeCompletionAt("code-completion-at", llvm::cl::desc("Dump code-completion information at a location")); static llvm::cl::opt<bool> -CodeCompletionDebugPrinter("code-completion-debug-printer", - llvm::cl::desc("Use the \"debug\" code-completion print"), - llvm::cl::init(true)); +NoCodeCompletionDebugPrinter("no-code-completion-debug-printer", + llvm::cl::desc("Don't the \"debug\" code-completion print")); static llvm::cl::opt<bool> CodeCompletionWantsMacros("code-completion-macros", @@ -297,8 +291,7 @@ CodeCompletionWantsMacros("code-completion-macros", static llvm::cl::opt<bool> DisableFree("disable-free", - llvm::cl::desc("Disable freeing of memory on exit"), - llvm::cl::init(false)); + llvm::cl::desc("Disable freeing of memory on exit")); static llvm::cl::opt<bool> EmptyInputOnly("empty-input-only", @@ -444,12 +437,11 @@ TimeReport("ftime-report", namespace langoptions { static llvm::cl::opt<bool> -AllowBuiltins("fbuiltin", llvm::cl::init(true), - llvm::cl::desc("Disable implicit builtin knowledge of functions")); +NoBuiltin("fno-builtin", + llvm::cl::desc("Disable implicit builtin knowledge of functions")); static llvm::cl::opt<bool> -AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"), - llvm::cl::init(false)); +AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax")); static llvm::cl::opt<bool> AccessControl("faccess-control", @@ -537,8 +529,8 @@ MainFileName("main-file-name", llvm::cl::desc("Main file name to use for debug info")); static llvm::cl::opt<bool> -MathErrno("fmath-errno", llvm::cl::init(true), - llvm::cl::desc("Require math functions to respect errno")); +NoMathErrno("fno-math-errno", + llvm::cl::desc("Don't require math functions to respect errno")); static llvm::cl::opt<bool> NoElideConstructors("fno-elide-constructors", @@ -581,15 +573,13 @@ ObjCNonFragileABI("fobjc-nonfragile-abi", static llvm::cl::opt<bool> OverflowChecking("ftrapv", - llvm::cl::desc("Trap on integer overflow"), - llvm::cl::init(false)); + llvm::cl::desc("Trap on integer overflow")); static llvm::cl::opt<unsigned> PICLevel("pic-level", llvm::cl::desc("Value for __PIC__")); static llvm::cl::opt<bool> -PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"), - llvm::cl::init(false)); +PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code")); static llvm::cl::opt<bool> PascalStrings("fpascal-strings", @@ -597,8 +587,8 @@ PascalStrings("fpascal-strings", "string literals")); static llvm::cl::opt<bool> -Rtti("frtti", llvm::cl::init(true), - llvm::cl::desc("Enable generation of rtti information")); +NoRtti("fno-rtti", + llvm::cl::desc("Disable generation of rtti information")); static llvm::cl::opt<bool> ShortWChar("fshort-wchar", @@ -609,8 +599,7 @@ StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined")); static llvm::cl::opt<int> StackProtector("stack-protector", - llvm::cl::desc("Enable stack protectors"), - llvm::cl::init(-1)); + llvm::cl::desc("Enable stack protectors")); static llvm::cl::opt<LangOptions::VisibilityMode> SymbolVisibility("fvisibility", @@ -625,7 +614,7 @@ SymbolVisibility("fvisibility", clEnumValEnd)); static llvm::cl::opt<unsigned> -TemplateDepth("ftemplate-depth", llvm::cl::init(99), +TemplateDepth("ftemplate-depth", llvm::cl::desc("Maximum depth of recursive template " "instantiation")); @@ -724,7 +713,7 @@ iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"), llvm::cl::desc("Set directory to include search path with prefix")); static llvm::cl::opt<std::string> -isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"), +isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::desc("Set the system root directory (usually /)")); static llvm::cl::opt<bool> @@ -793,7 +782,7 @@ void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) { Opts.VisualizeEGUbi = VisualizeEGUbi; Opts.AnalyzeAll = AnalyzeAll; Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress; - Opts.PurgeDead = PurgeDead; + Opts.PurgeDead = !NoPurgeDead; Opts.EagerlyAssume = EagerlyAssume; Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction; Opts.EnableExperimentalChecks = AnalyzerExperimentalChecks; @@ -807,7 +796,8 @@ void clang::InitializeCodeGenOptions(CodeGenOptions &Opts, using namespace codegenoptions; // -Os implies -O2 - Opts.OptimizationLevel = OptSize ? 2 : OptLevel; + unsigned Opt = OptLevel.getPosition() ? OptLevel : 0; + Opts.OptimizationLevel = OptSize ? 2 : Opt; // We must always run at least the always inlining pass. Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining @@ -875,7 +865,7 @@ void clang::InitializeFrontendOptions(FrontendOptions &Opts) { } Opts.CodeCompletionAt = CodeCompletionAt; - Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter; + Opts.DebugCodeCompletionPrinter = !NoCodeCompletionDebugPrinter; Opts.DisableFree = DisableFree; Opts.EmptyInputOnly = EmptyInputOnly; Opts.FixItLocations = FixItAtLocations; @@ -907,7 +897,8 @@ void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts, llvm::StringRef BuiltinIncludePath) { using namespace headersearchoptions; - Opts.Sysroot = isysroot; + if (isysroot.getPosition()) + Opts.Sysroot = isysroot; Opts.Verbose = Verbose; // Handle -I... and -F... options, walking the lists in parallel. @@ -1231,7 +1222,7 @@ void clang::InitializeLangOptions(LangOptions &Options, if (NoLaxVectorConversions.getPosition()) Options.LaxVectorConversions = 0; Options.Exceptions = Exceptions; - Options.Rtti = Rtti; + Options.Rtti = !NoRtti; if (EnableBlocks.getPosition()) Options.Blocks = EnableBlocks; if (CharIsSigned.getPosition()) @@ -1239,8 +1230,7 @@ void clang::InitializeLangOptions(LangOptions &Options, if (ShortWChar.getPosition()) Options.ShortWChar = ShortWChar; - if (!AllowBuiltins) - Options.NoBuiltin = 1; + Options.NoBuiltin = NoBuiltin; if (Freestanding) Options.Freestanding = Options.NoBuiltin = 1; @@ -1255,9 +1245,10 @@ void clang::InitializeLangOptions(LangOptions &Options, // OpenCL and C++ both have bool, true, false keywords. Options.Bool = Options.OpenCL | Options.CPlusPlus; - Options.MathErrno = MathErrno; + Options.MathErrno = !NoMathErrno; - Options.InstantiationDepth = TemplateDepth; + if (TemplateDepth.getPosition()) + Options.InstantiationDepth = TemplateDepth; // Override the default runtime if the user requested it. if (GNURuntime) @@ -1273,8 +1264,10 @@ void clang::InitializeLangOptions(LangOptions &Options, Options.EmitAllDecls = 1; // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support. + unsigned Opt = + codegenoptions::OptLevel.getPosition() ? codegenoptions::OptLevel : 0; Options.OptimizeSize = 0; - Options.Optimize = codegenoptions::OptSize || codegenoptions::OptLevel; + Options.Optimize = codegenoptions::OptSize || Opt; assert(PICLevel <= 2 && "Invalid value for -pic-level"); Options.PICLevel = PICLevel; @@ -1286,17 +1279,18 @@ void clang::InitializeLangOptions(LangOptions &Options, // inlining enabled. // // FIXME: This is affected by other options (-fno-inline). - Options.NoInline = !codegenoptions::OptLevel; + Options.NoInline = !Opt; Options.Static = StaticDefine; - switch (StackProtector) { - default: - assert(StackProtector <= 2 && "Invalid value for -stack-protector"); - case -1: break; - case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break; - case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break; - case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break; + if (StackProtector.getPosition()) { + switch (StackProtector) { + default: + assert(0 && "Invalid value for -stack-protector"); + case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break; + case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break; + case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break; + } } if (MainFileName.getPosition()) diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index 1ad04c8..1a95380 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -3,15 +3,27 @@ set(LLVM_NO_RTTI 1) set( LLVM_USED_LIBS clangDriver clangBasic + clangFrontend ) set(LLVM_LINK_COMPONENTS system support bitreader bitwriter) add_clang_executable(clang driver.cpp + cc1_main.cpp ) add_dependencies(clang clang-cc) +# Create the clang++ symlink in the build directory. +add_custom_target(clang++ ALL + ${CMAKE_COMMAND} -E create_symlink + "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}" + "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}" + DEPENDS clang) + install(TARGETS clang RUNTIME DESTINATION bin) + +# Create the clang++ symlink at installation time. +install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink \"${CMAKE_INSTALL_PREFIX}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}\" \"${CMAKE_INSTALL_PREFIX}/bin/clang++${CMAKE_EXECUTABLE_SUFFIX}\")") diff --git a/tools/driver/Makefile b/tools/driver/Makefile index 4b2fb44..19f93a2 100644 --- a/tools/driver/Makefile +++ b/tools/driver/Makefile @@ -9,6 +9,7 @@ LEVEL = ../../../.. TOOLNAME = clang +TOOLALIAS = clang++ CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include CXXFLAGS = -fno-rtti @@ -18,7 +19,7 @@ TOOL_NO_EXPORTS = 1 # FIXME: It is unfortunate we need to pull in the bitcode reader and # writer just to get the serializer stuff used by clangBasic. LINK_COMPONENTS := system support bitreader bitwriter -USEDLIBS = clangDriver.a clangBasic.a +USEDLIBS = clangDriver.a clangBasic.a clangFrontend.a include $(LEVEL)/Makefile.common diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp new file mode 100644 index 0000000..c516359 --- /dev/null +++ b/tools/driver/cc1_main.cpp @@ -0,0 +1,88 @@ +//===-- cc1_main.cpp - Clang CC1 Driver -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This is the entry point to the clang -cc1 functionality. +// +//===----------------------------------------------------------------------===// + +#include "clang/Driver/Arg.h" +#include "clang/Driver/ArgList.h" +#include "clang/Driver/CC1Options.h" +#include "clang/Driver/DriverDiagnostic.h" +#include "clang/Driver/OptTable.h" +#include "clang/Driver/Option.h" +#include "clang/Frontend/CompilerInvocation.h" +#include "llvm/Support/raw_ostream.h" +#include <cstdlib> +#include <vector> + +using namespace clang; +using namespace clang::driver; + +int cc1_main(Diagnostic &Diags, const char **ArgBegin, const char **ArgEnd) { + llvm::errs() << "cc1 argv:"; + for (const char **i = ArgBegin; i != ArgEnd; ++i) + llvm::errs() << " \"" << *i << '"'; + llvm::errs() << "\n"; + + // Parse the arguments. + OptTable *Opts = createCC1OptTable(); + unsigned MissingArgIndex, MissingArgCount; + InputArgList *Args = Opts->ParseArgs(ArgBegin, ArgEnd, + MissingArgIndex, MissingArgCount); + + // Check for missing argument error. + if (MissingArgCount) + Diags.Report(clang::diag::err_drv_missing_argument) + << Args->getArgString(MissingArgIndex) << MissingArgCount; + + // Dump the parsed arguments. + llvm::errs() << "cc1 parsed options:\n"; + for (ArgList::const_iterator it = Args->begin(), ie = Args->end(); + it != ie; ++it) + (*it)->dump(); + + // Create a compiler invocation. + llvm::errs() << "cc1 creating invocation.\n"; + CompilerInvocation Invocation; + CompilerInvocation::CreateFromArgs(Invocation, + llvm::SmallVector<llvm::StringRef, 32>(ArgBegin, ArgEnd)); + + // Convert the invocation back to argument strings. + std::vector<std::string> InvocationArgs; + Invocation.toArgs(InvocationArgs); + + // Dump the converted arguments. + llvm::SmallVector<llvm::StringRef, 32> Invocation2Args; + llvm::errs() << "invocation argv:"; + for (unsigned i = 0, e = InvocationArgs.size(); i != e; ++i) { + Invocation2Args.push_back(InvocationArgs[i]); + llvm::errs() << " \"" << InvocationArgs[i] << '"'; + } + llvm::errs() << "\n"; + + // Convert those arguments to another invocation, and check that we got the + // same thing. + CompilerInvocation Invocation2; + CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args); + + // FIXME: Implement CompilerInvocation comparison. + if (memcmp(&Invocation, &Invocation2, sizeof(Invocation)) != 0) { + llvm::errs() << "warning: Invocations differ!\n"; + + std::vector<std::string> Invocation2Args; + Invocation2.toArgs(Invocation2Args); + llvm::errs() << "invocation argv:"; + for (unsigned i = 0, e = Invocation2Args.size(); i != e; ++i) + llvm::errs() << " \"" << Invocation2Args[i] << '"'; + llvm::errs() << "\n"; + } + + return 0; +} diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index fb7c6cc..dbfc293 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -15,7 +15,6 @@ #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Option.h" -#include "clang/Driver/Options.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/OwningPtr.h" @@ -179,6 +178,9 @@ void ApplyQAOverride(std::vector<const char*> &Args, const char *OverrideStr, } } +extern int cc1_main(Diagnostic &Diags, + const char **ArgBegin, const char **ArgEnd); + int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); llvm::PrettyStackTraceProgram X(argc, argv); @@ -188,6 +190,10 @@ int main(int argc, const char **argv) { Diagnostic Diags(&DiagClient); + // Dispatch to cc1_main if appropriate. + if (argc > 1 && llvm::StringRef(argv[1]) == "-cc1") + return cc1_main(Diags, argv+2, argv+argc); + #ifdef CLANG_IS_PRODUCTION bool IsProduction = true; #else |