2009-11-17 14:02:29 +08:00
|
|
|
//===--- CompilerInvocation.cpp -------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Frontend/CompilerInvocation.h"
|
2009-12-01 11:16:53 +08:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Basic/Version.h"
|
2010-11-04 06:45:23 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
2009-12-01 11:16:53 +08:00
|
|
|
#include "clang/Driver/Arg.h"
|
|
|
|
#include "clang/Driver/ArgList.h"
|
2012-05-01 22:57:16 +08:00
|
|
|
#include "clang/Driver/Options.h"
|
2009-12-01 11:16:53 +08:00
|
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
|
|
|
#include "clang/Driver/OptTable.h"
|
|
|
|
#include "clang/Driver/Option.h"
|
|
|
|
#include "clang/Frontend/CompilerInvocation.h"
|
|
|
|
#include "clang/Frontend/LangStandard.h"
|
2010-08-19 07:57:17 +08:00
|
|
|
#include "clang/Serialization/ASTReader.h"
|
2009-12-01 11:16:53 +08:00
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-11-17 14:02:29 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-12-01 11:16:53 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2010-08-30 17:42:39 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-11-17 14:02:29 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-11-30 02:12:39 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
2009-11-17 14:02:29 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2011-11-18 07:01:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Initialization.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-11-18 12:32:13 +08:00
|
|
|
CompilerInvocationBase::CompilerInvocationBase()
|
2011-11-18 07:01:24 +08:00
|
|
|
: LangOpts(new LangOptions()) {}
|
|
|
|
|
2011-11-18 12:32:13 +08:00
|
|
|
CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X)
|
2012-02-20 22:00:23 +08:00
|
|
|
: RefCountedBase<CompilerInvocation>(),
|
2011-11-29 19:31:35 +08:00
|
|
|
LangOpts(new LangOptions(*X.getLangOpts())) {}
|
2011-11-18 07:01:24 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-11-17 14:02:29 +08:00
|
|
|
static const char *getAnalysisStoreName(AnalysisStores Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("Unknown analysis store!");
|
2009-11-17 14:02:29 +08:00
|
|
|
#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \
|
|
|
|
case NAME##Model: return CMDFLAG;
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *getAnalysisConstraintName(AnalysisConstraints Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("Unknown analysis constraints!");
|
2009-11-17 14:02:29 +08:00
|
|
|
#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \
|
|
|
|
case NAME##Model: return CMDFLAG;
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *getAnalysisDiagClientName(AnalysisDiagClients Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("Unknown analysis client!");
|
2009-11-17 14:02:29 +08:00
|
|
|
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE) \
|
|
|
|
case PD_##NAME: return CMDFLAG;
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-30 10:03:00 +08:00
|
|
|
static const char *getAnalysisPurgeModeName(AnalysisPurgeMode Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
2012-03-09 07:16:35 +08:00
|
|
|
llvm_unreachable("Unknown analysis purge mode!");
|
2011-09-30 10:03:00 +08:00
|
|
|
#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \
|
|
|
|
case NAME: return CMDFLAG;
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-09 07:16:35 +08:00
|
|
|
static const char *getAnalysisIPAModeName(AnalysisIPAMode Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown analysis ipa mode!");
|
|
|
|
#define ANALYSIS_IPA(NAME, CMDFLAG, DESC) \
|
|
|
|
case NAME: return CMDFLAG;
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
getAnalysisInliningModeName(AnalysisInliningMode Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown analysis inlining mode!");
|
|
|
|
#define ANALYSIS_INLINE_SELECTION(NAME, CMDFLAG, DESC) \
|
|
|
|
case NAME: return CMDFLAG;
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Serialization (to args)
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
namespace {
|
|
|
|
/// ToArgsList - Helper class to create a list of std::strings.
|
|
|
|
class ToArgsList {
|
|
|
|
std::vector<std::string> &Res;
|
|
|
|
public:
|
|
|
|
explicit ToArgsList(std::vector<std::string> &Res) : Res(Res) {}
|
|
|
|
|
|
|
|
void push_back(StringRef Str) {
|
|
|
|
// Avoid creating a temporary string.
|
|
|
|
Res.push_back(std::string());
|
|
|
|
Res.back().assign(Str.data(), Str.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_back(StringRef Str1, StringRef Str2) {
|
|
|
|
push_back(Str1);
|
|
|
|
push_back(Str2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts, ToArgsList &Res) {
|
2011-02-25 08:09:51 +08:00
|
|
|
if (Opts.ShowCheckerHelp)
|
|
|
|
Res.push_back("-analyzer-checker-help");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (Opts.AnalysisStoreOpt != RegionStoreModel)
|
|
|
|
Res.push_back("-analyzer-store",
|
|
|
|
getAnalysisStoreName(Opts.AnalysisStoreOpt));
|
|
|
|
if (Opts.AnalysisConstraintsOpt != RangeConstraintsModel)
|
|
|
|
Res.push_back("-analyzer-constraints",
|
|
|
|
getAnalysisConstraintName(Opts.AnalysisConstraintsOpt));
|
|
|
|
if (Opts.AnalysisDiagOpt != PD_HTML)
|
|
|
|
Res.push_back("-analyzer-output",
|
|
|
|
getAnalysisDiagClientName(Opts.AnalysisDiagOpt));
|
|
|
|
if (Opts.AnalysisPurgeOpt != PurgeStmt)
|
|
|
|
Res.push_back("-analyzer-purge",
|
|
|
|
getAnalysisPurgeModeName(Opts.AnalysisPurgeOpt));
|
|
|
|
if (!Opts.AnalyzeSpecificFunction.empty())
|
|
|
|
Res.push_back("-analyze-function", Opts.AnalyzeSpecificFunction);
|
2012-08-22 05:44:21 +08:00
|
|
|
if (Opts.IPAMode != BasicInlining)
|
2012-03-26 23:39:31 +08:00
|
|
|
Res.push_back("-analyzer-ipa", getAnalysisIPAModeName(Opts.IPAMode));
|
|
|
|
if (Opts.InliningMode != NoRedundancy)
|
|
|
|
Res.push_back("-analyzer-inlining-mode",
|
|
|
|
getAnalysisInliningModeName(Opts.InliningMode));
|
2012-03-09 07:16:35 +08:00
|
|
|
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.AnalyzeAll)
|
|
|
|
Res.push_back("-analyzer-opt-analyze-headers");
|
|
|
|
if (Opts.AnalyzerDisplayProgress)
|
|
|
|
Res.push_back("-analyzer-display-progress");
|
2009-12-08 06:06:12 +08:00
|
|
|
if (Opts.AnalyzeNestedBlocks)
|
|
|
|
Res.push_back("-analyzer-opt-analyze-nested-blocks");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.EagerlyAssume)
|
|
|
|
Res.push_back("-analyzer-eagerly-assume");
|
|
|
|
if (Opts.TrimGraph)
|
|
|
|
Res.push_back("-trim-egraph");
|
|
|
|
if (Opts.VisualizeEGDot)
|
|
|
|
Res.push_back("-analyzer-viz-egraph-graphviz");
|
2011-03-17 03:14:34 +08:00
|
|
|
if (Opts.VisualizeEGUbi)
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-analyzer-viz-egraph-ubigraph");
|
2012-03-29 03:59:16 +08:00
|
|
|
if (Opts.NoRetryExhausted)
|
|
|
|
Res.push_back("-analyzer-disable-retry-exhausted");
|
2011-02-15 02:13:31 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = Opts.CheckersControlList.size(); i != e; ++i) {
|
|
|
|
const std::pair<std::string, bool> &opt = Opts.CheckersControlList[i];
|
|
|
|
if (opt.second)
|
|
|
|
Res.push_back("-analyzer-disable-checker");
|
|
|
|
else
|
|
|
|
Res.push_back("-analyzer-checker");
|
|
|
|
Res.push_back(opt.first);
|
|
|
|
}
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
static void CodeGenOptsToArgs(const CodeGenOptions &Opts, ToArgsList &Res) {
|
2012-04-27 15:24:20 +08:00
|
|
|
switch (Opts.DebugInfo) {
|
|
|
|
case CodeGenOptions::NoDebugInfo:
|
|
|
|
break;
|
2012-05-04 15:39:27 +08:00
|
|
|
case CodeGenOptions::DebugLineTablesOnly:
|
|
|
|
Res.push_back("-gline-tables-only");
|
|
|
|
break;
|
2012-04-27 15:24:20 +08:00
|
|
|
case CodeGenOptions::LimitedDebugInfo:
|
|
|
|
Res.push_back("-g");
|
|
|
|
Res.push_back("-flimit-debug-info");
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::FullDebugInfo:
|
|
|
|
Res.push_back("-g");
|
|
|
|
Res.push_back("-fno-limit-debug-info");
|
|
|
|
break;
|
|
|
|
}
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.DisableLLVMOpts)
|
|
|
|
Res.push_back("-disable-llvm-optzns");
|
|
|
|
if (Opts.DisableRedZone)
|
|
|
|
Res.push_back("-disable-red-zone");
|
2012-01-23 16:29:12 +08:00
|
|
|
if (Opts.DisableTailCalls)
|
|
|
|
Res.push_back("-mdisable-tail-calls");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.DebugCompilationDir.empty())
|
|
|
|
Res.push_back("-fdebug-compilation-dir", Opts.DebugCompilationDir);
|
|
|
|
if (!Opts.DwarfDebugFlags.empty())
|
|
|
|
Res.push_back("-dwarf-debug-flags", Opts.DwarfDebugFlags);
|
2011-04-22 07:44:07 +08:00
|
|
|
if (Opts.EmitGcovArcs)
|
|
|
|
Res.push_back("-femit-coverage-data");
|
|
|
|
if (Opts.EmitGcovNotes)
|
|
|
|
Res.push_back("-femit-coverage-notes");
|
2012-07-12 07:02:10 +08:00
|
|
|
if (Opts.EmitOpenCLArgMetadata)
|
|
|
|
Res.push_back("-cl-kernel-arg-info");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (!Opts.MergeAllConstants)
|
|
|
|
Res.push_back("-fno-merge-all-constants");
|
2009-11-21 01:23:30 +08:00
|
|
|
if (Opts.NoCommon)
|
|
|
|
Res.push_back("-fno-common");
|
2011-03-18 10:56:14 +08:00
|
|
|
if (Opts.ForbidGuardVariables)
|
|
|
|
Res.push_back("-fforbid-guard-variables");
|
IRgen: Add a -fuse-register-sized-bitfield-access option, for testing.
- Changes bit-field access policy to try to use (aligned) register sized accesses.
The idea here is that by using larger accesses we expose more coalescing
potential to the backend when we have situations like adjacent bit-fields in the
same structure (which is common), and that the backend should be smart enough to
narrow the accesses down when no coalescing is done or when it is shown not to
be profitable.
--
$ clang -m32 -O3 -S -o - t.c
_f0: ## @f0
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movb (%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, (%eax)
movb 1(%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, 1(%eax)
movb 2(%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, 2(%eax)
movb 3(%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, 3(%eax)
popl %ebp
ret
$ clang -m32 -O3 -S -o - t.c -Xclang -fuse-register-sized-bitfield-access
_f0: ## @f0
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl $-2139062144, %ecx ## imm = 0xFFFFFFFF80808080
andl (%eax), %ecx
orl $16843009, %ecx ## imm = 0x1010101
movl %ecx, (%eax)
popl %ebp
ret
--
llvm-svn: 133532
2011-06-22 02:54:46 +08:00
|
|
|
if (Opts.UseRegisterSizedBitfieldAccess)
|
|
|
|
Res.push_back("-fuse-register-sized-bitfield-access");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.NoImplicitFloat)
|
|
|
|
Res.push_back("-no-implicit-float");
|
2010-07-01 09:31:45 +08:00
|
|
|
if (Opts.OmitLeafFramePointer)
|
|
|
|
Res.push_back("-momit-leaf-frame-pointer");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.OptimizeSize) {
|
|
|
|
assert(Opts.OptimizationLevel == 2 && "Invalid options!");
|
2011-04-30 06:49:50 +08:00
|
|
|
Opts.OptimizeSize == 1 ? Res.push_back("-Os") : Res.push_back("-Oz");
|
2009-11-20 04:54:59 +08:00
|
|
|
} else if (Opts.OptimizationLevel != 0)
|
|
|
|
Res.push_back("-O" + llvm::utostr(Opts.OptimizationLevel));
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.MainFileName.empty())
|
|
|
|
Res.push_back("-main-file-name", Opts.MainFileName);
|
2011-12-10 07:41:18 +08:00
|
|
|
if (Opts.NoInfsFPMath)
|
|
|
|
Res.push_back("-menable-no-infinities");
|
|
|
|
if (Opts.NoNaNsFPMath)
|
|
|
|
Res.push_back("-menable-no-nans");
|
2009-11-17 14:02:29 +08:00
|
|
|
// SimplifyLibCalls is only derived.
|
|
|
|
// TimePasses is only derived.
|
|
|
|
// UnitAtATime is unused.
|
|
|
|
// Inlining is only derived.
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2010-08-08 07:08:14 +08:00
|
|
|
// UnrollLoops is derived, but also accepts an option, no
|
|
|
|
// harm in pushing it back here.
|
|
|
|
if (Opts.UnrollLoops)
|
|
|
|
Res.push_back("-funroll-loops");
|
2010-04-13 08:38:24 +08:00
|
|
|
if (Opts.DataSections)
|
|
|
|
Res.push_back("-fdata-sections");
|
|
|
|
if (Opts.FunctionSections)
|
|
|
|
Res.push_back("-ffunction-sections");
|
2009-11-29 15:18:39 +08:00
|
|
|
if (Opts.AsmVerbose)
|
|
|
|
Res.push_back("-masm-verbose");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.CodeModel.empty())
|
|
|
|
Res.push_back("-mcode-model", Opts.CodeModel);
|
2011-10-07 02:29:46 +08:00
|
|
|
if (Opts.CUDAIsDevice)
|
|
|
|
Res.push_back("-fcuda-is-device");
|
2010-03-20 12:15:41 +08:00
|
|
|
if (!Opts.CXAAtExit)
|
|
|
|
Res.push_back("-fno-use-cxa-atexit");
|
|
|
|
if (Opts.CXXCtorDtorAliases)
|
|
|
|
Res.push_back("-mconstructor-aliases");
|
2011-06-16 07:02:42 +08:00
|
|
|
if (Opts.ObjCAutoRefCountExceptions)
|
|
|
|
Res.push_back("-fobjc-arc-eh");
|
2009-11-29 15:18:39 +08:00
|
|
|
if (!Opts.DebugPass.empty()) {
|
2012-03-26 23:39:31 +08:00
|
|
|
Res.push_back("-mdebug-pass", Opts.DebugPass);
|
2009-11-29 15:18:39 +08:00
|
|
|
}
|
|
|
|
if (Opts.DisableFPElim)
|
|
|
|
Res.push_back("-mdisable-fp-elim");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.FloatABI.empty())
|
|
|
|
Res.push_back("-mfloat-abi", Opts.FloatABI);
|
|
|
|
if (!Opts.LimitFloatPrecision.empty())
|
|
|
|
Res.push_back("-mlimit-float-precision", Opts.LimitFloatPrecision);
|
2009-11-29 15:18:39 +08:00
|
|
|
if (Opts.NoZeroInitializedInBSS)
|
|
|
|
Res.push_back("-mno-zero-initialized-bss");
|
2010-04-25 01:56:46 +08:00
|
|
|
switch (Opts.getObjCDispatchMethod()) {
|
|
|
|
case CodeGenOptions::Legacy:
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::Mixed:
|
|
|
|
Res.push_back("-fobjc-dispatch-method=mixed");
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::NonLegacy:
|
|
|
|
Res.push_back("-fobjc-dispatch-method=non-legacy");
|
|
|
|
break;
|
|
|
|
}
|
2012-05-23 01:19:45 +08:00
|
|
|
if (Opts.BoundsChecking > 0)
|
|
|
|
Res.push_back("-fbounds-checking=" + llvm::utostr(Opts.BoundsChecking));
|
2012-03-26 23:39:31 +08:00
|
|
|
if (Opts.NumRegisterParameters)
|
|
|
|
Res.push_back("-mregparm", llvm::utostr(Opts.NumRegisterParameters));
|
2011-08-26 08:26:29 +08:00
|
|
|
if (Opts.NoGlobalMerge)
|
|
|
|
Res.push_back("-mno-global-merge");
|
2011-06-21 08:14:18 +08:00
|
|
|
if (Opts.NoExecStack)
|
|
|
|
Res.push_back("-mnoexecstack");
|
2010-05-27 13:39:39 +08:00
|
|
|
if (Opts.RelaxAll)
|
|
|
|
Res.push_back("-mrelax-all");
|
2011-03-29 06:49:28 +08:00
|
|
|
if (Opts.SaveTempLabels)
|
|
|
|
Res.push_back("-msave-temp-labels");
|
2011-05-01 02:35:43 +08:00
|
|
|
if (Opts.NoDwarf2CFIAsm)
|
|
|
|
Res.push_back("-fno-dwarf2-cfi-asm");
|
2011-10-18 07:05:52 +08:00
|
|
|
if (Opts.NoDwarfDirectoryAsm)
|
|
|
|
Res.push_back("-fno-dwarf-directory-asm");
|
2009-11-30 16:42:00 +08:00
|
|
|
if (Opts.SoftFloat)
|
|
|
|
Res.push_back("-msoft-float");
|
2012-03-28 07:58:37 +08:00
|
|
|
if (Opts.StrictEnums)
|
|
|
|
Res.push_back("-fstrict-enums");
|
2009-11-29 15:18:39 +08:00
|
|
|
if (Opts.UnwindTables)
|
|
|
|
Res.push_back("-munwind-tables");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (Opts.RelocationModel != "pic")
|
|
|
|
Res.push_back("-mrelocation-model", Opts.RelocationModel);
|
2010-02-13 11:50:24 +08:00
|
|
|
if (!Opts.VerifyModule)
|
|
|
|
Res.push_back("-disable-llvm-verifier");
|
2012-03-26 23:39:31 +08:00
|
|
|
for (unsigned i = 0, e = Opts.BackendOptions.size(); i != e; ++i)
|
|
|
|
Res.push_back("-backend-option", Opts.BackendOptions[i]);
|
2012-06-28 16:01:44 +08:00
|
|
|
|
|
|
|
switch (Opts.DefaultTLSModel) {
|
|
|
|
case CodeGenOptions::GeneralDynamicTLSModel:
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::LocalDynamicTLSModel:
|
|
|
|
Res.push_back("-ftls-model=local-dynamic");
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::InitialExecTLSModel:
|
|
|
|
Res.push_back("-ftls-model=initial-exec");
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::LocalExecTLSModel:
|
|
|
|
Res.push_back("-ftls-model=local-exec");
|
|
|
|
break;
|
|
|
|
}
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DependencyOutputOptsToArgs(const DependencyOutputOptions &Opts,
|
2012-03-26 23:39:31 +08:00
|
|
|
ToArgsList &Res) {
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.IncludeSystemHeaders)
|
|
|
|
Res.push_back("-sys-header-deps");
|
2011-02-02 23:41:17 +08:00
|
|
|
if (Opts.ShowHeaderIncludes)
|
|
|
|
Res.push_back("-H");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.HeaderIncludeOutputFile.empty())
|
|
|
|
Res.push_back("-header-include-file", Opts.HeaderIncludeOutputFile);
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.UsePhonyTargets)
|
|
|
|
Res.push_back("-MP");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.OutputFile.empty())
|
|
|
|
Res.push_back("-dependency-file", Opts.OutputFile);
|
|
|
|
for (unsigned i = 0, e = Opts.Targets.size(); i != e; ++i)
|
|
|
|
Res.push_back("-MT", Opts.Targets[i]);
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts,
|
2012-03-26 23:39:31 +08:00
|
|
|
ToArgsList &Res) {
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.IgnoreWarnings)
|
|
|
|
Res.push_back("-w");
|
|
|
|
if (Opts.NoRewriteMacros)
|
|
|
|
Res.push_back("-Wno-rewrite-macros");
|
|
|
|
if (Opts.Pedantic)
|
|
|
|
Res.push_back("-pedantic");
|
|
|
|
if (Opts.PedanticErrors)
|
|
|
|
Res.push_back("-pedantic-errors");
|
|
|
|
if (!Opts.ShowColumn)
|
|
|
|
Res.push_back("-fno-show-column");
|
|
|
|
if (!Opts.ShowLocation)
|
|
|
|
Res.push_back("-fno-show-source-location");
|
|
|
|
if (!Opts.ShowCarets)
|
|
|
|
Res.push_back("-fno-caret-diagnostics");
|
|
|
|
if (!Opts.ShowFixits)
|
|
|
|
Res.push_back("-fno-diagnostics-fixit-info");
|
|
|
|
if (Opts.ShowSourceRanges)
|
|
|
|
Res.push_back("-fdiagnostics-print-source-range-info");
|
2010-08-20 04:24:43 +08:00
|
|
|
if (Opts.ShowParseableFixits)
|
|
|
|
Res.push_back("-fdiagnostics-parseable-fixits");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.ShowColors)
|
|
|
|
Res.push_back("-fcolor-diagnostics");
|
|
|
|
if (Opts.VerifyDiagnostics)
|
|
|
|
Res.push_back("-verify");
|
|
|
|
if (Opts.ShowOptionNames)
|
|
|
|
Res.push_back("-fdiagnostics-show-option");
|
2010-05-05 05:55:25 +08:00
|
|
|
if (Opts.ShowCategories == 1)
|
|
|
|
Res.push_back("-fdiagnostics-show-category=id");
|
|
|
|
else if (Opts.ShowCategories == 2)
|
|
|
|
Res.push_back("-fdiagnostics-show-category=name");
|
2011-05-22 01:07:29 +08:00
|
|
|
switch (Opts.Format) {
|
|
|
|
case DiagnosticOptions::Clang:
|
|
|
|
Res.push_back("-fdiagnostics-format=clang"); break;
|
|
|
|
case DiagnosticOptions::Msvc:
|
|
|
|
Res.push_back("-fdiagnostics-format=msvc"); break;
|
|
|
|
case DiagnosticOptions::Vi:
|
|
|
|
Res.push_back("-fdiagnostics-format=vi"); break;
|
|
|
|
}
|
2012-03-26 23:39:31 +08:00
|
|
|
if (Opts.ErrorLimit)
|
|
|
|
Res.push_back("-ferror-limit", llvm::utostr(Opts.ErrorLimit));
|
|
|
|
if (!Opts.DiagnosticLogFile.empty())
|
|
|
|
Res.push_back("-diagnostic-log-file", Opts.DiagnosticLogFile);
|
2010-05-05 01:13:42 +08:00
|
|
|
if (Opts.MacroBacktraceLimit
|
2012-03-26 23:39:31 +08:00
|
|
|
!= DiagnosticOptions::DefaultMacroBacktraceLimit)
|
|
|
|
Res.push_back("-fmacro-backtrace-limit",
|
|
|
|
llvm::utostr(Opts.MacroBacktraceLimit));
|
2010-05-05 01:13:42 +08:00
|
|
|
if (Opts.TemplateBacktraceLimit
|
2012-03-26 23:39:31 +08:00
|
|
|
!= DiagnosticOptions::DefaultTemplateBacktraceLimit)
|
|
|
|
Res.push_back("-ftemplate-backtrace-limit",
|
|
|
|
llvm::utostr(Opts.TemplateBacktraceLimit));
|
2011-12-17 03:06:07 +08:00
|
|
|
if (Opts.ConstexprBacktraceLimit
|
2012-03-26 23:39:31 +08:00
|
|
|
!= DiagnosticOptions::DefaultConstexprBacktraceLimit)
|
|
|
|
Res.push_back("-fconstexpr-backtrace-limit",
|
|
|
|
llvm::utostr(Opts.ConstexprBacktraceLimit));
|
|
|
|
|
|
|
|
if (Opts.TabStop != DiagnosticOptions::DefaultTabStop)
|
|
|
|
Res.push_back("-ftabstop", llvm::utostr(Opts.TabStop));
|
|
|
|
if (Opts.MessageLength)
|
|
|
|
Res.push_back("-fmessage-length", llvm::utostr(Opts.MessageLength));
|
|
|
|
if (!Opts.DumpBuildInformation.empty())
|
|
|
|
Res.push_back("-dump-build-information", Opts.DumpBuildInformation);
|
2009-11-17 14:02:29 +08:00
|
|
|
for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i)
|
|
|
|
Res.push_back("-W" + Opts.Warnings[i]);
|
|
|
|
}
|
|
|
|
|
2010-06-08 07:22:09 +08:00
|
|
|
static const char *getInputKindName(InputKind Kind) {
|
2009-11-17 14:02:29 +08:00
|
|
|
switch (Kind) {
|
2010-06-08 07:22:09 +08:00
|
|
|
case IK_None: break;
|
|
|
|
case IK_AST: return "ast";
|
|
|
|
case IK_Asm: return "assembler-with-cpp";
|
|
|
|
case IK_C: return "c";
|
|
|
|
case IK_CXX: return "c++";
|
2010-06-08 07:26:47 +08:00
|
|
|
case IK_LLVM_IR: return "ir";
|
2010-06-08 07:22:09 +08:00
|
|
|
case IK_ObjC: return "objective-c";
|
|
|
|
case IK_ObjCXX: return "objective-c++";
|
|
|
|
case IK_OpenCL: return "cl";
|
2010-12-01 11:15:20 +08:00
|
|
|
case IK_CUDA: return "cuda";
|
2010-06-08 07:22:09 +08:00
|
|
|
case IK_PreprocessedC: return "cpp-output";
|
|
|
|
case IK_PreprocessedCXX: return "c++-cpp-output";
|
|
|
|
case IK_PreprocessedObjC: return "objective-c-cpp-output";
|
|
|
|
case IK_PreprocessedObjCXX:return "objective-c++-cpp-output";
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("Unexpected language kind!");
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *getActionName(frontend::ActionKind Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case frontend::PluginAction:
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("Invalid kind!");
|
2009-11-17 14:02:29 +08:00
|
|
|
|
2012-07-31 17:37:40 +08:00
|
|
|
case frontend::ASTDeclList: return "-ast-list";
|
2009-11-17 14:02:29 +08:00
|
|
|
case frontend::ASTDump: return "-ast-dump";
|
2010-11-24 19:21:45 +08:00
|
|
|
case frontend::ASTDumpXML: return "-ast-dump-xml";
|
2009-11-17 14:02:29 +08:00
|
|
|
case frontend::ASTPrint: return "-ast-print";
|
|
|
|
case frontend::ASTView: return "-ast-view";
|
|
|
|
case frontend::DumpRawTokens: return "-dump-raw-tokens";
|
|
|
|
case frontend::DumpTokens: return "-dump-tokens";
|
|
|
|
case frontend::EmitAssembly: return "-S";
|
|
|
|
case frontend::EmitBC: return "-emit-llvm-bc";
|
|
|
|
case frontend::EmitHTML: return "-emit-html";
|
|
|
|
case frontend::EmitLLVM: return "-emit-llvm";
|
|
|
|
case frontend::EmitLLVMOnly: return "-emit-llvm-only";
|
2010-05-26 02:41:01 +08:00
|
|
|
case frontend::EmitCodeGenOnly: return "-emit-codegen-only";
|
2010-02-03 09:18:43 +08:00
|
|
|
case frontend::EmitObj: return "-emit-obj";
|
2009-11-17 14:02:29 +08:00
|
|
|
case frontend::FixIt: return "-fixit";
|
2011-08-26 06:30:56 +08:00
|
|
|
case frontend::GenerateModule: return "-emit-module";
|
2009-11-17 14:02:29 +08:00
|
|
|
case frontend::GeneratePCH: return "-emit-pch";
|
|
|
|
case frontend::GeneratePTH: return "-emit-pth";
|
2010-03-20 03:44:04 +08:00
|
|
|
case frontend::InitOnly: return "-init-only";
|
2009-11-17 14:02:29 +08:00
|
|
|
case frontend::ParseSyntaxOnly: return "-fsyntax-only";
|
|
|
|
case frontend::PrintDeclContext: return "-print-decl-contexts";
|
2010-07-21 04:18:03 +08:00
|
|
|
case frontend::PrintPreamble: return "-print-preamble";
|
2009-11-17 14:02:29 +08:00
|
|
|
case frontend::PrintPreprocessedInput: return "-E";
|
|
|
|
case frontend::RewriteMacros: return "-rewrite-macros";
|
|
|
|
case frontend::RewriteObjC: return "-rewrite-objc";
|
|
|
|
case frontend::RewriteTest: return "-rewrite-test";
|
|
|
|
case frontend::RunAnalysis: return "-analyze";
|
2012-03-07 04:06:33 +08:00
|
|
|
case frontend::MigrateSource: return "-migrate";
|
2009-11-17 14:02:29 +08:00
|
|
|
case frontend::RunPreprocessorOnly: return "-Eonly";
|
|
|
|
}
|
|
|
|
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("Unexpected language kind!");
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
static void FileSystemOptsToArgs(const FileSystemOptions &Opts, ToArgsList &Res){
|
|
|
|
if (!Opts.WorkingDir.empty())
|
|
|
|
Res.push_back("-working-directory", Opts.WorkingDir);
|
2010-11-04 06:45:23 +08:00
|
|
|
}
|
|
|
|
|
2012-07-03 01:35:10 +08:00
|
|
|
static void CodeCompleteOptionsToArgs(const CodeCompleteOptions &Opts,
|
|
|
|
ToArgsList &Res) {
|
|
|
|
if (Opts.IncludeMacros)
|
|
|
|
Res.push_back("-code-completion-macros");
|
|
|
|
if (Opts.IncludeCodePatterns)
|
|
|
|
Res.push_back("-code-completion-patterns");
|
|
|
|
if (!Opts.IncludeGlobals)
|
|
|
|
Res.push_back("-no-code-completion-globals");
|
|
|
|
if (Opts.IncludeBriefComments)
|
|
|
|
Res.push_back("-code-completion-brief-comments");
|
|
|
|
}
|
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
static void FrontendOptsToArgs(const FrontendOptions &Opts, ToArgsList &Res) {
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.DisableFree)
|
|
|
|
Res.push_back("-disable-free");
|
|
|
|
if (Opts.RelocatablePCH)
|
|
|
|
Res.push_back("-relocatable-pch");
|
2009-12-03 15:01:58 +08:00
|
|
|
if (Opts.ShowHelp)
|
|
|
|
Res.push_back("-help");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.ShowStats)
|
2009-11-25 18:14:52 +08:00
|
|
|
Res.push_back("-print-stats");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.ShowTimers)
|
|
|
|
Res.push_back("-ftime-report");
|
2009-12-03 15:01:58 +08:00
|
|
|
if (Opts.ShowVersion)
|
|
|
|
Res.push_back("-version");
|
2010-08-14 01:31:00 +08:00
|
|
|
if (Opts.FixWhatYouCan)
|
|
|
|
Res.push_back("-fix-what-you-can");
|
2012-01-26 10:40:48 +08:00
|
|
|
if (Opts.FixOnlyWarnings)
|
|
|
|
Res.push_back("-fix-only-warnings");
|
|
|
|
if (Opts.FixAndRecompile)
|
|
|
|
Res.push_back("-fixit-recompile");
|
|
|
|
if (Opts.FixToTemporaries)
|
|
|
|
Res.push_back("-fixit-to-temporary");
|
2011-06-16 07:25:17 +08:00
|
|
|
switch (Opts.ARCMTAction) {
|
|
|
|
case FrontendOptions::ARCMT_None:
|
|
|
|
break;
|
|
|
|
case FrontendOptions::ARCMT_Check:
|
|
|
|
Res.push_back("-arcmt-check");
|
|
|
|
break;
|
|
|
|
case FrontendOptions::ARCMT_Modify:
|
|
|
|
Res.push_back("-arcmt-modify");
|
|
|
|
break;
|
2011-07-10 04:00:58 +08:00
|
|
|
case FrontendOptions::ARCMT_Migrate:
|
|
|
|
Res.push_back("-arcmt-migrate");
|
|
|
|
break;
|
|
|
|
}
|
2012-07-03 01:35:10 +08:00
|
|
|
CodeCompleteOptionsToArgs(Opts.CodeCompleteOpts, Res);
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.MTMigrateDir.empty())
|
|
|
|
Res.push_back("-mt-migrate-directory", Opts.MTMigrateDir);
|
|
|
|
if (!Opts.ARCMTMigrateReportOut.empty())
|
|
|
|
Res.push_back("-arcmt-migrate-report-output", Opts.ARCMTMigrateReportOut);
|
2011-07-20 01:20:03 +08:00
|
|
|
if (Opts.ARCMTMigrateEmitARCErrors)
|
|
|
|
Res.push_back("-arcmt-migrate-emit-errors");
|
2009-11-17 14:02:29 +08:00
|
|
|
|
2012-03-07 04:06:33 +08:00
|
|
|
if (Opts.ObjCMTAction & ~FrontendOptions::ObjCMT_Literals)
|
|
|
|
Res.push_back("-objcmt-migrate-literals");
|
|
|
|
if (Opts.ObjCMTAction & ~FrontendOptions::ObjCMT_Subscripting)
|
|
|
|
Res.push_back("-objcmt-migrate-subscripting");
|
|
|
|
|
2009-11-17 14:02:29 +08:00
|
|
|
bool NeedLang = false;
|
|
|
|
for (unsigned i = 0, e = Opts.Inputs.size(); i != e; ++i)
|
2012-01-21 00:28:04 +08:00
|
|
|
if (FrontendOptions::getInputKindForExtension(Opts.Inputs[i].File) !=
|
|
|
|
Opts.Inputs[i].Kind)
|
2009-11-17 14:02:29 +08:00
|
|
|
NeedLang = true;
|
2012-03-26 23:39:31 +08:00
|
|
|
if (NeedLang)
|
|
|
|
Res.push_back("-x", getInputKindName(Opts.Inputs[0].Kind));
|
2009-11-17 14:02:29 +08:00
|
|
|
for (unsigned i = 0, e = Opts.Inputs.size(); i != e; ++i) {
|
2012-01-21 00:28:04 +08:00
|
|
|
assert((!NeedLang || Opts.Inputs[i].Kind == Opts.Inputs[0].Kind) &&
|
2009-11-17 14:02:29 +08:00
|
|
|
"Unable to represent this input vector!");
|
2012-01-21 00:28:04 +08:00
|
|
|
Res.push_back(Opts.Inputs[i].File);
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.OutputFile.empty())
|
|
|
|
Res.push_back("-o", Opts.OutputFile);
|
|
|
|
if (!Opts.CodeCompletionAt.FileName.empty())
|
|
|
|
Res.push_back("-code-completion-at",
|
|
|
|
Opts.CodeCompletionAt.FileName + ":" +
|
2009-11-17 14:02:29 +08:00
|
|
|
llvm::utostr(Opts.CodeCompletionAt.Line) + ":" +
|
|
|
|
llvm::utostr(Opts.CodeCompletionAt.Column));
|
2011-02-18 03:04:40 +08:00
|
|
|
if (Opts.ProgramAction != frontend::PluginAction)
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back(getActionName(Opts.ProgramAction));
|
|
|
|
if (!Opts.ActionName.empty()) {
|
2012-03-26 23:39:31 +08:00
|
|
|
Res.push_back("-plugin", Opts.ActionName);
|
|
|
|
for(unsigned i = 0, e = Opts.PluginArgs.size(); i != e; ++i)
|
|
|
|
Res.push_back("-plugin-arg-" + Opts.ActionName, Opts.PluginArgs[i]);
|
2009-12-03 13:11:05 +08:00
|
|
|
}
|
2012-07-27 00:01:23 +08:00
|
|
|
if (!Opts.ASTDumpFilter.empty())
|
|
|
|
Res.push_back("-ast-dump-filter", Opts.ASTDumpFilter);
|
2012-03-26 23:39:31 +08:00
|
|
|
for (unsigned i = 0, e = Opts.Plugins.size(); i != e; ++i)
|
|
|
|
Res.push_back("-load", Opts.Plugins[i]);
|
2011-01-26 04:34:14 +08:00
|
|
|
for (unsigned i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) {
|
2012-03-26 23:39:31 +08:00
|
|
|
Res.push_back("-add-plugin", Opts.AddPluginActions[i]);
|
|
|
|
for(unsigned ai = 0, ae = Opts.AddPluginArgs.size(); ai != ae; ++ai)
|
|
|
|
Res.push_back("-plugin-arg-" + Opts.AddPluginActions[i],
|
|
|
|
Opts.AddPluginArgs[i][ai]);
|
|
|
|
}
|
|
|
|
for (unsigned i = 0, e = Opts.ASTMergeFiles.size(); i != e; ++i)
|
|
|
|
Res.push_back("-ast-merge", Opts.ASTMergeFiles[i]);
|
|
|
|
for (unsigned i = 0, e = Opts.LLVMArgs.size(); i != e; ++i)
|
|
|
|
Res.push_back("-mllvm", Opts.LLVMArgs[i]);
|
Extend the ExternalASTSource interface to allow the AST source to
provide the layout of records, rather than letting Clang compute
the layout itself. LLDB provides the motivation for this feature:
because various layout-altering attributes (packed, aligned, etc.)
don't get reliably get placed into DWARF, the record layouts computed
by LLDB from the reconstructed records differ from the actual layouts,
and badness occurs. This interface lets the DWARF data drive layout,
so we don't need the attributes preserved to get the answer write.
The testing methodology for this change is fun. I've introduced a
variant of -fdump-record-layouts called -fdump-record-layouts-simple
that always has the simple C format and provides size/alignment/field
offsets. There is also a -cc1 option -foverride-record-layout=<file>
to take the output of -fdump-record-layouts-simple and parse it to
produce a set of overridden layouts, which is introduced into the AST
via a testing-only ExternalASTSource (called
LayoutOverrideSource). Each test contains a number of records to lay
out, which use various layout-changing attributes, and then dumps the
layouts. We then run the test again, using the preprocessor to
eliminate the layout-changing attributes entirely (which would give us
different layouts for the records), but supplying the
previously-computed record layouts. Finally, we diff the layouts
produced from the two runs to be sure that they are identical.
Note that this code makes the assumption that we don't *have* to
provide the offsets of bases or virtual bases to get the layout right,
because the alignment attributes don't affect it. I believe this
assumption holds, but if it does not, we can extend
LayoutOverrideSource to also provide base offset information.
Fixes the Clang side of <rdar://problem/10169539>.
llvm-svn: 149055
2012-01-26 15:55:45 +08:00
|
|
|
if (!Opts.OverrideRecordLayoutsFile.empty())
|
|
|
|
Res.push_back("-foverride-record-layout=" + Opts.OverrideRecordLayoutsFile);
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
|
2012-03-26 23:39:31 +08:00
|
|
|
ToArgsList &Res) {
|
2009-11-19 13:32:21 +08:00
|
|
|
if (Opts.Sysroot != "/") {
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-isysroot");
|
|
|
|
Res.push_back(Opts.Sysroot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// User specified include entries.
|
|
|
|
for (unsigned i = 0, e = Opts.UserEntries.size(); i != e; ++i) {
|
|
|
|
const HeaderSearchOptions::Entry &E = Opts.UserEntries[i];
|
2009-11-26 10:13:54 +08:00
|
|
|
if (E.IsFramework && (E.Group != frontend::Angled || !E.IsUserSupplied))
|
2010-04-08 06:58:06 +08:00
|
|
|
llvm::report_fatal_error("Invalid option set!");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (E.IsUserSupplied) {
|
2011-07-28 12:45:53 +08:00
|
|
|
switch (E.Group) {
|
|
|
|
case frontend::After:
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-idirafter");
|
2011-07-28 12:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case frontend::Quoted:
|
2009-11-26 10:13:54 +08:00
|
|
|
Res.push_back("-iquote");
|
2011-07-28 12:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case frontend::System:
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-isystem");
|
2011-07-28 12:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case frontend::IndexHeaderMap:
|
|
|
|
Res.push_back("-index-header-map");
|
|
|
|
Res.push_back(E.IsFramework? "-F" : "-I");
|
|
|
|
break;
|
|
|
|
|
2011-09-23 05:41:16 +08:00
|
|
|
case frontend::CSystem:
|
|
|
|
Res.push_back("-c-isystem");
|
|
|
|
break;
|
|
|
|
|
2011-07-28 12:45:53 +08:00
|
|
|
case frontend::CXXSystem:
|
2011-02-22 08:40:56 +08:00
|
|
|
Res.push_back("-cxx-isystem");
|
2011-07-28 12:45:53 +08:00
|
|
|
break;
|
2011-09-23 05:41:16 +08:00
|
|
|
|
|
|
|
case frontend::ObjCSystem:
|
|
|
|
Res.push_back("-objc-isystem");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case frontend::ObjCXXSystem:
|
|
|
|
Res.push_back("-objcxx-isystem");
|
|
|
|
break;
|
2011-07-28 12:45:53 +08:00
|
|
|
|
|
|
|
case frontend::Angled:
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back(E.IsFramework ? "-F" : "-I");
|
2011-07-28 12:45:53 +08:00
|
|
|
break;
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
} else {
|
2011-11-05 16:30:29 +08:00
|
|
|
if (E.IsInternal) {
|
|
|
|
assert(E.Group == frontend::System && "Unexpected header search group");
|
2011-11-07 17:17:31 +08:00
|
|
|
if (E.ImplicitExternC)
|
2011-11-05 17:24:44 +08:00
|
|
|
Res.push_back("-internal-externc-isystem");
|
|
|
|
else
|
|
|
|
Res.push_back("-internal-isystem");
|
2011-11-05 16:30:29 +08:00
|
|
|
} else {
|
|
|
|
if (E.Group != frontend::Angled && E.Group != frontend::System)
|
|
|
|
llvm::report_fatal_error("Invalid option set!");
|
|
|
|
Res.push_back(E.Group == frontend::Angled ? "-iwithprefixbefore" :
|
|
|
|
"-iwithprefix");
|
|
|
|
}
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
Res.push_back(E.Path);
|
|
|
|
}
|
|
|
|
|
2012-06-14 04:27:03 +08:00
|
|
|
/// User-specified system header prefixes.
|
|
|
|
for (unsigned i = 0, e = Opts.SystemHeaderPrefixes.size(); i != e; ++i) {
|
|
|
|
if (Opts.SystemHeaderPrefixes[i].IsSystemHeader)
|
|
|
|
Res.push_back("-isystem-prefix");
|
|
|
|
else
|
|
|
|
Res.push_back("-ino-system-prefix");
|
|
|
|
|
|
|
|
Res.push_back(Opts.SystemHeaderPrefixes[i].Prefix);
|
|
|
|
}
|
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.ResourceDir.empty())
|
|
|
|
Res.push_back("-resource-dir", Opts.ResourceDir);
|
|
|
|
if (!Opts.ModuleCachePath.empty())
|
|
|
|
Res.push_back("-fmodule-cache-path", Opts.ModuleCachePath);
|
2011-10-12 02:20:10 +08:00
|
|
|
if (!Opts.UseStandardSystemIncludes)
|
|
|
|
Res.push_back("-nostdsysteminc");
|
2010-03-25 04:13:48 +08:00
|
|
|
if (!Opts.UseStandardCXXIncludes)
|
|
|
|
Res.push_back("-nostdinc++");
|
2011-06-22 05:12:29 +08:00
|
|
|
if (Opts.UseLibcxx)
|
|
|
|
Res.push_back("-stdlib=libc++");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.Verbose)
|
|
|
|
Res.push_back("-v");
|
|
|
|
}
|
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
static void LangOptsToArgs(const LangOptions &Opts, ToArgsList &Res) {
|
2009-11-17 14:02:29 +08:00
|
|
|
LangOptions DefaultLangOpts;
|
|
|
|
|
|
|
|
// FIXME: Need to set -std to get all the implicit options.
|
|
|
|
|
|
|
|
// FIXME: We want to only pass options relative to the defaults, which
|
|
|
|
// requires constructing a target. :(
|
|
|
|
//
|
|
|
|
// It would be better to push the all target specific choices into the driver,
|
|
|
|
// so that everything below that was more uniform.
|
|
|
|
|
|
|
|
if (Opts.Trigraphs)
|
|
|
|
Res.push_back("-trigraphs");
|
|
|
|
// Implicit based on the input kind:
|
|
|
|
// AsmPreprocessor, CPlusPlus, ObjC1, ObjC2, OpenCL
|
|
|
|
// Implicit based on the input language standard:
|
|
|
|
// BCPLComment, C99, CPlusPlus0x, Digraphs, GNUInline, ImplicitInt, GNUMode
|
|
|
|
if (Opts.DollarIdents)
|
|
|
|
Res.push_back("-fdollars-in-identifiers");
|
2010-04-18 04:17:31 +08:00
|
|
|
if (Opts.GNUMode && !Opts.GNUKeywords)
|
|
|
|
Res.push_back("-fno-gnu-keywords");
|
|
|
|
if (!Opts.GNUMode && Opts.GNUKeywords)
|
|
|
|
Res.push_back("-fgnu-keywords");
|
2011-09-18 01:15:52 +08:00
|
|
|
if (Opts.MicrosoftExt)
|
2009-12-17 04:10:18 +08:00
|
|
|
Res.push_back("-fms-extensions");
|
2011-10-24 23:27:23 +08:00
|
|
|
if (Opts.MicrosoftMode)
|
|
|
|
Res.push_back("-fms-compatibility");
|
2010-10-21 13:21:48 +08:00
|
|
|
if (Opts.MSCVersion != 0)
|
|
|
|
Res.push_back("-fmsc-version=" + llvm::utostr(Opts.MSCVersion));
|
2010-09-03 07:59:25 +08:00
|
|
|
if (Opts.Borland)
|
|
|
|
Res.push_back("-fborland-extensions");
|
2010-12-24 05:35:43 +08:00
|
|
|
if (Opts.ObjCDefaultSynthProperties)
|
|
|
|
Res.push_back("-fobjc-default-synthesize-properties");
|
2009-11-17 14:02:29 +08:00
|
|
|
// NoInline is implicit.
|
|
|
|
if (!Opts.CXXOperatorNames)
|
|
|
|
Res.push_back("-fno-operator-names");
|
|
|
|
if (Opts.PascalStrings)
|
|
|
|
Res.push_back("-fpascal-strings");
|
2009-12-12 09:27:46 +08:00
|
|
|
if (Opts.CatchUndefined)
|
|
|
|
Res.push_back("-fcatch-undefined-behavior");
|
2011-11-22 09:28:36 +08:00
|
|
|
if (Opts.AddressSanitizer)
|
|
|
|
Res.push_back("-faddress-sanitizer");
|
2012-03-02 06:27:08 +08:00
|
|
|
if (Opts.ThreadSanitizer)
|
|
|
|
Res.push_back("-fthread-sanitizer");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.WritableStrings)
|
|
|
|
Res.push_back("-fwritable-strings");
|
2010-03-15 18:54:44 +08:00
|
|
|
if (Opts.ConstStrings)
|
2011-04-23 14:30:43 +08:00
|
|
|
Res.push_back("-fconst-strings");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (!Opts.LaxVectorConversions)
|
|
|
|
Res.push_back("-fno-lax-vector-conversions");
|
|
|
|
if (Opts.AltiVec)
|
|
|
|
Res.push_back("-faltivec");
|
2009-11-20 04:54:59 +08:00
|
|
|
if (Opts.Exceptions)
|
|
|
|
Res.push_back("-fexceptions");
|
2011-02-23 11:16:42 +08:00
|
|
|
if (Opts.ObjCExceptions)
|
|
|
|
Res.push_back("-fobjc-exceptions");
|
|
|
|
if (Opts.CXXExceptions)
|
|
|
|
Res.push_back("-fcxx-exceptions");
|
2010-02-11 02:48:44 +08:00
|
|
|
if (Opts.SjLjExceptions)
|
|
|
|
Res.push_back("-fsjlj-exceptions");
|
2011-03-19 05:23:38 +08:00
|
|
|
if (Opts.TraditionalCPP)
|
|
|
|
Res.push_back("-traditional-cpp");
|
2009-12-03 02:57:08 +08:00
|
|
|
if (!Opts.RTTI)
|
2009-11-19 13:32:09 +08:00
|
|
|
Res.push_back("-fno-rtti");
|
2011-02-01 23:15:22 +08:00
|
|
|
if (Opts.MSBitfields)
|
|
|
|
Res.push_back("-mms-bitfields");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.Freestanding)
|
|
|
|
Res.push_back("-ffreestanding");
|
|
|
|
if (Opts.NoBuiltin)
|
|
|
|
Res.push_back("-fno-builtin");
|
2009-12-17 00:59:22 +08:00
|
|
|
if (!Opts.AssumeSaneOperatorNew)
|
|
|
|
Res.push_back("-fno-assume-sane-operator-new");
|
2010-02-07 07:23:06 +08:00
|
|
|
if (!Opts.ThreadsafeStatics)
|
|
|
|
Res.push_back("-fno-threadsafe-statics");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.POSIXThreads)
|
|
|
|
Res.push_back("-pthread");
|
2009-11-17 17:15:57 +08:00
|
|
|
if (Opts.Blocks)
|
2009-11-29 13:52:21 +08:00
|
|
|
Res.push_back("-fblocks");
|
2011-09-10 04:41:01 +08:00
|
|
|
if (Opts.BlocksRuntimeOptional)
|
|
|
|
Res.push_back("-fblocks-runtime-optional");
|
2012-01-04 01:07:34 +08:00
|
|
|
if (Opts.Modules)
|
|
|
|
Res.push_back("-fmodules");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.EmitAllDecls)
|
|
|
|
Res.push_back("-femit-all-decls");
|
2010-01-08 10:20:44 +08:00
|
|
|
if (Opts.MathErrno)
|
|
|
|
Res.push_back("-fmath-errno");
|
2010-06-27 05:25:03 +08:00
|
|
|
switch (Opts.getSignedOverflowBehavior()) {
|
|
|
|
case LangOptions::SOB_Undefined: break;
|
|
|
|
case LangOptions::SOB_Defined: Res.push_back("-fwrapv"); break;
|
2010-10-21 11:16:25 +08:00
|
|
|
case LangOptions::SOB_Trapping:
|
2011-11-03 04:52:01 +08:00
|
|
|
Res.push_back("-ftrapv");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.OverflowHandler.empty())
|
|
|
|
Res.push_back("-ftrapv-handler", Opts.OverflowHandler);
|
2011-11-03 04:52:01 +08:00
|
|
|
break;
|
2010-06-27 05:25:03 +08:00
|
|
|
}
|
2012-07-06 08:59:19 +08:00
|
|
|
switch (Opts.getFPContractMode()) {
|
|
|
|
case LangOptions::FPC_Off: Res.push_back("-ffp-contract=off"); break;
|
|
|
|
case LangOptions::FPC_On: Res.push_back("-ffp-contract=on"); break;
|
|
|
|
case LangOptions::FPC_Fast: Res.push_back("-ffp-contract=fast"); break;
|
|
|
|
}
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.HeinousExtensions)
|
|
|
|
Res.push_back("-fheinous-gnu-extensions");
|
|
|
|
// Optimize is implicit.
|
|
|
|
// OptimizeSize is implicit.
|
2012-01-02 22:19:45 +08:00
|
|
|
if (Opts.FastMath)
|
|
|
|
Res.push_back("-ffast-math");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.Static)
|
|
|
|
Res.push_back("-static-define");
|
Extend the ExternalASTSource interface to allow the AST source to
provide the layout of records, rather than letting Clang compute
the layout itself. LLDB provides the motivation for this feature:
because various layout-altering attributes (packed, aligned, etc.)
don't get reliably get placed into DWARF, the record layouts computed
by LLDB from the reconstructed records differ from the actual layouts,
and badness occurs. This interface lets the DWARF data drive layout,
so we don't need the attributes preserved to get the answer write.
The testing methodology for this change is fun. I've introduced a
variant of -fdump-record-layouts called -fdump-record-layouts-simple
that always has the simple C format and provides size/alignment/field
offsets. There is also a -cc1 option -foverride-record-layout=<file>
to take the output of -fdump-record-layouts-simple and parse it to
produce a set of overridden layouts, which is introduced into the AST
via a testing-only ExternalASTSource (called
LayoutOverrideSource). Each test contains a number of records to lay
out, which use various layout-changing attributes, and then dumps the
layouts. We then run the test again, using the preprocessor to
eliminate the layout-changing attributes entirely (which would give us
different layouts for the records), but supplying the
previously-computed record layouts. Finally, we diff the layouts
produced from the two runs to be sure that they are identical.
Note that this code makes the assumption that we don't *have* to
provide the offsets of bases or virtual bases to get the layout right,
because the alignment attributes don't affect it. I believe this
assumption holds, but if it does not, we can extend
LayoutOverrideSource to also provide base offset information.
Fixes the Clang side of <rdar://problem/10169539>.
llvm-svn: 149055
2012-01-26 15:55:45 +08:00
|
|
|
if (Opts.DumpRecordLayoutsSimple)
|
|
|
|
Res.push_back("-fdump-record-layouts-simple");
|
|
|
|
else if (Opts.DumpRecordLayouts)
|
2010-04-15 23:06:22 +08:00
|
|
|
Res.push_back("-fdump-record-layouts");
|
2010-04-18 04:15:18 +08:00
|
|
|
if (Opts.DumpVTableLayouts)
|
2010-04-15 23:06:22 +08:00
|
|
|
Res.push_back("-fdump-vtable-layouts");
|
|
|
|
if (Opts.NoBitFieldTypeAlign)
|
|
|
|
Res.push_back("-fno-bitfield-type-alignment");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (Opts.PICLevel)
|
|
|
|
Res.push_back("-pic-level", llvm::utostr(Opts.PICLevel));
|
Teach Clang about PIE compilations. This is the first step of PR12380.
First, this patch cleans up the parsing of the PIC and PIE family of
options in the driver. The existing logic failed to claim arguments all
over the place resulting in kludges that marked the options as unused.
Instead actually walk all of the arguments and claim them properly.
We now treat -f{,no-}{pic,PIC,pie,PIE} as a single set, accepting the
last one on the commandline. Previously there were lots of ordering bugs
that could creep in due to the nature of the parsing. Let me know if
folks would like weird things such as "-fPIE -fno-pic" to turn on PIE,
but disable full PIC. This doesn't make any sense to me, but we could in
theory support it.
Options that seem to have intentional "trump" status (-static, -mkernel,
etc) continue to do so and are commented as such.
Next, a -pie-level flag is threaded into the frontend, rigged to
a language option, and handled preprocessor, setting up the appropriate
defines. We'll now have the correct defines when compiling with -fpie.
The one place outside of the preprocessor that was inspecting the PIC
level (as opposed to the relocation model, which is set and handled
separately, yay!) is in the GNU ObjC runtime. I changed it to exactly
preserve existing behavior. If folks want to change its behavior in the
face of PIE, they can do that in a separate patch.
Essentially the only functionality changed here is the preprocessor
defines and bug-fixes to the argument management.
Tests have been updated and extended to test all of this a bit more
thoroughly.
llvm-svn: 154291
2012-04-09 00:40:35 +08:00
|
|
|
if (Opts.PIELevel)
|
|
|
|
Res.push_back("-pie-level", llvm::utostr(Opts.PIELevel));
|
2009-11-17 14:02:29 +08:00
|
|
|
if (Opts.ObjCGCBitmapPrint)
|
|
|
|
Res.push_back("-print-ivar-layout");
|
2010-04-23 04:26:39 +08:00
|
|
|
if (Opts.NoConstantCFStrings)
|
|
|
|
Res.push_back("-fno-constant-cfstrings");
|
2010-04-10 03:03:51 +08:00
|
|
|
if (!Opts.AccessControl)
|
|
|
|
Res.push_back("-fno-access-control");
|
2009-11-20 04:54:59 +08:00
|
|
|
if (!Opts.CharIsSigned)
|
2009-11-29 13:52:21 +08:00
|
|
|
Res.push_back("-fno-signed-char");
|
2009-11-20 04:54:59 +08:00
|
|
|
if (Opts.ShortWChar)
|
|
|
|
Res.push_back("-fshort-wchar");
|
2009-11-17 14:02:29 +08:00
|
|
|
if (!Opts.ElideConstructors)
|
|
|
|
Res.push_back("-fno-elide-constructors");
|
2011-09-14 01:21:33 +08:00
|
|
|
if (Opts.getGC() != LangOptions::NonGC) {
|
|
|
|
if (Opts.getGC() == LangOptions::HybridGC) {
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-fobjc-gc");
|
|
|
|
} else {
|
2011-09-14 01:21:33 +08:00
|
|
|
assert(Opts.getGC() == LangOptions::GCOnly && "Invalid GC mode!");
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-fobjc-gc-only");
|
|
|
|
}
|
|
|
|
}
|
2012-06-20 14:18:46 +08:00
|
|
|
Res.push_back("-fobjc-runtime=" + Opts.ObjCRuntime.getAsString());
|
2011-06-16 07:02:42 +08:00
|
|
|
if (Opts.ObjCAutoRefCount)
|
|
|
|
Res.push_back("-fobjc-arc");
|
2012-08-21 10:47:43 +08:00
|
|
|
if (Opts.ObjCARCWeak)
|
2011-07-06 08:26:06 +08:00
|
|
|
Res.push_back("-fobjc-runtime-has-weak");
|
2011-06-15 07:20:43 +08:00
|
|
|
if (!Opts.ObjCInferRelatedResultType)
|
|
|
|
Res.push_back("-fno-objc-infer-related-result-type");
|
|
|
|
|
2011-01-07 09:05:02 +08:00
|
|
|
if (Opts.AppleKext)
|
|
|
|
Res.push_back("-fapple-kext");
|
2012-06-28 16:01:44 +08:00
|
|
|
|
2010-10-23 05:05:15 +08:00
|
|
|
if (Opts.getVisibilityMode() != DefaultVisibility) {
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-fvisibility");
|
2010-10-23 05:05:15 +08:00
|
|
|
if (Opts.getVisibilityMode() == HiddenVisibility) {
|
2009-11-20 04:54:59 +08:00
|
|
|
Res.push_back("hidden");
|
2009-11-17 14:02:29 +08:00
|
|
|
} else {
|
2010-10-23 05:05:15 +08:00
|
|
|
assert(Opts.getVisibilityMode() == ProtectedVisibility &&
|
2009-11-17 14:02:29 +08:00
|
|
|
"Invalid visibility!");
|
|
|
|
Res.push_back("protected");
|
|
|
|
}
|
|
|
|
}
|
2010-06-16 01:05:35 +08:00
|
|
|
if (Opts.InlineVisibilityHidden)
|
|
|
|
Res.push_back("-fvisibility-inlines-hidden");
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2012-03-26 23:39:31 +08:00
|
|
|
if (Opts.getStackProtector() != 0)
|
|
|
|
Res.push_back("-stack-protector", llvm::utostr(Opts.getStackProtector()));
|
|
|
|
if (Opts.InstantiationDepth != DefaultLangOpts.InstantiationDepth)
|
|
|
|
Res.push_back("-ftemplate-depth", llvm::utostr(Opts.InstantiationDepth));
|
|
|
|
if (Opts.ConstexprCallDepth != DefaultLangOpts.ConstexprCallDepth)
|
|
|
|
Res.push_back("-fconstexpr-depth", llvm::utostr(Opts.ConstexprCallDepth));
|
|
|
|
if (!Opts.ObjCConstantStringClass.empty())
|
|
|
|
Res.push_back("-fconstant-string-class", Opts.ObjCConstantStringClass);
|
2011-03-19 06:38:29 +08:00
|
|
|
if (Opts.FakeAddressSpaceMap)
|
|
|
|
Res.push_back("-ffake-address-space-map");
|
2011-04-10 06:50:59 +08:00
|
|
|
if (Opts.ParseUnknownAnytype)
|
|
|
|
Res.push_back("-funknown-anytype");
|
2011-07-14 01:56:40 +08:00
|
|
|
if (Opts.DebuggerSupport)
|
|
|
|
Res.push_back("-fdebugger-support");
|
2012-02-04 09:29:37 +08:00
|
|
|
if (Opts.DebuggerCastResultToId)
|
|
|
|
Res.push_back("-fdebugger-cast-result-to-id");
|
2012-03-07 04:06:33 +08:00
|
|
|
if (Opts.DebuggerObjCLiteral)
|
|
|
|
Res.push_back("-fdebugger-objc-literal");
|
2011-04-23 06:18:13 +08:00
|
|
|
if (Opts.DelayedTemplateParsing)
|
|
|
|
Res.push_back("-fdelayed-template-parsing");
|
2011-04-24 03:48:40 +08:00
|
|
|
if (Opts.Deprecated)
|
|
|
|
Res.push_back("-fdeprecated-macro");
|
2011-11-02 09:53:16 +08:00
|
|
|
if (Opts.ApplePragmaPack)
|
|
|
|
Res.push_back("-fapple-pragma-pack");
|
2011-11-16 03:35:01 +08:00
|
|
|
if (!Opts.CurrentModule.empty())
|
|
|
|
Res.push_back("-fmodule-name=" + Opts.CurrentModule);
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts,
|
2012-03-26 23:39:31 +08:00
|
|
|
ToArgsList &Res) {
|
2009-11-17 14:02:29 +08:00
|
|
|
for (unsigned i = 0, e = Opts.Macros.size(); i != e; ++i)
|
2009-11-26 10:14:07 +08:00
|
|
|
Res.push_back(std::string(Opts.Macros[i].second ? "-U" : "-D") +
|
|
|
|
Opts.Macros[i].first);
|
2009-11-17 14:02:29 +08:00
|
|
|
for (unsigned i = 0, e = Opts.Includes.size(); i != e; ++i) {
|
2009-11-26 10:14:07 +08:00
|
|
|
// FIXME: We need to avoid reincluding the implicit PCH and PTH includes.
|
2012-03-26 23:39:31 +08:00
|
|
|
Res.push_back("-include", Opts.Includes[i]);
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
2012-03-26 23:39:31 +08:00
|
|
|
for (unsigned i = 0, e = Opts.MacroIncludes.size(); i != e; ++i)
|
|
|
|
Res.push_back("-imacros", Opts.MacroIncludes[i]);
|
2009-11-17 14:02:29 +08:00
|
|
|
if (!Opts.UsePredefines)
|
|
|
|
Res.push_back("-undef");
|
2010-03-20 00:15:56 +08:00
|
|
|
if (Opts.DetailedRecord)
|
|
|
|
Res.push_back("-detailed-preprocessing-record");
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.ImplicitPCHInclude.empty())
|
|
|
|
Res.push_back("-include-pch", Opts.ImplicitPCHInclude);
|
|
|
|
if (!Opts.ImplicitPTHInclude.empty())
|
|
|
|
Res.push_back("-include-pth", Opts.ImplicitPTHInclude);
|
2009-11-17 14:02:29 +08:00
|
|
|
if (!Opts.TokenCache.empty()) {
|
2012-03-26 23:39:31 +08:00
|
|
|
if (Opts.ImplicitPTHInclude.empty())
|
|
|
|
Res.push_back("-token-cache", Opts.TokenCache);
|
|
|
|
else
|
2009-11-26 10:14:07 +08:00
|
|
|
assert(Opts.ImplicitPTHInclude == Opts.TokenCache &&
|
|
|
|
"Unsupported option combination!");
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
2012-03-26 23:39:31 +08:00
|
|
|
for (unsigned i = 0, e = Opts.ChainedIncludes.size(); i != e; ++i)
|
|
|
|
Res.push_back("-chain-include", Opts.ChainedIncludes[i]);
|
2009-12-03 13:11:16 +08:00
|
|
|
for (unsigned i = 0, e = Opts.RemappedFiles.size(); i != e; ++i) {
|
2012-03-26 23:39:31 +08:00
|
|
|
Res.push_back("-remap-file", Opts.RemappedFiles[i].first + ";" +
|
|
|
|
Opts.RemappedFiles[i].second);
|
2009-12-03 13:11:16 +08:00
|
|
|
}
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PreprocessorOutputOptsToArgs(const PreprocessorOutputOptions &Opts,
|
2012-03-26 23:39:31 +08:00
|
|
|
ToArgsList &Res) {
|
2009-11-17 14:02:29 +08:00
|
|
|
if (!Opts.ShowCPP && !Opts.ShowMacros)
|
2010-04-08 06:58:06 +08:00
|
|
|
llvm::report_fatal_error("Invalid option combination!");
|
2009-11-17 14:02:29 +08:00
|
|
|
|
|
|
|
if (Opts.ShowCPP && Opts.ShowMacros)
|
|
|
|
Res.push_back("-dD");
|
|
|
|
else if (!Opts.ShowCPP && Opts.ShowMacros)
|
|
|
|
Res.push_back("-dM");
|
|
|
|
|
|
|
|
if (!Opts.ShowLineMarkers)
|
|
|
|
Res.push_back("-P");
|
|
|
|
if (Opts.ShowComments)
|
|
|
|
Res.push_back("-C");
|
|
|
|
if (Opts.ShowMacroComments)
|
|
|
|
Res.push_back("-CC");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TargetOptsToArgs(const TargetOptions &Opts,
|
2012-03-26 23:39:31 +08:00
|
|
|
ToArgsList &Res) {
|
2009-11-17 14:02:29 +08:00
|
|
|
Res.push_back("-triple");
|
|
|
|
Res.push_back(Opts.Triple);
|
2012-03-26 23:39:31 +08:00
|
|
|
if (!Opts.CPU.empty())
|
|
|
|
Res.push_back("-target-cpu", Opts.CPU);
|
|
|
|
if (!Opts.ABI.empty())
|
|
|
|
Res.push_back("-target-abi", Opts.ABI);
|
|
|
|
if (!Opts.LinkerVersion.empty())
|
|
|
|
Res.push_back("-target-linker-version", Opts.LinkerVersion);
|
|
|
|
if (!Opts.CXXABI.empty())
|
|
|
|
Res.push_back("-cxx-abi", Opts.CXXABI);
|
|
|
|
for (unsigned i = 0, e = Opts.Features.size(); i != e; ++i)
|
|
|
|
Res.push_back("-target-feature", Opts.Features[i]);
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
|
|
|
|
2012-06-11 11:34:26 +08:00
|
|
|
void CompilerInvocation::toArgs(std::vector<std::string> &Res) const {
|
2012-03-26 23:39:31 +08:00
|
|
|
ToArgsList List(Res);
|
|
|
|
AnalyzerOptsToArgs(getAnalyzerOpts(), List);
|
|
|
|
CodeGenOptsToArgs(getCodeGenOpts(), List);
|
|
|
|
DependencyOutputOptsToArgs(getDependencyOutputOpts(), List);
|
|
|
|
DiagnosticOptsToArgs(getDiagnosticOpts(), List);
|
|
|
|
FileSystemOptsToArgs(getFileSystemOpts(), List);
|
|
|
|
FrontendOptsToArgs(getFrontendOpts(), List);
|
|
|
|
HeaderSearchOptsToArgs(getHeaderSearchOpts(), List);
|
|
|
|
LangOptsToArgs(*getLangOpts(), List);
|
|
|
|
PreprocessorOptsToArgs(getPreprocessorOpts(), List);
|
|
|
|
PreprocessorOutputOptsToArgs(getPreprocessorOutputOpts(), List);
|
|
|
|
TargetOptsToArgs(getTargetOpts(), List);
|
2009-11-17 14:02:29 +08:00
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Deserialization (to args)
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
using namespace clang::driver;
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace clang::driver::options;
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2010-12-04 09:50:36 +08:00
|
|
|
static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2010-12-04 09:50:45 +08:00
|
|
|
unsigned DefaultOpt = 0;
|
|
|
|
if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable))
|
|
|
|
DefaultOpt = 2;
|
2012-05-01 22:57:16 +08:00
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
|
|
|
|
if (A->getOption().matches(options::OPT_O0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
assert (A->getOption().matches(options::OPT_O));
|
|
|
|
|
|
|
|
llvm::StringRef S(A->getValue(Args));
|
|
|
|
if (S == "s" || S == "z" || S.empty())
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
return Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefaultOpt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getOptimizationLevelSize(ArgList &Args, InputKind IK,
|
|
|
|
DiagnosticsEngine &Diags) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
|
|
|
|
if (A->getOption().matches(options::OPT_O)) {
|
|
|
|
switch (A->getValue(Args)[0]) {
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case 's':
|
|
|
|
return 1;
|
|
|
|
case 'z':
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addWarningArgs(ArgList &Args, std::vector<std::string> &Warnings) {
|
|
|
|
for (arg_iterator I = Args.filtered_begin(OPT_W_Group),
|
|
|
|
E = Args.filtered_end(); I != E; ++I) {
|
|
|
|
Arg *A = *I;
|
|
|
|
// If the argument is a pure flag, add its name (minus the "-W" at the beginning)
|
|
|
|
// to the warning list. Else, add its value (for the OPT_W case).
|
|
|
|
if (A->getOption().getKind() == Option::FlagClass) {
|
|
|
|
Warnings.push_back(A->getOption().getName().substr(2));
|
|
|
|
} else {
|
|
|
|
for (unsigned Idx = 0, End = A->getNumValues();
|
|
|
|
Idx < End; ++Idx) {
|
|
|
|
StringRef V = A->getValue(Args, Idx);
|
|
|
|
// "-Wl," and such are not warning options.
|
|
|
|
// FIXME: Should be handled by putting these in separate flags.
|
|
|
|
if (V.startswith("l,") || V.startswith("a,") || V.startswith("p,"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Warnings.push_back(V);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-04 09:50:36 +08:00
|
|
|
}
|
|
|
|
|
2011-12-23 11:05:38 +08:00
|
|
|
static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2011-12-23 11:05:38 +08:00
|
|
|
bool Success = true;
|
2009-12-01 11:16:53 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_analyzer_store)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name = A->getValue(Args);
|
2009-12-01 11:16:53 +08:00
|
|
|
AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name)
|
|
|
|
#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \
|
|
|
|
.Case(CMDFLAG, NAME##Model)
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
.Default(NumStores);
|
2011-12-23 11:05:38 +08:00
|
|
|
if (Value == NumStores) {
|
2009-12-01 11:16:53 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
2010-06-10 06:30:54 +08:00
|
|
|
<< A->getAsString(Args) << Name;
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
|
|
|
} else {
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.AnalysisStoreOpt = Value;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name = A->getValue(Args);
|
2009-12-01 11:16:53 +08:00
|
|
|
AnalysisConstraints Value = llvm::StringSwitch<AnalysisConstraints>(Name)
|
|
|
|
#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \
|
|
|
|
.Case(CMDFLAG, NAME##Model)
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
.Default(NumConstraints);
|
2011-12-23 11:05:38 +08:00
|
|
|
if (Value == NumConstraints) {
|
2009-12-01 11:16:53 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
2010-06-10 06:30:54 +08:00
|
|
|
<< A->getAsString(Args) << Name;
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
|
|
|
} else {
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.AnalysisConstraintsOpt = Value;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(OPT_analyzer_output)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name = A->getValue(Args);
|
2009-12-01 11:16:53 +08:00
|
|
|
AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name)
|
|
|
|
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) \
|
|
|
|
.Case(CMDFLAG, PD_##NAME)
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
.Default(NUM_ANALYSIS_DIAG_CLIENTS);
|
2011-12-23 11:05:38 +08:00
|
|
|
if (Value == NUM_ANALYSIS_DIAG_CLIENTS) {
|
2009-12-01 11:16:53 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
2010-06-10 06:30:54 +08:00
|
|
|
<< A->getAsString(Args) << Name;
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
|
|
|
} else {
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.AnalysisDiagOpt = Value;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2011-09-30 10:03:00 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) {
|
|
|
|
StringRef Name = A->getValue(Args);
|
|
|
|
AnalysisPurgeMode Value = llvm::StringSwitch<AnalysisPurgeMode>(Name)
|
|
|
|
#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \
|
|
|
|
.Case(CMDFLAG, NAME)
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
.Default(NumPurgeModes);
|
2011-12-23 11:05:38 +08:00
|
|
|
if (Value == NumPurgeModes) {
|
2011-09-30 10:03:00 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< A->getAsString(Args) << Name;
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
|
|
|
} else {
|
2011-09-30 10:03:00 +08:00
|
|
|
Opts.AnalysisPurgeOpt = Value;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2011-09-30 10:03:00 +08:00
|
|
|
}
|
|
|
|
|
2012-03-09 07:16:35 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_analyzer_ipa)) {
|
|
|
|
StringRef Name = A->getValue(Args);
|
|
|
|
AnalysisIPAMode Value = llvm::StringSwitch<AnalysisIPAMode>(Name)
|
|
|
|
#define ANALYSIS_IPA(NAME, CMDFLAG, DESC) \
|
|
|
|
.Case(CMDFLAG, NAME)
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
.Default(NumIPAModes);
|
|
|
|
if (Value == NumIPAModes) {
|
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< A->getAsString(Args) << Name;
|
|
|
|
Success = false;
|
|
|
|
} else {
|
|
|
|
Opts.IPAMode = Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(OPT_analyzer_inlining_mode)) {
|
|
|
|
StringRef Name = A->getValue(Args);
|
|
|
|
AnalysisInliningMode Value = llvm::StringSwitch<AnalysisInliningMode>(Name)
|
|
|
|
#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) \
|
|
|
|
.Case(CMDFLAG, NAME)
|
|
|
|
#include "clang/Frontend/Analyses.def"
|
|
|
|
.Default(NumInliningModes);
|
|
|
|
if (Value == NumInliningModes) {
|
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< A->getAsString(Args) << Name;
|
|
|
|
Success = false;
|
|
|
|
} else {
|
|
|
|
Opts.InliningMode = Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 08:09:51 +08:00
|
|
|
Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.VisualizeEGDot = Args.hasArg(OPT_analyzer_viz_egraph_graphviz);
|
|
|
|
Opts.VisualizeEGUbi = Args.hasArg(OPT_analyzer_viz_egraph_ubigraph);
|
2012-03-29 03:59:16 +08:00
|
|
|
Opts.NoRetryExhausted = Args.hasArg(OPT_analyzer_disable_retry_exhausted);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers);
|
|
|
|
Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress);
|
2009-12-08 06:06:12 +08:00
|
|
|
Opts.AnalyzeNestedBlocks =
|
|
|
|
Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.EagerlyAssume = Args.hasArg(OPT_analyzer_eagerly_assume);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function);
|
2010-08-03 08:09:51 +08:00
|
|
|
Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG);
|
2010-09-30 15:41:24 +08:00
|
|
|
Opts.CFGAddImplicitDtors = Args.hasArg(OPT_analysis_CFGAddImplicitDtors);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.TrimGraph = Args.hasArg(OPT_trim_egraph);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.MaxNodes = Args.getLastArgIntValue(OPT_analyzer_max_nodes, 150000,Diags);
|
2010-10-19 07:36:05 +08:00
|
|
|
Opts.MaxLoop = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags);
|
2011-02-09 09:27:33 +08:00
|
|
|
Opts.EagerlyTrimEGraph = !Args.hasArg(OPT_analyzer_no_eagerly_trim_egraph);
|
2012-02-28 05:33:16 +08:00
|
|
|
Opts.PrintStats = Args.hasArg(OPT_analyzer_stats);
|
2012-03-03 03:05:03 +08:00
|
|
|
Opts.InlineMaxStackDepth =
|
|
|
|
Args.getLastArgIntValue(OPT_analyzer_inline_max_stack_depth,
|
|
|
|
Opts.InlineMaxStackDepth, Diags);
|
|
|
|
Opts.InlineMaxFunctionSize =
|
|
|
|
Args.getLastArgIntValue(OPT_analyzer_inline_max_function_size,
|
|
|
|
Opts.InlineMaxFunctionSize, Diags);
|
2011-02-15 02:13:31 +08:00
|
|
|
|
|
|
|
Opts.CheckersControlList.clear();
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_analyzer_checker,
|
|
|
|
OPT_analyzer_disable_checker),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
const Arg *A = *it;
|
|
|
|
A->claim();
|
|
|
|
bool enable = (A->getOption().getID() == OPT_analyzer_checker);
|
2011-02-24 16:42:20 +08:00
|
|
|
// We can have a list of comma separated checker names, e.g:
|
|
|
|
// '-analyzer-checker=cocoa,unix'
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef checkerList = A->getValue(Args);
|
|
|
|
SmallVector<StringRef, 4> checkers;
|
2011-02-24 16:42:20 +08:00
|
|
|
checkerList.split(checkers, ",");
|
|
|
|
for (unsigned i = 0, e = checkers.size(); i != e; ++i)
|
|
|
|
Opts.CheckersControlList.push_back(std::make_pair(checkers[i], enable));
|
2011-02-15 02:13:31 +08:00
|
|
|
}
|
2012-08-29 13:55:00 +08:00
|
|
|
|
|
|
|
// Go through the analyzer configuration options.
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_analyzer_config),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
const Arg *A = *it;
|
|
|
|
A->claim();
|
|
|
|
// We can have a list of comma separated config names, e.g:
|
2012-08-30 13:49:16 +08:00
|
|
|
// '-analyzer-config key1=val1,key2=val2'
|
2012-08-29 13:55:00 +08:00
|
|
|
StringRef configList = A->getValue(Args);
|
|
|
|
SmallVector<StringRef, 4> configVals;
|
|
|
|
configList.split(configVals, ",");
|
|
|
|
for (unsigned i = 0, e = configVals.size(); i != e; ++i) {
|
|
|
|
StringRef key, val;
|
2012-08-30 13:49:16 +08:00
|
|
|
llvm::tie(key, val) = configVals[i].split("=");
|
2012-08-29 13:55:00 +08:00
|
|
|
if (val.empty()) {
|
|
|
|
Diags.Report(SourceLocation(),
|
|
|
|
diag::err_analyzer_config_no_value) << configVals[i];
|
|
|
|
Success = false;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-30 13:49:16 +08:00
|
|
|
if (val.find('=') != StringRef::npos) {
|
2012-08-29 13:55:00 +08:00
|
|
|
Diags.Report(SourceLocation(),
|
|
|
|
diag::err_analyzer_config_multiple_values)
|
|
|
|
<< configVals[i];
|
|
|
|
Success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Opts.Config[key] = val;
|
|
|
|
}
|
|
|
|
}
|
2011-12-23 11:05:38 +08:00
|
|
|
|
|
|
|
return Success;
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2012-01-25 08:20:29 +08:00
|
|
|
static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) {
|
|
|
|
Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error);
|
2012-01-27 04:57:58 +08:00
|
|
|
Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal);
|
2012-01-25 08:20:29 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-23 11:05:38 +08:00
|
|
|
static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2011-12-23 11:05:38 +08:00
|
|
|
bool Success = true;
|
2010-12-04 09:50:36 +08:00
|
|
|
|
2012-02-06 08:40:31 +08:00
|
|
|
unsigned OptLevel = getOptimizationLevel(Args, IK, Diags);
|
|
|
|
if (OptLevel > 3) {
|
2010-12-04 09:50:36 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
2012-02-06 08:40:31 +08:00
|
|
|
<< Args.getLastArg(OPT_O)->getAsString(Args) << OptLevel;
|
|
|
|
OptLevel = 3;
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
2012-02-06 08:40:31 +08:00
|
|
|
Opts.OptimizationLevel = OptLevel;
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
// We must always run at least the always inlining pass.
|
|
|
|
Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
|
|
|
|
: CodeGenOptions::OnlyAlwaysInlining;
|
2012-03-07 05:17:19 +08:00
|
|
|
// -fno-inline-functions overrides OptimizationLevel > 1.
|
2012-03-16 06:31:42 +08:00
|
|
|
Opts.NoInline = Args.hasArg(OPT_fno_inline);
|
2012-04-27 15:24:20 +08:00
|
|
|
Opts.Inlining = Args.hasArg(OPT_fno_inline_functions) ?
|
2012-03-16 06:31:42 +08:00
|
|
|
CodeGenOptions::OnlyAlwaysInlining : Opts.Inlining;
|
2009-12-01 11:16:53 +08:00
|
|
|
|
2012-05-04 15:39:27 +08:00
|
|
|
if (Args.hasArg(OPT_gline_tables_only)) {
|
|
|
|
Opts.DebugInfo = CodeGenOptions::DebugLineTablesOnly;
|
|
|
|
} else if (Args.hasArg(OPT_g_Flag)) {
|
2012-04-27 15:24:20 +08:00
|
|
|
if (Args.hasFlag(OPT_flimit_debug_info, OPT_fno_limit_debug_info, true))
|
|
|
|
Opts.DebugInfo = CodeGenOptions::LimitedDebugInfo;
|
|
|
|
else
|
|
|
|
Opts.DebugInfo = CodeGenOptions::FullDebugInfo;
|
|
|
|
}
|
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
|
|
|
|
Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
|
2011-03-18 10:56:14 +08:00
|
|
|
Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
|
IRgen: Add a -fuse-register-sized-bitfield-access option, for testing.
- Changes bit-field access policy to try to use (aligned) register sized accesses.
The idea here is that by using larger accesses we expose more coalescing
potential to the backend when we have situations like adjacent bit-fields in the
same structure (which is common), and that the backend should be smart enough to
narrow the accesses down when no coalescing is done or when it is shown not to
be profitable.
--
$ clang -m32 -O3 -S -o - t.c
_f0: ## @f0
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movb (%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, (%eax)
movb 1(%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, 1(%eax)
movb 2(%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, 2(%eax)
movb 3(%eax), %cl
andb $-128, %cl
orb $1, %cl
movb %cl, 3(%eax)
popl %ebp
ret
$ clang -m32 -O3 -S -o - t.c -Xclang -fuse-register-sized-bitfield-access
_f0: ## @f0
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl $-2139062144, %ecx ## imm = 0xFFFFFFFF80808080
andl (%eax), %ecx
orl $16843009, %ecx ## imm = 0x1010101
movl %ecx, (%eax)
popl %ebp
ret
--
llvm-svn: 133532
2011-06-22 02:54:46 +08:00
|
|
|
Opts.UseRegisterSizedBitfieldAccess = Args.hasArg(
|
|
|
|
OPT_fuse_register_sized_bitfield_access);
|
2010-10-15 06:36:56 +08:00
|
|
|
Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
|
|
|
|
Opts.NoCommon = Args.hasArg(OPT_fno_common);
|
|
|
|
Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
|
2012-05-01 22:57:16 +08:00
|
|
|
Opts.OptimizeSize = getOptimizationLevelSize(Args, IK, Diags);
|
2010-06-08 07:19:17 +08:00
|
|
|
Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) ||
|
|
|
|
Args.hasArg(OPT_ffreestanding));
|
2010-10-21 11:16:25 +08:00
|
|
|
Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) ||
|
2010-08-08 07:08:14 +08:00
|
|
|
(Opts.OptimizationLevel > 1 && !Opts.OptimizeSize);
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
|
2011-06-16 07:02:42 +08:00
|
|
|
Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
|
2011-10-07 02:29:46 +08:00
|
|
|
Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device);
|
2010-03-20 12:15:41 +08:00
|
|
|
Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit);
|
|
|
|
Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.CodeModel = Args.getLastArgValue(OPT_mcode_model);
|
|
|
|
Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
|
2012-01-23 16:29:12 +08:00
|
|
|
Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
|
2010-08-13 07:36:15 +08:00
|
|
|
Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables);
|
2010-12-04 09:51:33 +08:00
|
|
|
Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision);
|
2011-12-10 07:41:18 +08:00
|
|
|
Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) ||
|
|
|
|
Args.hasArg(OPT_cl_finite_math_only)||
|
|
|
|
Args.hasArg(OPT_cl_fast_relaxed_math));
|
|
|
|
Opts.NoNaNsFPMath = (Args.hasArg(OPT_menable_no_nans) ||
|
|
|
|
Args.hasArg(OPT_cl_finite_math_only)||
|
|
|
|
Args.hasArg(OPT_cl_fast_relaxed_math));
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
|
2011-03-23 00:48:17 +08:00
|
|
|
Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option);
|
2011-02-10 01:54:19 +08:00
|
|
|
Opts.NumRegisterParameters = Args.getLastArgIntValue(OPT_mregparm, 0, Diags);
|
2011-08-26 08:26:29 +08:00
|
|
|
Opts.NoGlobalMerge = Args.hasArg(OPT_mno_global_merge);
|
2011-06-21 08:14:18 +08:00
|
|
|
Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
|
2010-05-27 13:39:39 +08:00
|
|
|
Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
|
2010-07-01 09:31:45 +08:00
|
|
|
Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
|
2011-03-29 06:49:28 +08:00
|
|
|
Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
|
2011-05-01 02:35:43 +08:00
|
|
|
Opts.NoDwarf2CFIAsm = Args.hasArg(OPT_fno_dwarf2_cfi_asm);
|
2011-10-18 07:05:52 +08:00
|
|
|
Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
|
2012-03-28 07:58:37 +08:00
|
|
|
Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums);
|
2012-01-02 22:19:45 +08:00
|
|
|
Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
|
|
|
|
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
|
2010-12-04 09:51:23 +08:00
|
|
|
Args.hasArg(OPT_cl_fast_relaxed_math);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.UnwindTables = Args.hasArg(OPT_munwind_tables);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
|
2012-02-03 14:27:22 +08:00
|
|
|
Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ);
|
2012-05-23 01:19:45 +08:00
|
|
|
Opts.BoundsChecking = Args.getLastArgIntValue(OPT_fbounds_checking_EQ, 0,
|
|
|
|
Diags);
|
2012-06-19 09:26:10 +08:00
|
|
|
Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array);
|
2009-12-01 11:16:53 +08:00
|
|
|
|
2010-04-13 08:38:24 +08:00
|
|
|
Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections);
|
|
|
|
Opts.DataSections = Args.hasArg(OPT_fdata_sections);
|
|
|
|
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
|
2010-02-13 07:47:27 +08:00
|
|
|
Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier);
|
2010-04-25 01:56:46 +08:00
|
|
|
|
2010-06-22 08:03:40 +08:00
|
|
|
Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
|
2011-02-11 00:52:03 +08:00
|
|
|
Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
|
2011-04-22 07:44:07 +08:00
|
|
|
Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);
|
|
|
|
Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);
|
2012-07-12 07:02:10 +08:00
|
|
|
Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
|
2011-05-05 08:08:20 +08:00
|
|
|
Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);
|
2011-10-21 10:32:14 +08:00
|
|
|
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
|
2011-10-31 01:30:44 +08:00
|
|
|
Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file);
|
2012-08-22 00:16:06 +08:00
|
|
|
Opts.SSPBufferSize =
|
|
|
|
Args.getLastArgIntValue(OPT_stack_protector_buffer_size, 8, Diags);
|
2011-12-06 11:33:03 +08:00
|
|
|
Opts.StackRealignment = Args.hasArg(OPT_mstackrealign);
|
2011-12-06 07:05:23 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) {
|
|
|
|
StringRef Val = A->getValue(Args);
|
|
|
|
Val.getAsInteger(10, Opts.StackAlignment);
|
|
|
|
}
|
2010-06-22 08:03:40 +08:00
|
|
|
|
2010-04-25 01:56:46 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name = A->getValue(Args);
|
2010-04-25 01:56:46 +08:00
|
|
|
unsigned Method = llvm::StringSwitch<unsigned>(Name)
|
|
|
|
.Case("legacy", CodeGenOptions::Legacy)
|
|
|
|
.Case("non-legacy", CodeGenOptions::NonLegacy)
|
|
|
|
.Case("mixed", CodeGenOptions::Mixed)
|
|
|
|
.Default(~0U);
|
2011-12-23 11:05:38 +08:00
|
|
|
if (Method == ~0U) {
|
2010-04-25 01:56:46 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
|
|
|
} else {
|
2010-04-25 01:56:46 +08:00
|
|
|
Opts.ObjCDispatchMethod = Method;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2010-04-25 01:56:46 +08:00
|
|
|
}
|
2011-12-23 11:05:38 +08:00
|
|
|
|
2012-06-28 16:01:44 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
|
|
|
|
StringRef Name = A->getValue(Args);
|
|
|
|
unsigned Model = llvm::StringSwitch<unsigned>(Name)
|
|
|
|
.Case("global-dynamic", CodeGenOptions::GeneralDynamicTLSModel)
|
|
|
|
.Case("local-dynamic", CodeGenOptions::LocalDynamicTLSModel)
|
|
|
|
.Case("initial-exec", CodeGenOptions::InitialExecTLSModel)
|
|
|
|
.Case("local-exec", CodeGenOptions::LocalExecTLSModel)
|
|
|
|
.Default(~0U);
|
|
|
|
if (Model == ~0U) {
|
|
|
|
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
|
|
|
|
Success = false;
|
|
|
|
} else {
|
|
|
|
Opts.DefaultTLSModel = static_cast<CodeGenOptions::TLSModel>(Model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-23 11:05:38 +08:00
|
|
|
return Success;
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
|
|
|
|
ArgList &Args) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file);
|
|
|
|
Opts.Targets = Args.getAllArgValues(OPT_MT);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps);
|
|
|
|
Opts.UsePhonyTargets = Args.hasArg(OPT_MP);
|
2011-02-02 23:41:17 +08:00
|
|
|
Opts.ShowHeaderIncludes = Args.hasArg(OPT_H);
|
2011-02-03 05:11:31 +08:00
|
|
|
Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file);
|
2011-07-13 03:35:15 +08:00
|
|
|
Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG);
|
2012-02-03 07:45:13 +08:00
|
|
|
Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot);
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:09:56 +08:00
|
|
|
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
|
|
|
|
DiagnosticsEngine *Diags) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2011-12-23 11:05:38 +08:00
|
|
|
bool Success = true;
|
|
|
|
|
2011-04-08 02:11:14 +08:00
|
|
|
Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file);
|
2011-10-29 08:12:39 +08:00
|
|
|
Opts.DiagnosticSerializationFile =
|
|
|
|
Args.getLastArgValue(OPT_diagnostic_serialized_file);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.IgnoreWarnings = Args.hasArg(OPT_w);
|
|
|
|
Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros);
|
|
|
|
Opts.Pedantic = Args.hasArg(OPT_pedantic);
|
|
|
|
Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors);
|
|
|
|
Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics);
|
|
|
|
Opts.ShowColors = Args.hasArg(OPT_fcolor_diagnostics);
|
2011-05-22 01:07:29 +08:00
|
|
|
Opts.ShowColumn = Args.hasFlag(OPT_fshow_column,
|
|
|
|
OPT_fno_show_column,
|
|
|
|
/*Default=*/true);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
|
|
|
|
Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
|
|
|
|
Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
|
2010-06-11 13:57:47 +08:00
|
|
|
|
2011-03-28 04:00:08 +08:00
|
|
|
// Default behavior is to not to show note include stacks.
|
|
|
|
Opts.ShowNoteIncludeStack = false;
|
2011-03-27 09:50:55 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
|
|
|
|
OPT_fno_diagnostics_show_note_include_stack))
|
2011-03-28 04:00:08 +08:00
|
|
|
if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack))
|
|
|
|
Opts.ShowNoteIncludeStack = true;
|
2011-03-27 09:50:55 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef ShowOverloads =
|
2010-06-11 13:57:47 +08:00
|
|
|
Args.getLastArgValue(OPT_fshow_overloads_EQ, "all");
|
|
|
|
if (ShowOverloads == "best")
|
2011-09-26 07:23:43 +08:00
|
|
|
Opts.ShowOverloads = DiagnosticsEngine::Ovl_Best;
|
2010-06-11 13:57:47 +08:00
|
|
|
else if (ShowOverloads == "all")
|
2011-09-26 07:23:43 +08:00
|
|
|
Opts.ShowOverloads = DiagnosticsEngine::Ovl_All;
|
2011-12-23 11:05:38 +08:00
|
|
|
else {
|
2012-03-14 04:09:56 +08:00
|
|
|
Success = false;
|
|
|
|
if (Diags)
|
|
|
|
Diags->Report(diag::err_drv_invalid_value)
|
2010-06-11 13:57:47 +08:00
|
|
|
<< Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args)
|
|
|
|
<< ShowOverloads;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2010-06-11 13:57:47 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef ShowCategory =
|
2010-05-21 00:54:55 +08:00
|
|
|
Args.getLastArgValue(OPT_fdiagnostics_show_category, "none");
|
2010-05-05 05:55:25 +08:00
|
|
|
if (ShowCategory == "none")
|
|
|
|
Opts.ShowCategories = 0;
|
|
|
|
else if (ShowCategory == "id")
|
|
|
|
Opts.ShowCategories = 1;
|
|
|
|
else if (ShowCategory == "name")
|
|
|
|
Opts.ShowCategories = 2;
|
2011-12-23 11:05:38 +08:00
|
|
|
else {
|
2012-03-14 04:09:56 +08:00
|
|
|
Success = false;
|
|
|
|
if (Diags)
|
|
|
|
Diags->Report(diag::err_drv_invalid_value)
|
2010-05-05 05:55:25 +08:00
|
|
|
<< Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args)
|
|
|
|
<< ShowCategory;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Format =
|
2011-05-22 01:07:29 +08:00
|
|
|
Args.getLastArgValue(OPT_fdiagnostics_format, "clang");
|
|
|
|
if (Format == "clang")
|
|
|
|
Opts.Format = DiagnosticOptions::Clang;
|
2011-12-23 11:05:38 +08:00
|
|
|
else if (Format == "msvc")
|
2011-05-22 01:07:29 +08:00
|
|
|
Opts.Format = DiagnosticOptions::Msvc;
|
2011-12-23 11:05:38 +08:00
|
|
|
else if (Format == "vi")
|
2011-05-22 01:07:29 +08:00
|
|
|
Opts.Format = DiagnosticOptions::Vi;
|
2011-12-23 11:05:38 +08:00
|
|
|
else {
|
2012-03-14 04:09:56 +08:00
|
|
|
Success = false;
|
|
|
|
if (Diags)
|
|
|
|
Diags->Report(diag::err_drv_invalid_value)
|
2011-05-22 01:07:29 +08:00
|
|
|
<< Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args)
|
|
|
|
<< Format;
|
2011-12-23 11:05:38 +08:00
|
|
|
}
|
2011-05-22 01:07:29 +08:00
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info);
|
2010-08-20 04:24:43 +08:00
|
|
|
Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.VerifyDiagnostics = Args.hasArg(OPT_verify);
|
2012-06-27 02:18:47 +08:00
|
|
|
Opts.ElideType = !Args.hasArg(OPT_fno_elide_type);
|
|
|
|
Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.ErrorLimit = Args.getLastArgIntValue(OPT_ferror_limit, 0, Diags);
|
2010-05-05 01:13:42 +08:00
|
|
|
Opts.MacroBacktraceLimit
|
2010-10-21 11:16:25 +08:00
|
|
|
= Args.getLastArgIntValue(OPT_fmacro_backtrace_limit,
|
2010-05-05 01:13:42 +08:00
|
|
|
DiagnosticOptions::DefaultMacroBacktraceLimit, Diags);
|
2010-04-20 15:18:24 +08:00
|
|
|
Opts.TemplateBacktraceLimit
|
2010-10-21 11:16:25 +08:00
|
|
|
= Args.getLastArgIntValue(OPT_ftemplate_backtrace_limit,
|
|
|
|
DiagnosticOptions::DefaultTemplateBacktraceLimit,
|
2010-05-05 01:13:42 +08:00
|
|
|
Diags);
|
2011-12-17 03:06:07 +08:00
|
|
|
Opts.ConstexprBacktraceLimit
|
|
|
|
= Args.getLastArgIntValue(OPT_fconstexpr_backtrace_limit,
|
|
|
|
DiagnosticOptions::DefaultConstexprBacktraceLimit,
|
|
|
|
Diags);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.TabStop = Args.getLastArgIntValue(OPT_ftabstop,
|
2010-01-13 11:06:50 +08:00
|
|
|
DiagnosticOptions::DefaultTabStop, Diags);
|
|
|
|
if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) {
|
|
|
|
Opts.TabStop = DiagnosticOptions::DefaultTabStop;
|
2012-03-14 04:09:56 +08:00
|
|
|
if (Diags)
|
|
|
|
Diags->Report(diag::warn_ignoring_ftabstop_value)
|
|
|
|
<< Opts.TabStop << DiagnosticOptions::DefaultTabStop;
|
2010-01-13 11:06:50 +08:00
|
|
|
}
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.MessageLength = Args.getLastArgIntValue(OPT_fmessage_length, 0, Diags);
|
|
|
|
Opts.DumpBuildInformation = Args.getLastArgValue(OPT_dump_build_information);
|
2012-05-01 22:57:16 +08:00
|
|
|
addWarningArgs(Args, Opts.Warnings);
|
2011-12-23 11:05:38 +08:00
|
|
|
|
|
|
|
return Success;
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2010-11-04 06:45:23 +08:00
|
|
|
static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) {
|
|
|
|
Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory);
|
|
|
|
}
|
|
|
|
|
2010-06-08 07:22:09 +08:00
|
|
|
static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ProgramAction = frontend::ParseSyntaxOnly;
|
|
|
|
if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
|
|
|
|
switch (A->getOption().getID()) {
|
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Invalid option in group!");
|
2012-07-31 17:37:40 +08:00
|
|
|
case OPT_ast_list:
|
|
|
|
Opts.ProgramAction = frontend::ASTDeclList; break;
|
2009-12-01 11:16:53 +08:00
|
|
|
case OPT_ast_dump:
|
|
|
|
Opts.ProgramAction = frontend::ASTDump; break;
|
2010-11-24 19:21:45 +08:00
|
|
|
case OPT_ast_dump_xml:
|
|
|
|
Opts.ProgramAction = frontend::ASTDumpXML; break;
|
2009-12-01 11:16:53 +08:00
|
|
|
case OPT_ast_print:
|
|
|
|
Opts.ProgramAction = frontend::ASTPrint; break;
|
|
|
|
case OPT_ast_view:
|
|
|
|
Opts.ProgramAction = frontend::ASTView; break;
|
|
|
|
case OPT_dump_raw_tokens:
|
|
|
|
Opts.ProgramAction = frontend::DumpRawTokens; break;
|
|
|
|
case OPT_dump_tokens:
|
|
|
|
Opts.ProgramAction = frontend::DumpTokens; break;
|
|
|
|
case OPT_S:
|
|
|
|
Opts.ProgramAction = frontend::EmitAssembly; break;
|
|
|
|
case OPT_emit_llvm_bc:
|
|
|
|
Opts.ProgramAction = frontend::EmitBC; break;
|
|
|
|
case OPT_emit_html:
|
|
|
|
Opts.ProgramAction = frontend::EmitHTML; break;
|
|
|
|
case OPT_emit_llvm:
|
|
|
|
Opts.ProgramAction = frontend::EmitLLVM; break;
|
|
|
|
case OPT_emit_llvm_only:
|
|
|
|
Opts.ProgramAction = frontend::EmitLLVMOnly; break;
|
2010-05-26 02:41:01 +08:00
|
|
|
case OPT_emit_codegen_only:
|
|
|
|
Opts.ProgramAction = frontend::EmitCodeGenOnly; break;
|
2010-02-03 09:18:43 +08:00
|
|
|
case OPT_emit_obj:
|
|
|
|
Opts.ProgramAction = frontend::EmitObj; break;
|
2010-04-24 09:30:46 +08:00
|
|
|
case OPT_fixit_EQ:
|
|
|
|
Opts.FixItSuffix = A->getValue(Args);
|
|
|
|
// fall-through!
|
2009-12-01 11:16:53 +08:00
|
|
|
case OPT_fixit:
|
|
|
|
Opts.ProgramAction = frontend::FixIt; break;
|
2011-08-26 06:30:56 +08:00
|
|
|
case OPT_emit_module:
|
|
|
|
Opts.ProgramAction = frontend::GenerateModule; break;
|
2009-12-01 11:16:53 +08:00
|
|
|
case OPT_emit_pch:
|
|
|
|
Opts.ProgramAction = frontend::GeneratePCH; break;
|
|
|
|
case OPT_emit_pth:
|
|
|
|
Opts.ProgramAction = frontend::GeneratePTH; break;
|
2010-03-20 03:44:04 +08:00
|
|
|
case OPT_init_only:
|
|
|
|
Opts.ProgramAction = frontend::InitOnly; break;
|
2009-12-01 11:16:53 +08:00
|
|
|
case OPT_fsyntax_only:
|
|
|
|
Opts.ProgramAction = frontend::ParseSyntaxOnly; break;
|
|
|
|
case OPT_print_decl_contexts:
|
|
|
|
Opts.ProgramAction = frontend::PrintDeclContext; break;
|
2010-07-21 04:18:03 +08:00
|
|
|
case OPT_print_preamble:
|
|
|
|
Opts.ProgramAction = frontend::PrintPreamble; break;
|
2009-12-01 11:16:53 +08:00
|
|
|
case OPT_E:
|
|
|
|
Opts.ProgramAction = frontend::PrintPreprocessedInput; break;
|
|
|
|
case OPT_rewrite_macros:
|
|
|
|
Opts.ProgramAction = frontend::RewriteMacros; break;
|
|
|
|
case OPT_rewrite_objc:
|
|
|
|
Opts.ProgramAction = frontend::RewriteObjC; break;
|
|
|
|
case OPT_rewrite_test:
|
|
|
|
Opts.ProgramAction = frontend::RewriteTest; break;
|
|
|
|
case OPT_analyze:
|
|
|
|
Opts.ProgramAction = frontend::RunAnalysis; break;
|
2012-03-07 04:06:33 +08:00
|
|
|
case OPT_migrate:
|
|
|
|
Opts.ProgramAction = frontend::MigrateSource; break;
|
2009-12-01 11:16:53 +08:00
|
|
|
case OPT_Eonly:
|
|
|
|
Opts.ProgramAction = frontend::RunPreprocessorOnly; break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-17 00:59:23 +08:00
|
|
|
|
|
|
|
if (const Arg* A = Args.getLastArg(OPT_plugin)) {
|
|
|
|
Opts.Plugins.push_back(A->getValue(Args,0));
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ProgramAction = frontend::PluginAction;
|
|
|
|
Opts.ActionName = A->getValue(Args);
|
2010-06-17 00:59:23 +08:00
|
|
|
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg),
|
|
|
|
end = Args.filtered_end(); it != end; ++it) {
|
|
|
|
if ((*it)->getValue(Args, 0) == Opts.ActionName)
|
|
|
|
Opts.PluginArgs.push_back((*it)->getValue(Args, 1));
|
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2011-01-26 04:34:14 +08:00
|
|
|
Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin);
|
2011-01-30 05:21:49 +08:00
|
|
|
Opts.AddPluginArgs.resize(Opts.AddPluginActions.size());
|
|
|
|
for (int i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) {
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg),
|
|
|
|
end = Args.filtered_end(); it != end; ++it) {
|
|
|
|
if ((*it)->getValue(Args, 0) == Opts.AddPluginActions[i])
|
|
|
|
Opts.AddPluginArgs[i].push_back((*it)->getValue(Args, 1));
|
|
|
|
}
|
|
|
|
}
|
2011-01-26 04:34:14 +08:00
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) {
|
|
|
|
Opts.CodeCompletionAt =
|
|
|
|
ParsedSourceLocation::FromString(A->getValue(Args));
|
|
|
|
if (Opts.CodeCompletionAt.FileName.empty())
|
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< A->getAsString(Args) << A->getValue(Args);
|
|
|
|
}
|
|
|
|
Opts.DisableFree = Args.hasArg(OPT_disable_free);
|
|
|
|
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.OutputFile = Args.getLastArgValue(OPT_o);
|
|
|
|
Opts.Plugins = Args.getAllArgValues(OPT_load);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch);
|
2009-12-03 15:01:58 +08:00
|
|
|
Opts.ShowHelp = Args.hasArg(OPT_help);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ShowStats = Args.hasArg(OPT_print_stats);
|
|
|
|
Opts.ShowTimers = Args.hasArg(OPT_ftime_report);
|
2009-12-03 15:01:58 +08:00
|
|
|
Opts.ShowVersion = Args.hasArg(OPT_version);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
|
|
|
|
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
|
2010-08-14 01:31:00 +08:00
|
|
|
Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can);
|
2012-01-26 10:40:48 +08:00
|
|
|
Opts.FixOnlyWarnings = Args.hasArg(OPT_fix_only_warnings);
|
|
|
|
Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile);
|
|
|
|
Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp);
|
2012-07-27 00:01:23 +08:00
|
|
|
Opts.ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter);
|
2012-07-03 01:35:10 +08:00
|
|
|
|
|
|
|
Opts.CodeCompleteOpts.IncludeMacros
|
|
|
|
= Args.hasArg(OPT_code_completion_macros);
|
|
|
|
Opts.CodeCompleteOpts.IncludeCodePatterns
|
|
|
|
= Args.hasArg(OPT_code_completion_patterns);
|
|
|
|
Opts.CodeCompleteOpts.IncludeGlobals
|
|
|
|
= !Args.hasArg(OPT_no_code_completion_globals);
|
|
|
|
Opts.CodeCompleteOpts.IncludeBriefComments
|
|
|
|
= Args.hasArg(OPT_code_completion_brief_comments);
|
|
|
|
|
Extend the ExternalASTSource interface to allow the AST source to
provide the layout of records, rather than letting Clang compute
the layout itself. LLDB provides the motivation for this feature:
because various layout-altering attributes (packed, aligned, etc.)
don't get reliably get placed into DWARF, the record layouts computed
by LLDB from the reconstructed records differ from the actual layouts,
and badness occurs. This interface lets the DWARF data drive layout,
so we don't need the attributes preserved to get the answer write.
The testing methodology for this change is fun. I've introduced a
variant of -fdump-record-layouts called -fdump-record-layouts-simple
that always has the simple C format and provides size/alignment/field
offsets. There is also a -cc1 option -foverride-record-layout=<file>
to take the output of -fdump-record-layouts-simple and parse it to
produce a set of overridden layouts, which is introduced into the AST
via a testing-only ExternalASTSource (called
LayoutOverrideSource). Each test contains a number of records to lay
out, which use various layout-changing attributes, and then dumps the
layouts. We then run the test again, using the preprocessor to
eliminate the layout-changing attributes entirely (which would give us
different layouts for the records), but supplying the
previously-computed record layouts. Finally, we diff the layouts
produced from the two runs to be sure that they are identical.
Note that this code makes the assumption that we don't *have* to
provide the offsets of bases or virtual bases to get the layout right,
because the alignment attributes don't affect it. I believe this
assumption holds, but if it does not, we can extend
LayoutOverrideSource to also provide base offset information.
Fixes the Clang side of <rdar://problem/10169539>.
llvm-svn: 149055
2012-01-26 15:55:45 +08:00
|
|
|
Opts.OverrideRecordLayoutsFile
|
|
|
|
= Args.getLastArgValue(OPT_foverride_record_layout_EQ);
|
2011-06-16 07:25:17 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(OPT_arcmt_check,
|
2011-07-10 04:00:58 +08:00
|
|
|
OPT_arcmt_modify,
|
|
|
|
OPT_arcmt_migrate)) {
|
2011-06-16 07:25:17 +08:00
|
|
|
switch (A->getOption().getID()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("missed a case");
|
|
|
|
case OPT_arcmt_check:
|
|
|
|
Opts.ARCMTAction = FrontendOptions::ARCMT_Check;
|
|
|
|
break;
|
|
|
|
case OPT_arcmt_modify:
|
|
|
|
Opts.ARCMTAction = FrontendOptions::ARCMT_Modify;
|
|
|
|
break;
|
2011-07-10 04:00:58 +08:00
|
|
|
case OPT_arcmt_migrate:
|
|
|
|
Opts.ARCMTAction = FrontendOptions::ARCMT_Migrate;
|
|
|
|
break;
|
2011-06-16 07:25:17 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-07 04:06:33 +08:00
|
|
|
Opts.MTMigrateDir = Args.getLastArgValue(OPT_mt_migrate_directory);
|
2011-07-20 01:20:03 +08:00
|
|
|
Opts.ARCMTMigrateReportOut
|
|
|
|
= Args.getLastArgValue(OPT_arcmt_migrate_report_output);
|
|
|
|
Opts.ARCMTMigrateEmitARCErrors
|
|
|
|
= Args.hasArg(OPT_arcmt_migrate_emit_arc_errors);
|
2011-06-16 07:25:17 +08:00
|
|
|
|
2012-03-07 04:06:33 +08:00
|
|
|
if (Args.hasArg(OPT_objcmt_migrate_literals))
|
|
|
|
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Literals;
|
|
|
|
if (Args.hasArg(OPT_objcmt_migrate_subscripting))
|
|
|
|
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Subscripting;
|
|
|
|
|
|
|
|
if (Opts.ARCMTAction != FrontendOptions::ARCMT_None &&
|
|
|
|
Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) {
|
|
|
|
Diags.Report(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< "ARC migration" << "ObjC migration";
|
|
|
|
}
|
|
|
|
|
2010-06-08 07:22:09 +08:00
|
|
|
InputKind DashX = IK_None;
|
2009-12-01 11:16:53 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(OPT_x)) {
|
2010-06-08 07:22:09 +08:00
|
|
|
DashX = llvm::StringSwitch<InputKind>(A->getValue(Args))
|
|
|
|
.Case("c", IK_C)
|
|
|
|
.Case("cl", IK_OpenCL)
|
2010-12-01 11:15:20 +08:00
|
|
|
.Case("cuda", IK_CUDA)
|
2010-06-08 07:22:09 +08:00
|
|
|
.Case("c++", IK_CXX)
|
|
|
|
.Case("objective-c", IK_ObjC)
|
|
|
|
.Case("objective-c++", IK_ObjCXX)
|
|
|
|
.Case("cpp-output", IK_PreprocessedC)
|
|
|
|
.Case("assembler-with-cpp", IK_Asm)
|
|
|
|
.Case("c++-cpp-output", IK_PreprocessedCXX)
|
|
|
|
.Case("objective-c-cpp-output", IK_PreprocessedObjC)
|
2011-04-09 15:09:31 +08:00
|
|
|
.Case("objc-cpp-output", IK_PreprocessedObjC)
|
2010-06-08 07:22:09 +08:00
|
|
|
.Case("objective-c++-cpp-output", IK_PreprocessedObjCXX)
|
2011-08-14 03:03:50 +08:00
|
|
|
.Case("objc++-cpp-output", IK_PreprocessedObjCXX)
|
2010-06-08 07:22:09 +08:00
|
|
|
.Case("c-header", IK_C)
|
2011-10-10 06:03:19 +08:00
|
|
|
.Case("cl-header", IK_OpenCL)
|
2010-06-08 07:22:09 +08:00
|
|
|
.Case("objective-c-header", IK_ObjC)
|
|
|
|
.Case("c++-header", IK_CXX)
|
|
|
|
.Case("objective-c++-header", IK_ObjCXX)
|
|
|
|
.Case("ast", IK_AST)
|
2010-06-08 07:26:47 +08:00
|
|
|
.Case("ir", IK_LLVM_IR)
|
2010-06-08 07:22:09 +08:00
|
|
|
.Default(IK_None);
|
|
|
|
if (DashX == IK_None)
|
2009-12-01 11:16:53 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< A->getAsString(Args) << A->getValue(Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// '-' is the default input if none is given.
|
2010-05-21 00:54:55 +08:00
|
|
|
std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.Inputs.clear();
|
|
|
|
if (Inputs.empty())
|
|
|
|
Inputs.push_back("-");
|
|
|
|
for (unsigned i = 0, e = Inputs.size(); i != e; ++i) {
|
2010-06-08 07:22:09 +08:00
|
|
|
InputKind IK = DashX;
|
|
|
|
if (IK == IK_None) {
|
2009-12-01 11:16:53 +08:00
|
|
|
IK = FrontendOptions::getInputKindForExtension(
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef(Inputs[i]).rsplit('.').second);
|
2009-12-01 11:16:53 +08:00
|
|
|
// FIXME: Remove this hack.
|
|
|
|
if (i == 0)
|
|
|
|
DashX = IK;
|
|
|
|
}
|
2012-01-21 00:28:04 +08:00
|
|
|
Opts.Inputs.push_back(FrontendInputFile(Inputs[i], IK));
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return DashX;
|
|
|
|
}
|
|
|
|
|
2009-12-15 08:06:45 +08:00
|
|
|
std::string CompilerInvocation::GetResourcesPath(const char *Argv0,
|
|
|
|
void *MainAddr) {
|
2009-12-01 11:16:53 +08:00
|
|
|
llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr);
|
|
|
|
|
|
|
|
if (!P.isEmpty()) {
|
|
|
|
P.eraseComponent(); // Remove /clang from foo/bin/clang
|
|
|
|
P.eraseComponent(); // Remove /bin from foo/bin
|
|
|
|
|
|
|
|
// Get foo/lib/clang/<version>/include
|
|
|
|
P.appendComponent("lib");
|
|
|
|
P.appendComponent("clang");
|
|
|
|
P.appendComponent(CLANG_VERSION_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
return P.str();
|
|
|
|
}
|
|
|
|
|
2009-12-13 11:45:58 +08:00
|
|
|
static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/");
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.Verbose = Args.hasArg(OPT_v);
|
2011-10-11 04:34:10 +08:00
|
|
|
Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
|
2011-10-12 02:20:10 +08:00
|
|
|
Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc);
|
2010-03-25 04:13:48 +08:00
|
|
|
Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx);
|
2011-06-22 05:12:29 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
|
|
|
|
Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir);
|
2011-09-13 04:41:59 +08:00
|
|
|
Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodule_cache_path);
|
2011-09-14 07:15:45 +08:00
|
|
|
Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash);
|
2011-09-13 04:41:59 +08:00
|
|
|
|
2011-07-28 12:45:53 +08:00
|
|
|
// Add -I..., -F..., and -index-header-map options in order.
|
|
|
|
bool IsIndexHeaderMap = false;
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F,
|
|
|
|
OPT_index_header_map),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
if ((*it)->getOption().matches(OPT_index_header_map)) {
|
|
|
|
// -index-header-map applies to the next -I or -F.
|
|
|
|
IsIndexHeaderMap = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
frontend::IncludeDirGroup Group
|
|
|
|
= IsIndexHeaderMap? frontend::IndexHeaderMap : frontend::Angled;
|
|
|
|
|
|
|
|
Opts.AddPath((*it)->getValue(Args), Group, true,
|
2011-06-22 05:53:08 +08:00
|
|
|
/*IsFramework=*/ (*it)->getOption().matches(OPT_F), false);
|
2011-07-28 12:45:53 +08:00
|
|
|
IsIndexHeaderMap = false;
|
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
// Add -iprefix/-iwith-prefix/-iwithprefixbefore options.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Prefix = ""; // FIXME: This isn't the correct default prefix.
|
2009-12-01 11:16:53 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_iprefix, OPT_iwithprefix,
|
|
|
|
OPT_iwithprefixbefore),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
const Arg *A = *it;
|
|
|
|
if (A->getOption().matches(OPT_iprefix))
|
|
|
|
Prefix = A->getValue(Args);
|
|
|
|
else if (A->getOption().matches(OPT_iwithprefix))
|
|
|
|
Opts.AddPath(Prefix.str() + A->getValue(Args),
|
2011-06-22 05:53:08 +08:00
|
|
|
frontend::System, false, false, false);
|
2009-12-01 11:16:53 +08:00
|
|
|
else
|
2010-06-12 06:00:13 +08:00
|
|
|
Opts.AddPath(Prefix.str() + A->getValue(Args),
|
2011-06-22 05:53:08 +08:00
|
|
|
frontend::Angled, false, false, false);
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_idirafter),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it)
|
2011-06-22 05:53:08 +08:00
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::After, true, false, false);
|
2009-12-01 11:16:53 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_iquote),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it)
|
2011-06-22 05:53:08 +08:00
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::Quoted, true, false, false);
|
2011-09-23 05:41:16 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_isystem,
|
2011-02-22 08:40:56 +08:00
|
|
|
OPT_iwithsysroot), ie = Args.filtered_end(); it != ie; ++it)
|
2011-09-23 05:41:16 +08:00
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::System, true, false,
|
|
|
|
!(*it)->getOption().matches(OPT_iwithsysroot));
|
2011-10-19 04:40:38 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_iframework),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it)
|
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::System, true, true,
|
|
|
|
true);
|
2011-09-23 05:41:16 +08:00
|
|
|
|
|
|
|
// Add the paths for the various language specific isystem flags.
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_c_isystem),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it)
|
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::CSystem, true, false, true);
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it)
|
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::CXXSystem, true, false, true);
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_objc_isystem),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it)
|
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::ObjCSystem, true, false,true);
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_objcxx_isystem),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it)
|
|
|
|
Opts.AddPath((*it)->getValue(Args), frontend::ObjCXXSystem, true, false,
|
|
|
|
true);
|
2011-11-05 16:30:29 +08:00
|
|
|
|
|
|
|
// Add the internal paths from a driver that detects standard include paths.
|
|
|
|
for (arg_iterator I = Args.filtered_begin(OPT_internal_isystem,
|
2011-11-07 17:17:31 +08:00
|
|
|
OPT_internal_externc_isystem),
|
2011-11-05 16:30:29 +08:00
|
|
|
E = Args.filtered_end();
|
|
|
|
I != E; ++I)
|
|
|
|
Opts.AddPath((*I)->getValue(Args), frontend::System,
|
2011-11-07 17:17:31 +08:00
|
|
|
false, false, /*IgnoreSysRoot=*/true, /*IsInternal=*/true,
|
2011-11-05 16:30:29 +08:00
|
|
|
(*I)->getOption().matches(OPT_internal_externc_isystem));
|
2012-06-14 04:27:03 +08:00
|
|
|
|
|
|
|
// Add the path prefixes which are implicitly treated as being system headers.
|
|
|
|
for (arg_iterator I = Args.filtered_begin(OPT_isystem_prefix,
|
|
|
|
OPT_ino_system_prefix),
|
|
|
|
E = Args.filtered_end();
|
|
|
|
I != E; ++I)
|
|
|
|
Opts.AddSystemHeaderPrefix((*I)->getValue(Args),
|
|
|
|
(*I)->getOption().matches(OPT_isystem_prefix));
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-04 09:50:27 +08:00
|
|
|
void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
|
|
|
|
LangStandard::Kind LangStd) {
|
2011-04-15 13:22:18 +08:00
|
|
|
// Set some properties which depend solely on the input kind; it would be nice
|
2009-12-01 11:16:53 +08:00
|
|
|
// to move these to the language standard, and have the driver resolve the
|
|
|
|
// input kind + language standard.
|
2010-06-08 07:22:09 +08:00
|
|
|
if (IK == IK_Asm) {
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.AsmPreprocessor = 1;
|
2010-06-08 07:22:09 +08:00
|
|
|
} else if (IK == IK_ObjC ||
|
|
|
|
IK == IK_ObjCXX ||
|
|
|
|
IK == IK_PreprocessedObjC ||
|
|
|
|
IK == IK_PreprocessedObjCXX) {
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ObjC1 = Opts.ObjC2 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LangStd == LangStandard::lang_unspecified) {
|
|
|
|
// Based on the base language, pick one.
|
|
|
|
switch (IK) {
|
2010-06-08 07:22:09 +08:00
|
|
|
case IK_None:
|
|
|
|
case IK_AST:
|
2010-06-08 07:26:47 +08:00
|
|
|
case IK_LLVM_IR:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Invalid input kind!");
|
2010-06-08 07:22:09 +08:00
|
|
|
case IK_OpenCL:
|
2009-12-01 11:16:53 +08:00
|
|
|
LangStd = LangStandard::lang_opencl;
|
|
|
|
break;
|
2010-12-01 11:15:20 +08:00
|
|
|
case IK_CUDA:
|
|
|
|
LangStd = LangStandard::lang_cuda;
|
|
|
|
break;
|
2010-06-08 07:22:09 +08:00
|
|
|
case IK_Asm:
|
|
|
|
case IK_C:
|
|
|
|
case IK_PreprocessedC:
|
|
|
|
case IK_ObjC:
|
|
|
|
case IK_PreprocessedObjC:
|
2009-12-01 11:16:53 +08:00
|
|
|
LangStd = LangStandard::lang_gnu99;
|
|
|
|
break;
|
2010-06-08 07:22:09 +08:00
|
|
|
case IK_CXX:
|
|
|
|
case IK_PreprocessedCXX:
|
|
|
|
case IK_ObjCXX:
|
|
|
|
case IK_PreprocessedObjCXX:
|
2009-12-01 11:16:53 +08:00
|
|
|
LangStd = LangStandard::lang_gnucxx98;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
|
|
|
|
Opts.BCPLComment = Std.hasBCPLComments();
|
|
|
|
Opts.C99 = Std.isC99();
|
2011-12-24 01:00:35 +08:00
|
|
|
Opts.C11 = Std.isC11();
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.CPlusPlus = Std.isCPlusPlus();
|
|
|
|
Opts.CPlusPlus0x = Std.isCPlusPlus0x();
|
|
|
|
Opts.Digraphs = Std.hasDigraphs();
|
|
|
|
Opts.GNUMode = Std.isGNUMode();
|
|
|
|
Opts.GNUInline = !Std.isC99();
|
|
|
|
Opts.HexFloats = Std.hasHexFloats();
|
|
|
|
Opts.ImplicitInt = Std.hasImplicitInt();
|
|
|
|
|
2012-06-19 06:55:02 +08:00
|
|
|
// Set OpenCL Version.
|
2009-12-01 11:16:53 +08:00
|
|
|
if (LangStd == LangStandard::lang_opencl) {
|
|
|
|
Opts.OpenCL = 1;
|
2012-06-19 06:55:02 +08:00
|
|
|
Opts.OpenCLVersion = 100;
|
|
|
|
}
|
|
|
|
else if (LangStd == LangStandard::lang_opencl11) {
|
|
|
|
Opts.OpenCL = 1;
|
|
|
|
Opts.OpenCLVersion = 110;
|
|
|
|
}
|
|
|
|
else if (LangStd == LangStandard::lang_opencl12) {
|
|
|
|
Opts.OpenCL = 1;
|
|
|
|
Opts.OpenCLVersion = 120;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenCL has some additional defaults.
|
|
|
|
if (Opts.OpenCL) {
|
2011-09-22 02:28:29 +08:00
|
|
|
Opts.AltiVec = 0;
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.CXXOperatorNames = 1;
|
2011-09-22 02:28:29 +08:00
|
|
|
Opts.LaxVectorConversions = 0;
|
2011-02-14 09:42:53 +08:00
|
|
|
Opts.DefaultFPContract = 1;
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 11:15:20 +08:00
|
|
|
if (LangStd == LangStandard::lang_cuda)
|
|
|
|
Opts.CUDA = 1;
|
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
// OpenCL and C++ both have bool, true, false keywords.
|
|
|
|
Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
|
|
|
|
|
2010-12-04 09:50:27 +08:00
|
|
|
Opts.GNUKeywords = Opts.GNUMode;
|
|
|
|
Opts.CXXOperatorNames = Opts.CPlusPlus;
|
|
|
|
|
|
|
|
// Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
|
|
|
|
// is specified, or -std is set to a conforming mode.
|
|
|
|
Opts.Trigraphs = !Opts.GNUMode;
|
|
|
|
|
|
|
|
Opts.DollarIdents = !Opts.AsmPreprocessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2010-12-04 09:50:27 +08:00
|
|
|
// FIXME: Cleanup per-file based stuff.
|
|
|
|
LangStandard::Kind LangStd = LangStandard::lang_unspecified;
|
|
|
|
if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {
|
|
|
|
LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue(Args))
|
|
|
|
#define LANGSTANDARD(id, name, desc, features) \
|
|
|
|
.Case(name, LangStandard::lang_##id)
|
|
|
|
#include "clang/Frontend/LangStandards.def"
|
|
|
|
.Default(LangStandard::lang_unspecified);
|
|
|
|
if (LangStd == LangStandard::lang_unspecified)
|
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< A->getAsString(Args) << A->getValue(Args);
|
2011-05-03 03:24:53 +08:00
|
|
|
else {
|
|
|
|
// Valid standard, check to make sure language and standard are compatable.
|
|
|
|
const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
|
|
|
|
switch (IK) {
|
|
|
|
case IK_C:
|
|
|
|
case IK_ObjC:
|
|
|
|
case IK_PreprocessedC:
|
|
|
|
case IK_PreprocessedObjC:
|
|
|
|
if (!(Std.isC89() || Std.isC99()))
|
|
|
|
Diags.Report(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "C/ObjC";
|
|
|
|
break;
|
|
|
|
case IK_CXX:
|
|
|
|
case IK_ObjCXX:
|
|
|
|
case IK_PreprocessedCXX:
|
|
|
|
case IK_PreprocessedObjCXX:
|
|
|
|
if (!Std.isCPlusPlus())
|
|
|
|
Diags.Report(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "C++/ObjC++";
|
|
|
|
break;
|
|
|
|
case IK_OpenCL:
|
|
|
|
if (!Std.isC99())
|
|
|
|
Diags.Report(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "OpenCL";
|
|
|
|
break;
|
|
|
|
case IK_CUDA:
|
|
|
|
if (!Std.isCPlusPlus())
|
|
|
|
Diags.Report(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "CUDA";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-04 09:50:27 +08:00
|
|
|
}
|
|
|
|
|
2012-06-20 07:09:52 +08:00
|
|
|
// -cl-std only applies for OpenCL language standards.
|
|
|
|
// Override the -std option in this case.
|
2010-12-04 09:51:40 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) {
|
2012-06-20 07:09:52 +08:00
|
|
|
LangStandard::Kind OpenCLLangStd
|
|
|
|
= llvm::StringSwitch<LangStandard::Kind>(A->getValue(Args))
|
|
|
|
.Case("CL", LangStandard::lang_opencl)
|
|
|
|
.Case("CL1.1", LangStandard::lang_opencl11)
|
|
|
|
.Case("CL1.2", LangStandard::lang_opencl12)
|
|
|
|
.Default(LangStandard::lang_unspecified);
|
|
|
|
|
|
|
|
if (OpenCLLangStd == LangStandard::lang_unspecified) {
|
2010-12-04 09:51:40 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
2012-06-20 07:09:52 +08:00
|
|
|
<< A->getAsString(Args) << A->getValue(Args);
|
2010-12-04 09:51:40 +08:00
|
|
|
}
|
2012-06-20 07:09:52 +08:00
|
|
|
else
|
|
|
|
LangStd = OpenCLLangStd;
|
2010-12-04 09:51:40 +08:00
|
|
|
}
|
2012-06-20 07:09:52 +08:00
|
|
|
|
2010-12-04 09:50:27 +08:00
|
|
|
CompilerInvocation::setLangDefaults(Opts, IK, LangStd);
|
|
|
|
|
2010-04-18 04:17:31 +08:00
|
|
|
// We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
|
|
|
|
// keywords. This behavior is provided by GCC's poorly named '-fasm' flag,
|
|
|
|
// while a subset (the non-C++ GNU keywords) is provided by GCC's
|
|
|
|
// '-fgnu-keywords'. Clang conflates the two for simplicity under the single
|
|
|
|
// name, as it doesn't seem a useful distinction.
|
|
|
|
Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
|
2010-12-04 09:50:27 +08:00
|
|
|
Opts.GNUKeywords);
|
2010-04-18 04:17:31 +08:00
|
|
|
|
2010-12-04 09:50:27 +08:00
|
|
|
if (Args.hasArg(OPT_fno_operator_names))
|
|
|
|
Opts.CXXOperatorNames = 0;
|
2009-12-01 11:16:53 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
if (Opts.ObjC1) {
|
2012-06-20 14:18:46 +08:00
|
|
|
if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
|
|
|
|
StringRef value = arg->getValue(Args);
|
|
|
|
if (Opts.ObjCRuntime.tryParse(value))
|
|
|
|
Diags.Report(diag::err_drv_unknown_objc_runtime) << value;
|
|
|
|
}
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
if (Args.hasArg(OPT_fobjc_gc_only))
|
2011-09-14 01:21:33 +08:00
|
|
|
Opts.setGC(LangOptions::GCOnly);
|
2011-06-16 07:02:42 +08:00
|
|
|
else if (Args.hasArg(OPT_fobjc_gc))
|
2011-09-14 01:21:33 +08:00
|
|
|
Opts.setGC(LangOptions::HybridGC);
|
2011-06-16 07:02:42 +08:00
|
|
|
else if (Args.hasArg(OPT_fobjc_arc)) {
|
|
|
|
Opts.ObjCAutoRefCount = 1;
|
2012-08-21 10:47:43 +08:00
|
|
|
if (!Opts.ObjCRuntime.allowsARC())
|
|
|
|
Diags.Report(diag::err_arc_unsupported_on_runtime);
|
|
|
|
|
|
|
|
// Only set ObjCARCWeak if ARC is enabled.
|
|
|
|
if (Args.hasArg(OPT_fobjc_runtime_has_weak))
|
|
|
|
Opts.ObjCARCWeak = 1;
|
|
|
|
else
|
|
|
|
Opts.ObjCARCWeak = Opts.ObjCRuntime.allowsWeak();
|
2011-06-16 07:02:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(OPT_fno_objc_infer_related_result_type))
|
|
|
|
Opts.ObjCInferRelatedResultType = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-03 00:13:27 +08:00
|
|
|
if (Args.hasArg(OPT_fgnu89_inline))
|
|
|
|
Opts.GNUInline = 1;
|
|
|
|
|
2011-02-04 08:01:24 +08:00
|
|
|
if (Args.hasArg(OPT_fapple_kext)) {
|
|
|
|
if (!Opts.CPlusPlus)
|
|
|
|
Diags.Report(diag::warn_c_kext);
|
|
|
|
else
|
|
|
|
Opts.AppleKext = 1;
|
|
|
|
}
|
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
if (Args.hasArg(OPT_print_ivar_layout))
|
|
|
|
Opts.ObjCGCBitmapPrint = 1;
|
2010-04-23 04:26:39 +08:00
|
|
|
if (Args.hasArg(OPT_fno_constant_cfstrings))
|
|
|
|
Opts.NoConstantCFStrings = 1;
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
if (Args.hasArg(OPT_faltivec))
|
|
|
|
Opts.AltiVec = 1;
|
|
|
|
|
|
|
|
if (Args.hasArg(OPT_pthread))
|
|
|
|
Opts.POSIXThreads = 1;
|
|
|
|
|
2011-04-23 06:18:13 +08:00
|
|
|
if (Args.hasArg(OPT_fdelayed_template_parsing))
|
|
|
|
Opts.DelayedTemplateParsing = 1;
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Vis = Args.getLastArgValue(OPT_fvisibility, "default");
|
2009-12-01 11:16:53 +08:00
|
|
|
if (Vis == "default")
|
2010-10-23 05:05:15 +08:00
|
|
|
Opts.setVisibilityMode(DefaultVisibility);
|
2009-12-01 11:16:53 +08:00
|
|
|
else if (Vis == "hidden")
|
2010-10-23 05:05:15 +08:00
|
|
|
Opts.setVisibilityMode(HiddenVisibility);
|
2009-12-01 11:16:53 +08:00
|
|
|
else if (Vis == "protected")
|
2012-01-29 09:20:30 +08:00
|
|
|
// FIXME: diagnose if target does not support protected visibility
|
2010-10-23 05:05:15 +08:00
|
|
|
Opts.setVisibilityMode(ProtectedVisibility);
|
2009-12-01 11:16:53 +08:00
|
|
|
else
|
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis;
|
|
|
|
|
2012-07-06 08:59:19 +08:00
|
|
|
if (Arg *A = Args.getLastArg(OPT_ffp_contract)) {
|
|
|
|
StringRef Val = A->getValue(Args);
|
|
|
|
if (Val == "fast")
|
|
|
|
Opts.setFPContractMode(LangOptions::FPC_Fast);
|
|
|
|
else if (Val == "on")
|
|
|
|
Opts.setFPContractMode(LangOptions::FPC_On);
|
|
|
|
else if (Val == "off")
|
|
|
|
Opts.setFPContractMode(LangOptions::FPC_Off);
|
|
|
|
else
|
|
|
|
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
|
|
|
|
}
|
|
|
|
|
2010-06-16 01:05:35 +08:00
|
|
|
if (Args.hasArg(OPT_fvisibility_inlines_hidden))
|
|
|
|
Opts.InlineVisibilityHidden = 1;
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2010-09-18 02:29:54 +08:00
|
|
|
if (Args.hasArg(OPT_ftrapv)) {
|
2010-10-21 11:16:25 +08:00
|
|
|
Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping);
|
2010-09-18 02:29:54 +08:00
|
|
|
// Set the handler, if one is specified.
|
|
|
|
Opts.OverflowHandler =
|
|
|
|
Args.getLastArgValue(OPT_ftrapv_handler);
|
|
|
|
}
|
2010-06-27 05:25:03 +08:00
|
|
|
else if (Args.hasArg(OPT_fwrapv))
|
2010-10-21 11:16:25 +08:00
|
|
|
Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined);
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
if (Args.hasArg(OPT_trigraphs))
|
|
|
|
Opts.Trigraphs = 1;
|
|
|
|
|
2009-12-17 04:10:18 +08:00
|
|
|
Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
|
|
|
|
OPT_fno_dollars_in_identifiers,
|
2010-12-04 09:50:27 +08:00
|
|
|
Opts.DollarIdents);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings);
|
2011-10-24 23:27:23 +08:00
|
|
|
Opts.MicrosoftExt
|
|
|
|
= Args.hasArg(OPT_fms_extensions) || Args.hasArg(OPT_fms_compatibility);
|
2011-09-17 12:32:15 +08:00
|
|
|
Opts.MicrosoftMode = Args.hasArg(OPT_fms_compatibility);
|
2010-10-21 13:21:48 +08:00
|
|
|
Opts.MSCVersion = Args.getLastArgIntValue(OPT_fmsc_version, 0, Diags);
|
2010-09-03 07:59:25 +08:00
|
|
|
Opts.Borland = Args.hasArg(OPT_fborland_extensions);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
|
2011-04-23 14:30:43 +08:00
|
|
|
Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings,
|
|
|
|
Opts.ConstStrings);
|
2009-12-01 11:16:53 +08:00
|
|
|
if (Args.hasArg(OPT_fno_lax_vector_conversions))
|
2010-02-07 07:23:06 +08:00
|
|
|
Opts.LaxVectorConversions = 0;
|
|
|
|
if (Args.hasArg(OPT_fno_threadsafe_statics))
|
2010-02-11 16:02:13 +08:00
|
|
|
Opts.ThreadsafeStatics = 0;
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.Exceptions = Args.hasArg(OPT_fexceptions);
|
2011-02-22 09:52:06 +08:00
|
|
|
Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
|
2011-02-23 11:16:42 +08:00
|
|
|
Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
|
|
|
|
Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
|
2011-03-19 05:23:38 +08:00
|
|
|
Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
|
2011-02-23 11:16:42 +08:00
|
|
|
|
2009-12-03 02:57:08 +08:00
|
|
|
Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.Blocks = Args.hasArg(OPT_fblocks);
|
2011-09-10 04:41:01 +08:00
|
|
|
Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
|
2012-01-04 01:07:34 +08:00
|
|
|
Opts.Modules = Args.hasArg(OPT_fmodules);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char);
|
|
|
|
Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar);
|
2010-10-08 08:25:19 +08:00
|
|
|
Opts.ShortEnums = Args.hasArg(OPT_fshort_enums);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.Freestanding = Args.hasArg(OPT_ffreestanding);
|
|
|
|
Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
|
2009-12-17 00:59:22 +08:00
|
|
|
Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
|
2010-04-10 03:03:51 +08:00
|
|
|
Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);
|
2010-01-08 10:20:44 +08:00
|
|
|
Opts.MathErrno = Args.hasArg(OPT_fmath_errno);
|
2012-07-03 03:56:23 +08:00
|
|
|
Opts.InstantiationDepth = Args.getLastArgIntValue(OPT_ftemplate_depth, 512,
|
2011-11-22 03:36:32 +08:00
|
|
|
Diags);
|
|
|
|
Opts.ConstexprCallDepth = Args.getLastArgIntValue(OPT_fconstexpr_depth, 512,
|
|
|
|
Diags);
|
2011-04-23 06:18:13 +08:00
|
|
|
Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing);
|
2012-05-01 22:57:16 +08:00
|
|
|
Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy_EQ,
|
2010-11-18 07:11:54 +08:00
|
|
|
0, Diags);
|
2011-02-01 23:15:22 +08:00
|
|
|
Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.ObjCConstantStringClass =
|
|
|
|
Args.getLastArgValue(OPT_fconstant_string_class);
|
2010-12-24 05:35:43 +08:00
|
|
|
Opts.ObjCDefaultSynthProperties =
|
|
|
|
Args.hasArg(OPT_fobjc_default_synthesize_properties);
|
2012-05-23 01:19:45 +08:00
|
|
|
Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
|
2012-05-01 22:57:16 +08:00
|
|
|
Opts.PackStruct = Args.getLastArgIntValue(OPT_fpack_struct_EQ, 0, Diags);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags);
|
Teach Clang about PIE compilations. This is the first step of PR12380.
First, this patch cleans up the parsing of the PIC and PIE family of
options in the driver. The existing logic failed to claim arguments all
over the place resulting in kludges that marked the options as unused.
Instead actually walk all of the arguments and claim them properly.
We now treat -f{,no-}{pic,PIC,pie,PIE} as a single set, accepting the
last one on the commandline. Previously there were lots of ordering bugs
that could creep in due to the nature of the parsing. Let me know if
folks would like weird things such as "-fPIE -fno-pic" to turn on PIE,
but disable full PIC. This doesn't make any sense to me, but we could in
theory support it.
Options that seem to have intentional "trump" status (-static, -mkernel,
etc) continue to do so and are commented as such.
Next, a -pie-level flag is threaded into the frontend, rigged to
a language option, and handled preprocessor, setting up the appropriate
defines. We'll now have the correct defines when compiling with -fpie.
The one place outside of the preprocessor that was inspecting the PIC
level (as opposed to the relocation model, which is set and handled
separately, yay!) is in the GNU ObjC runtime. I changed it to exactly
preserve existing behavior. If folks want to change its behavior in the
face of PIE, they can do that in a separate patch.
Essentially the only functionality changed here is the preprocessor
defines and bug-fixes to the argument management.
Tests have been updated and extended to test all of this a bit more
thoroughly.
llvm-svn: 154291
2012-04-09 00:40:35 +08:00
|
|
|
Opts.PIELevel = Args.getLastArgIntValue(OPT_pie_level, 0, Diags);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.Static = Args.hasArg(OPT_static_define);
|
Extend the ExternalASTSource interface to allow the AST source to
provide the layout of records, rather than letting Clang compute
the layout itself. LLDB provides the motivation for this feature:
because various layout-altering attributes (packed, aligned, etc.)
don't get reliably get placed into DWARF, the record layouts computed
by LLDB from the reconstructed records differ from the actual layouts,
and badness occurs. This interface lets the DWARF data drive layout,
so we don't need the attributes preserved to get the answer write.
The testing methodology for this change is fun. I've introduced a
variant of -fdump-record-layouts called -fdump-record-layouts-simple
that always has the simple C format and provides size/alignment/field
offsets. There is also a -cc1 option -foverride-record-layout=<file>
to take the output of -fdump-record-layouts-simple and parse it to
produce a set of overridden layouts, which is introduced into the AST
via a testing-only ExternalASTSource (called
LayoutOverrideSource). Each test contains a number of records to lay
out, which use various layout-changing attributes, and then dumps the
layouts. We then run the test again, using the preprocessor to
eliminate the layout-changing attributes entirely (which would give us
different layouts for the records), but supplying the
previously-computed record layouts. Finally, we diff the layouts
produced from the two runs to be sure that they are identical.
Note that this code makes the assumption that we don't *have* to
provide the offsets of bases or virtual bases to get the layout right,
because the alignment attributes don't affect it. I believe this
assumption holds, but if it does not, we can extend
LayoutOverrideSource to also provide base offset information.
Fixes the Clang side of <rdar://problem/10169539>.
llvm-svn: 149055
2012-01-26 15:55:45 +08:00
|
|
|
Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple);
|
|
|
|
Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple
|
|
|
|
|| Args.hasArg(OPT_fdump_record_layouts);
|
2010-04-18 04:15:18 +08:00
|
|
|
Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
|
2010-07-10 01:35:33 +08:00
|
|
|
Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking);
|
2010-04-15 23:06:22 +08:00
|
|
|
Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
|
2010-12-04 09:50:56 +08:00
|
|
|
Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
|
2010-12-04 09:51:23 +08:00
|
|
|
Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
|
2011-03-02 01:40:53 +08:00
|
|
|
Opts.MRTD = Args.hasArg(OPT_mrtd);
|
2011-12-13 05:14:55 +08:00
|
|
|
Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
|
2011-03-19 06:38:29 +08:00
|
|
|
Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
|
2011-04-10 06:50:59 +08:00
|
|
|
Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
|
2011-07-14 01:56:40 +08:00
|
|
|
Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support);
|
2012-02-04 09:29:37 +08:00
|
|
|
Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id);
|
2012-03-07 04:06:33 +08:00
|
|
|
Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal);
|
2011-11-22 09:28:36 +08:00
|
|
|
Opts.AddressSanitizer = Args.hasArg(OPT_faddress_sanitizer);
|
2012-03-02 06:27:08 +08:00
|
|
|
Opts.ThreadSanitizer = Args.hasArg(OPT_fthread_sanitizer);
|
2011-11-02 09:53:16 +08:00
|
|
|
Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack);
|
2011-11-16 03:35:01 +08:00
|
|
|
Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name);
|
2009-12-01 11:16:53 +08:00
|
|
|
|
2011-04-23 17:27:53 +08:00
|
|
|
// Record whether the __DEPRECATED define was requested.
|
|
|
|
Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro,
|
|
|
|
OPT_fno_deprecated_macro,
|
|
|
|
Opts.Deprecated);
|
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
// FIXME: Eliminate this dependency.
|
2012-08-09 00:09:15 +08:00
|
|
|
unsigned Opt = getOptimizationLevel(Args, IK, Diags),
|
|
|
|
OptSize = getOptimizationLevelSize(Args, IK, Diags);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.Optimize = Opt != 0;
|
2012-08-09 00:09:15 +08:00
|
|
|
Opts.OptimizeSize = OptSize != 0;
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
// This is the __NO_INLINE__ define, which just depends on things like the
|
|
|
|
// optimization level and -fno-inline, not actually whether the backend has
|
|
|
|
// inlining enabled.
|
2012-03-16 06:31:42 +08:00
|
|
|
Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline);
|
2009-12-01 11:16:53 +08:00
|
|
|
|
2012-01-02 22:19:45 +08:00
|
|
|
Opts.FastMath = Args.hasArg(OPT_ffast_math);
|
2012-07-19 11:52:53 +08:00
|
|
|
Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only);
|
2012-01-02 22:19:45 +08:00
|
|
|
|
2012-08-25 05:42:51 +08:00
|
|
|
Opts.EmitMicrosoftInlineAsm = Args.hasArg(OPT_fenable_experimental_ms_inline_asm);
|
|
|
|
|
2010-05-21 00:54:55 +08:00
|
|
|
unsigned SSP = Args.getLastArgIntValue(OPT_stack_protector, 0, Diags);
|
2009-12-01 11:16:53 +08:00
|
|
|
switch (SSP) {
|
|
|
|
default:
|
|
|
|
Diags.Report(diag::err_drv_invalid_value)
|
|
|
|
<< Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP;
|
|
|
|
break;
|
2011-09-14 01:21:33 +08:00
|
|
|
case 0: Opts.setStackProtector(LangOptions::SSPOff); break;
|
|
|
|
case 1: Opts.setStackProtector(LangOptions::SSPOn); break;
|
|
|
|
case 2: Opts.setStackProtector(LangOptions::SSPReq); break;
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-03 13:11:16 +08:00
|
|
|
static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
|
2010-11-04 06:45:23 +08:00
|
|
|
FileManager &FileMgr,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch);
|
|
|
|
Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth);
|
2009-12-01 11:16:53 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(OPT_token_cache))
|
|
|
|
Opts.TokenCache = A->getValue(Args);
|
|
|
|
else
|
|
|
|
Opts.TokenCache = Opts.ImplicitPTHInclude;
|
|
|
|
Opts.UsePredefines = !Args.hasArg(OPT_undef);
|
2010-03-20 00:15:56 +08:00
|
|
|
Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record);
|
2010-07-27 08:27:13 +08:00
|
|
|
Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch);
|
2010-10-15 04:14:25 +08:00
|
|
|
|
2010-10-15 04:14:18 +08:00
|
|
|
Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls);
|
2010-10-15 04:14:25 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_error_on_deserialized_pch_decl),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
const Arg *A = *it;
|
|
|
|
Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue(Args));
|
|
|
|
}
|
2010-07-27 08:27:13 +08:00
|
|
|
|
Introduce basic support for loading a precompiled preamble while
reparsing an ASTUnit. When saving a preamble, create a buffer larger
than the actual file we're working with but fill everything from the
end of the preamble to the end of the file with spaces (so the lexer
will quickly skip them). When we load the file, create a buffer of the
same size, filling it with the file and then spaces. Then, instruct
the lexer to start lexing after the preamble, therefore continuing the
parse from the spot where the preamble left off.
It's now possible to perform a simple preamble build + parse (+
reparse) with ASTUnit. However, one has to disable a bunch of checking
in the PCH reader to do so. That part isn't committed; it will likely
be handled with some other kind of flag (e.g., -fno-validate-pch).
As part of this, fix some issues with null termination of the memory
buffers created for the preamble; we were trying to explicitly
NULL-terminate them, even though they were also getting implicitly
NULL terminated, leading to excess warnings about NULL characters in
source files.
llvm-svn: 109445
2010-07-27 05:36:20 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Value(A->getValue(Args));
|
Introduce basic support for loading a precompiled preamble while
reparsing an ASTUnit. When saving a preamble, create a buffer larger
than the actual file we're working with but fill everything from the
end of the preamble to the end of the file with spaces (so the lexer
will quickly skip them). When we load the file, create a buffer of the
same size, filling it with the file and then spaces. Then, instruct
the lexer to start lexing after the preamble, therefore continuing the
parse from the spot where the preamble left off.
It's now possible to perform a simple preamble build + parse (+
reparse) with ASTUnit. However, one has to disable a bunch of checking
in the PCH reader to do so. That part isn't committed; it will likely
be handled with some other kind of flag (e.g., -fno-validate-pch).
As part of this, fix some issues with null termination of the memory
buffers created for the preamble; we were trying to explicitly
NULL-terminate them, even though they were also getting implicitly
NULL terminated, leading to excess warnings about NULL characters in
source files.
llvm-svn: 109445
2010-07-27 05:36:20 +08:00
|
|
|
size_t Comma = Value.find(',');
|
|
|
|
unsigned Bytes = 0;
|
|
|
|
unsigned EndOfLine = 0;
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
if (Comma == StringRef::npos ||
|
Introduce basic support for loading a precompiled preamble while
reparsing an ASTUnit. When saving a preamble, create a buffer larger
than the actual file we're working with but fill everything from the
end of the preamble to the end of the file with spaces (so the lexer
will quickly skip them). When we load the file, create a buffer of the
same size, filling it with the file and then spaces. Then, instruct
the lexer to start lexing after the preamble, therefore continuing the
parse from the spot where the preamble left off.
It's now possible to perform a simple preamble build + parse (+
reparse) with ASTUnit. However, one has to disable a bunch of checking
in the PCH reader to do so. That part isn't committed; it will likely
be handled with some other kind of flag (e.g., -fno-validate-pch).
As part of this, fix some issues with null termination of the memory
buffers created for the preamble; we were trying to explicitly
NULL-terminate them, even though they were also getting implicitly
NULL terminated, leading to excess warnings about NULL characters in
source files.
llvm-svn: 109445
2010-07-27 05:36:20 +08:00
|
|
|
Value.substr(0, Comma).getAsInteger(10, Bytes) ||
|
|
|
|
Value.substr(Comma + 1).getAsInteger(10, EndOfLine))
|
|
|
|
Diags.Report(diag::err_drv_preamble_format);
|
|
|
|
else {
|
|
|
|
Opts.PrecompiledPreambleBytes.first = Bytes;
|
|
|
|
Opts.PrecompiledPreambleBytes.second = (EndOfLine != 0);
|
|
|
|
}
|
|
|
|
}
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
// Add macros from the command line.
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
if ((*it)->getOption().matches(OPT_D))
|
|
|
|
Opts.addMacroDef((*it)->getValue(Args));
|
2009-12-01 11:16:53 +08:00
|
|
|
else
|
2010-06-12 06:00:13 +08:00
|
|
|
Opts.addMacroUndef((*it)->getValue(Args));
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros);
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
// Add the ordered list of -includes.
|
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_include, OPT_include_pch,
|
|
|
|
OPT_include_pth),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
const Arg *A = *it;
|
2009-12-01 11:16:53 +08:00
|
|
|
// PCH is handled specially, we need to extra the original include path.
|
2010-06-12 06:00:13 +08:00
|
|
|
if (A->getOption().matches(OPT_include_pch)) {
|
2009-12-01 11:16:53 +08:00
|
|
|
std::string OriginalFile =
|
2010-11-23 16:35:12 +08:00
|
|
|
ASTReader::getOriginalSourceFile(A->getValue(Args), FileMgr, Diags);
|
2009-12-01 11:16:53 +08:00
|
|
|
if (OriginalFile.empty())
|
2009-12-03 17:13:06 +08:00
|
|
|
continue;
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
Opts.Includes.push_back(OriginalFile);
|
|
|
|
} else
|
2010-06-12 06:00:13 +08:00
|
|
|
Opts.Includes.push_back(A->getValue(Args));
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
2009-12-03 13:11:16 +08:00
|
|
|
|
2011-03-10 01:21:42 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_chain_include),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
const Arg *A = *it;
|
|
|
|
Opts.ChainedIncludes.push_back(A->getValue(Args));
|
|
|
|
}
|
|
|
|
|
2010-04-14 11:54:58 +08:00
|
|
|
// Include 'altivec.h' if -faltivec option present
|
|
|
|
if (Args.hasArg(OPT_faltivec))
|
|
|
|
Opts.Includes.push_back("altivec.h");
|
|
|
|
|
2009-12-03 13:11:16 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(OPT_remap_file),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
const Arg *A = *it;
|
2011-07-23 18:55:15 +08:00
|
|
|
std::pair<StringRef,StringRef> Split =
|
|
|
|
StringRef(A->getValue(Args)).split(';');
|
2009-12-03 13:11:16 +08:00
|
|
|
|
|
|
|
if (Split.second.empty()) {
|
2010-06-12 06:00:13 +08:00
|
|
|
Diags.Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args);
|
2009-12-03 13:11:16 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Opts.addRemappedFile(Split.first, Split.second);
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name = A->getValue(Args);
|
2011-06-16 07:02:42 +08:00
|
|
|
unsigned Library = llvm::StringSwitch<unsigned>(Name)
|
|
|
|
.Case("libc++", ARCXX_libcxx)
|
|
|
|
.Case("libstdc++", ARCXX_libstdcxx)
|
|
|
|
.Case("none", ARCXX_nolib)
|
|
|
|
.Default(~0U);
|
|
|
|
if (Library == ~0U)
|
|
|
|
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
|
|
|
|
else
|
|
|
|
Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library;
|
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
|
|
|
|
ArgList &Args) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ShowCPP = !Args.hasArg(OPT_dM);
|
|
|
|
Opts.ShowComments = Args.hasArg(OPT_C);
|
2010-08-25 06:44:13 +08:00
|
|
|
Opts.ShowLineMarkers = !Args.hasArg(OPT_P);
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts.ShowMacroComments = Args.hasArg(OPT_CC);
|
2010-08-25 06:44:13 +08:00
|
|
|
Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD);
|
2012-06-15 01:36:09 +08:00
|
|
|
Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes);
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
|
2012-05-01 22:57:16 +08:00
|
|
|
using namespace options;
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.ABI = Args.getLastArgValue(OPT_target_abi);
|
2010-06-11 09:06:47 +08:00
|
|
|
Opts.CXXABI = Args.getLastArgValue(OPT_cxx_abi);
|
2010-05-21 00:54:55 +08:00
|
|
|
Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
|
|
|
|
Opts.Features = Args.getAllArgValues(OPT_target_feature);
|
2010-08-12 07:07:42 +08:00
|
|
|
Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version);
|
2010-08-30 17:42:39 +08:00
|
|
|
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
|
2009-12-01 11:16:53 +08:00
|
|
|
|
2011-11-02 05:33:06 +08:00
|
|
|
// Use the default target triple if unspecified.
|
2009-12-01 11:16:53 +08:00
|
|
|
if (Opts.Triple.empty())
|
2011-11-02 05:33:06 +08:00
|
|
|
Opts.Triple = llvm::sys::getDefaultTargetTriple();
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2011-12-23 11:05:38 +08:00
|
|
|
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
|
2010-11-23 16:35:12 +08:00
|
|
|
const char *const *ArgBegin,
|
|
|
|
const char *const *ArgEnd,
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags) {
|
2011-12-23 11:05:38 +08:00
|
|
|
bool Success = true;
|
|
|
|
|
2009-12-01 11:16:53 +08:00
|
|
|
// Parse the arguments.
|
2012-05-01 22:57:16 +08:00
|
|
|
OwningPtr<OptTable> Opts(createDriverOptTable());
|
2009-12-01 11:16:53 +08:00
|
|
|
unsigned MissingArgIndex, MissingArgCount;
|
2012-02-05 10:12:40 +08:00
|
|
|
OwningPtr<InputArgList> Args(
|
2009-12-01 11:16:53 +08:00
|
|
|
Opts->ParseArgs(ArgBegin, ArgEnd,MissingArgIndex, MissingArgCount));
|
|
|
|
|
|
|
|
// Check for missing argument error.
|
2011-12-23 11:05:38 +08:00
|
|
|
if (MissingArgCount) {
|
2009-12-01 11:16:53 +08:00
|
|
|
Diags.Report(diag::err_drv_missing_argument)
|
|
|
|
<< Args->getArgString(MissingArgIndex) << MissingArgCount;
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
|
|
|
|
// Issue errors on unknown arguments.
|
|
|
|
for (arg_iterator it = Args->filtered_begin(OPT_UNKNOWN),
|
2011-12-23 11:05:38 +08:00
|
|
|
ie = Args->filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
Diags.Report(diag::err_drv_unknown_argument) << (*it)->getAsString(*Args);
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = false;
|
|
|
|
}
|
2009-12-01 11:16:53 +08:00
|
|
|
|
2012-05-01 22:57:16 +08:00
|
|
|
// Issue errors on arguments that are not valid for CC1.
|
|
|
|
for (ArgList::iterator I = Args->begin(), E = Args->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (!(*I)->getOption().isCC1Option()) {
|
|
|
|
Diags.Report(diag::err_drv_unknown_argument) << (*I)->getAsString(*Args);
|
|
|
|
Success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags) && Success;
|
2012-01-25 08:20:29 +08:00
|
|
|
Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success;
|
2009-12-01 11:16:53 +08:00
|
|
|
ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args);
|
2012-03-14 04:09:56 +08:00
|
|
|
Success = ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, &Diags)
|
2011-12-23 11:05:38 +08:00
|
|
|
&& Success;
|
2010-11-04 06:45:23 +08:00
|
|
|
ParseFileSystemArgs(Res.getFileSystemOpts(), *Args);
|
2010-12-04 09:50:36 +08:00
|
|
|
// FIXME: We shouldn't have to pass the DashX option around here
|
2010-06-08 07:22:09 +08:00
|
|
|
InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags);
|
2011-12-23 11:05:38 +08:00
|
|
|
Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags)
|
|
|
|
&& Success;
|
2009-12-13 11:45:58 +08:00
|
|
|
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
|
2011-02-26 01:24:55 +08:00
|
|
|
if (DashX != IK_AST && DashX != IK_LLVM_IR) {
|
2011-11-18 07:01:24 +08:00
|
|
|
ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags);
|
2011-02-26 01:24:55 +08:00
|
|
|
if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
|
2011-11-18 07:01:24 +08:00
|
|
|
Res.getLangOpts()->ObjCExceptions = 1;
|
2011-02-26 01:24:55 +08:00
|
|
|
}
|
2010-11-04 06:45:23 +08:00
|
|
|
// FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of
|
|
|
|
// PCH file and find the original header name. Remove the need to do that in
|
2010-11-23 16:35:12 +08:00
|
|
|
// ParsePreprocessorArgs and remove the FileManager
|
2010-11-04 06:45:23 +08:00
|
|
|
// parameters from the function and the "FileManager.h" #include.
|
2010-11-23 15:51:02 +08:00
|
|
|
FileManager FileMgr(Res.getFileSystemOpts());
|
2010-11-23 16:35:12 +08:00
|
|
|
ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags);
|
2009-12-01 11:16:53 +08:00
|
|
|
ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args);
|
|
|
|
ParseTargetArgs(Res.getTargetOpts(), *Args);
|
2011-12-23 11:05:38 +08:00
|
|
|
|
|
|
|
return Success;
|
2009-12-01 11:16:53 +08:00
|
|
|
}
|
2011-09-14 07:15:45 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ModuleSignature {
|
|
|
|
llvm::SmallVector<uint64_t, 16> Data;
|
|
|
|
unsigned CurBit;
|
|
|
|
uint64_t CurValue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ModuleSignature() : CurBit(0), CurValue(0) { }
|
|
|
|
|
|
|
|
void add(uint64_t Value, unsigned Bits);
|
|
|
|
void add(StringRef Value);
|
|
|
|
void flush();
|
|
|
|
|
|
|
|
llvm::APInt getAsInteger() const;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleSignature::add(uint64_t Value, unsigned int NumBits) {
|
|
|
|
CurValue |= Value << CurBit;
|
|
|
|
if (CurBit + NumBits < 64) {
|
|
|
|
CurBit += NumBits;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the current word.
|
|
|
|
Data.push_back(CurValue);
|
|
|
|
|
|
|
|
if (CurBit)
|
|
|
|
CurValue = Value >> (64-CurBit);
|
|
|
|
else
|
|
|
|
CurValue = 0;
|
|
|
|
CurBit = (CurBit+NumBits) & 63;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleSignature::flush() {
|
|
|
|
if (CurBit == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Data.push_back(CurValue);
|
|
|
|
CurBit = 0;
|
|
|
|
CurValue = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleSignature::add(StringRef Value) {
|
|
|
|
for (StringRef::iterator I = Value.begin(), IEnd = Value.end(); I != IEnd;++I)
|
|
|
|
add(*I, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::APInt ModuleSignature::getAsInteger() const {
|
|
|
|
return llvm::APInt(Data.size() * 64, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CompilerInvocation::getModuleHash() const {
|
|
|
|
ModuleSignature Signature;
|
|
|
|
|
|
|
|
// Start the signature with the compiler version.
|
2012-03-08 07:50:05 +08:00
|
|
|
// FIXME: The full version string can be quite long. Omit it from the
|
|
|
|
// module hash for now to avoid failures where the path name becomes too
|
|
|
|
// long. An MD5 or similar checksum would work well here.
|
|
|
|
// Signature.add(getClangFullRepositoryVersion());
|
2011-09-14 07:15:45 +08:00
|
|
|
|
|
|
|
// Extend the signature with the language options
|
|
|
|
#define LANGOPT(Name, Bits, Default, Description) \
|
2011-11-18 07:01:24 +08:00
|
|
|
Signature.add(LangOpts->Name, Bits);
|
2011-09-14 07:15:45 +08:00
|
|
|
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
|
2011-11-18 07:01:24 +08:00
|
|
|
Signature.add(static_cast<unsigned>(LangOpts->get##Name()), Bits);
|
2011-09-14 07:15:45 +08:00
|
|
|
#define BENIGN_LANGOPT(Name, Bits, Default, Description)
|
|
|
|
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
|
|
|
|
#include "clang/Basic/LangOptions.def"
|
|
|
|
|
|
|
|
// Extend the signature with the target triple
|
|
|
|
llvm::Triple T(TargetOpts.Triple);
|
|
|
|
Signature.add((unsigned)T.getArch(), 5);
|
|
|
|
Signature.add((unsigned)T.getVendor(), 4);
|
|
|
|
Signature.add((unsigned)T.getOS(), 5);
|
|
|
|
Signature.add((unsigned)T.getEnvironment(), 4);
|
|
|
|
|
2011-09-14 23:55:12 +08:00
|
|
|
// Extend the signature with preprocessor options.
|
|
|
|
Signature.add(getPreprocessorOpts().UsePredefines, 1);
|
|
|
|
Signature.add(getPreprocessorOpts().DetailedRecord, 1);
|
|
|
|
|
2011-10-17 22:55:37 +08:00
|
|
|
// Hash the preprocessor defines.
|
|
|
|
// FIXME: This is terrible. Use an MD5 sum of the preprocessor defines.
|
|
|
|
std::vector<StringRef> MacroDefs;
|
|
|
|
for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator
|
|
|
|
I = getPreprocessorOpts().Macros.begin(),
|
|
|
|
IEnd = getPreprocessorOpts().Macros.end();
|
|
|
|
I != IEnd; ++I) {
|
|
|
|
if (!I->second)
|
|
|
|
MacroDefs.push_back(I->first);
|
|
|
|
}
|
|
|
|
llvm::array_pod_sort(MacroDefs.begin(), MacroDefs.end());
|
|
|
|
|
|
|
|
unsigned PPHashResult = 0;
|
|
|
|
for (unsigned I = 0, N = MacroDefs.size(); I != N; ++I)
|
|
|
|
PPHashResult = llvm::HashString(MacroDefs[I], PPHashResult);
|
|
|
|
Signature.add(PPHashResult, 32);
|
|
|
|
|
2011-09-14 07:15:45 +08:00
|
|
|
// We've generated the signature. Treat it as one large APInt that we'll
|
2011-09-14 23:55:12 +08:00
|
|
|
// encode in base-36 and return.
|
2011-09-14 07:15:45 +08:00
|
|
|
Signature.flush();
|
2011-09-14 23:55:12 +08:00
|
|
|
return Signature.getAsInteger().toString(36, /*Signed=*/false);
|
2011-09-14 07:15:45 +08:00
|
|
|
}
|