Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 1 | //===--- CompilerInvocation.cpp -------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Frontend/CompilerInvocation.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 11 | #include "clang/Basic/Diagnostic.h" |
| 12 | #include "clang/Basic/Version.h" |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 13 | #include "clang/Basic/FileManager.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Arg.h" |
| 15 | #include "clang/Driver/ArgList.h" |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Options.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 17 | #include "clang/Driver/DriverDiagnostic.h" |
| 18 | #include "clang/Driver/OptTable.h" |
| 19 | #include "clang/Driver/Option.h" |
| 20 | #include "clang/Frontend/CompilerInvocation.h" |
| 21 | #include "clang/Frontend/LangStandard.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 22 | #include "clang/Serialization/ASTReader.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/OwningPtr.h" |
| 24 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringSwitch.h" |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Triple.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Host.h" |
| 30 | #include "llvm/Support/Path.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 31 | using namespace clang; |
| 32 | |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
| 34 | // Initialization. |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 37 | CompilerInvocationBase::CompilerInvocationBase() |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 38 | : LangOpts(new LangOptions()) {} |
| 39 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 40 | CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X) |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 41 | : RefCountedBase<CompilerInvocation>(), |
Benjamin Kramer | 85224ae | 2011-11-29 11:31:35 +0000 | [diff] [blame] | 42 | LangOpts(new LangOptions(*X.getLangOpts())) {} |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 43 | |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | // Utility functions. |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 48 | static const char *getAnalysisStoreName(AnalysisStores Kind) { |
| 49 | switch (Kind) { |
| 50 | default: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 51 | llvm_unreachable("Unknown analysis store!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 52 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \ |
| 53 | case NAME##Model: return CMDFLAG; |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 54 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | static const char *getAnalysisConstraintName(AnalysisConstraints Kind) { |
| 59 | switch (Kind) { |
| 60 | default: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 61 | llvm_unreachable("Unknown analysis constraints!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 62 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \ |
| 63 | case NAME##Model: return CMDFLAG; |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 64 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | static const char *getAnalysisDiagClientName(AnalysisDiagClients Kind) { |
| 69 | switch (Kind) { |
| 70 | default: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 71 | llvm_unreachable("Unknown analysis client!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 72 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE) \ |
| 73 | case PD_##NAME: return CMDFLAG; |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 74 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 78 | static const char *getAnalysisPurgeModeName(AnalysisPurgeMode Kind) { |
| 79 | switch (Kind) { |
| 80 | default: |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 81 | llvm_unreachable("Unknown analysis purge mode!"); |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 82 | #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \ |
| 83 | case NAME: return CMDFLAG; |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 84 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 88 | static const char *getAnalysisIPAModeName(AnalysisIPAMode Kind) { |
| 89 | switch (Kind) { |
| 90 | default: |
| 91 | llvm_unreachable("Unknown analysis ipa mode!"); |
| 92 | #define ANALYSIS_IPA(NAME, CMDFLAG, DESC) \ |
| 93 | case NAME: return CMDFLAG; |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 94 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | static const char * |
| 99 | getAnalysisInliningModeName(AnalysisInliningMode Kind) { |
| 100 | switch (Kind) { |
| 101 | default: |
| 102 | llvm_unreachable("Unknown analysis inlining mode!"); |
| 103 | #define ANALYSIS_INLINE_SELECTION(NAME, CMDFLAG, DESC) \ |
| 104 | case NAME: return CMDFLAG; |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 105 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 109 | //===----------------------------------------------------------------------===// |
| 110 | // Serialization (to args) |
| 111 | //===----------------------------------------------------------------------===// |
| 112 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 113 | namespace { |
| 114 | /// ToArgsList - Helper class to create a list of std::strings. |
| 115 | class ToArgsList { |
| 116 | std::vector<std::string> &Res; |
| 117 | public: |
| 118 | explicit ToArgsList(std::vector<std::string> &Res) : Res(Res) {} |
| 119 | |
| 120 | void push_back(StringRef Str) { |
| 121 | // Avoid creating a temporary string. |
| 122 | Res.push_back(std::string()); |
| 123 | Res.back().assign(Str.data(), Str.size()); |
| 124 | } |
| 125 | |
| 126 | void push_back(StringRef Str1, StringRef Str2) { |
| 127 | push_back(Str1); |
| 128 | push_back(Str2); |
| 129 | } |
| 130 | }; |
| 131 | } |
| 132 | |
| 133 | static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts, ToArgsList &Res) { |
Argyrios Kyrtzidis | 116f364 | 2011-02-25 00:09:51 +0000 | [diff] [blame] | 134 | if (Opts.ShowCheckerHelp) |
| 135 | Res.push_back("-analyzer-checker-help"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 136 | if (Opts.AnalysisStoreOpt != RegionStoreModel) |
| 137 | Res.push_back("-analyzer-store", |
| 138 | getAnalysisStoreName(Opts.AnalysisStoreOpt)); |
| 139 | if (Opts.AnalysisConstraintsOpt != RangeConstraintsModel) |
| 140 | Res.push_back("-analyzer-constraints", |
| 141 | getAnalysisConstraintName(Opts.AnalysisConstraintsOpt)); |
| 142 | if (Opts.AnalysisDiagOpt != PD_HTML) |
| 143 | Res.push_back("-analyzer-output", |
| 144 | getAnalysisDiagClientName(Opts.AnalysisDiagOpt)); |
| 145 | if (Opts.AnalysisPurgeOpt != PurgeStmt) |
| 146 | Res.push_back("-analyzer-purge", |
| 147 | getAnalysisPurgeModeName(Opts.AnalysisPurgeOpt)); |
| 148 | if (!Opts.AnalyzeSpecificFunction.empty()) |
| 149 | Res.push_back("-analyze-function", Opts.AnalyzeSpecificFunction); |
Anna Zaks | 3f2a55d | 2012-08-30 22:42:59 +0000 | [diff] [blame] | 150 | if (Opts.IPAMode != DynamicDispatchBifurcate) |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 151 | Res.push_back("-analyzer-ipa", getAnalysisIPAModeName(Opts.IPAMode)); |
| 152 | if (Opts.InliningMode != NoRedundancy) |
| 153 | Res.push_back("-analyzer-inlining-mode", |
| 154 | getAnalysisInliningModeName(Opts.InliningMode)); |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 155 | |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 156 | if (Opts.AnalyzeAll) |
| 157 | Res.push_back("-analyzer-opt-analyze-headers"); |
| 158 | if (Opts.AnalyzerDisplayProgress) |
| 159 | Res.push_back("-analyzer-display-progress"); |
Ted Kremenek | fc57651 | 2009-12-07 22:06:12 +0000 | [diff] [blame] | 160 | if (Opts.AnalyzeNestedBlocks) |
| 161 | Res.push_back("-analyzer-opt-analyze-nested-blocks"); |
Ted Kremenek | 0caa2d4 | 2012-08-30 19:26:48 +0000 | [diff] [blame] | 162 | if (Opts.eagerlyAssumeBinOpBifurcation) |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 163 | Res.push_back("-analyzer-eagerly-assume"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 164 | if (Opts.TrimGraph) |
| 165 | Res.push_back("-trim-egraph"); |
Ted Kremenek | 3b8a040 | 2012-08-30 19:26:53 +0000 | [diff] [blame] | 166 | if (Opts.visualizeExplodedGraphWithGraphViz) |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 167 | Res.push_back("-analyzer-viz-egraph-graphviz"); |
Ted Kremenek | 3b8a040 | 2012-08-30 19:26:53 +0000 | [diff] [blame] | 168 | if (Opts.visualizeExplodedGraphWithUbiGraph) |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 169 | Res.push_back("-analyzer-viz-egraph-ubigraph"); |
Anna Zaks | b47dbcb | 2012-03-28 19:59:16 +0000 | [diff] [blame] | 170 | if (Opts.NoRetryExhausted) |
| 171 | Res.push_back("-analyzer-disable-retry-exhausted"); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 172 | |
| 173 | for (unsigned i = 0, e = Opts.CheckersControlList.size(); i != e; ++i) { |
| 174 | const std::pair<std::string, bool> &opt = Opts.CheckersControlList[i]; |
| 175 | if (opt.second) |
| 176 | Res.push_back("-analyzer-disable-checker"); |
| 177 | else |
| 178 | Res.push_back("-analyzer-checker"); |
| 179 | Res.push_back(opt.first); |
| 180 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 183 | static void CodeGenOptsToArgs(const CodeGenOptions &Opts, ToArgsList &Res) { |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 184 | switch (Opts.DebugInfo) { |
| 185 | case CodeGenOptions::NoDebugInfo: |
| 186 | break; |
Alexey Samsonov | fd00eec | 2012-05-04 07:39:27 +0000 | [diff] [blame] | 187 | case CodeGenOptions::DebugLineTablesOnly: |
| 188 | Res.push_back("-gline-tables-only"); |
| 189 | break; |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 190 | case CodeGenOptions::LimitedDebugInfo: |
| 191 | Res.push_back("-g"); |
| 192 | Res.push_back("-flimit-debug-info"); |
| 193 | break; |
| 194 | case CodeGenOptions::FullDebugInfo: |
| 195 | Res.push_back("-g"); |
| 196 | Res.push_back("-fno-limit-debug-info"); |
| 197 | break; |
| 198 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 199 | if (Opts.DisableLLVMOpts) |
| 200 | Res.push_back("-disable-llvm-optzns"); |
| 201 | if (Opts.DisableRedZone) |
| 202 | Res.push_back("-disable-red-zone"); |
Nick Lewycky | 1db772b | 2012-01-23 08:29:12 +0000 | [diff] [blame] | 203 | if (Opts.DisableTailCalls) |
| 204 | Res.push_back("-mdisable-tail-calls"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 205 | if (!Opts.DebugCompilationDir.empty()) |
| 206 | Res.push_back("-fdebug-compilation-dir", Opts.DebugCompilationDir); |
| 207 | if (!Opts.DwarfDebugFlags.empty()) |
| 208 | Res.push_back("-dwarf-debug-flags", Opts.DwarfDebugFlags); |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 209 | if (Opts.EmitGcovArcs) |
| 210 | Res.push_back("-femit-coverage-data"); |
| 211 | if (Opts.EmitGcovNotes) |
| 212 | Res.push_back("-femit-coverage-notes"); |
Tanya Lattner | 198871c | 2012-07-11 23:02:10 +0000 | [diff] [blame] | 213 | if (Opts.EmitOpenCLArgMetadata) |
| 214 | Res.push_back("-cl-kernel-arg-info"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 215 | if (!Opts.MergeAllConstants) |
| 216 | Res.push_back("-fno-merge-all-constants"); |
Daniel Dunbar | 50a4487 | 2009-11-20 17:23:30 +0000 | [diff] [blame] | 217 | if (Opts.NoCommon) |
| 218 | Res.push_back("-fno-common"); |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 219 | if (Opts.ForbidGuardVariables) |
| 220 | Res.push_back("-fforbid-guard-variables"); |
Daniel Dunbar | e26bdb9 | 2011-06-21 18:54:46 +0000 | [diff] [blame] | 221 | if (Opts.UseRegisterSizedBitfieldAccess) |
| 222 | Res.push_back("-fuse-register-sized-bitfield-access"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 223 | if (Opts.NoImplicitFloat) |
| 224 | Res.push_back("-no-implicit-float"); |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 225 | if (Opts.OmitLeafFramePointer) |
| 226 | Res.push_back("-momit-leaf-frame-pointer"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 227 | if (Opts.OptimizeSize) { |
| 228 | assert(Opts.OptimizationLevel == 2 && "Invalid options!"); |
Bob Wilson | a0fa203 | 2011-04-29 22:49:50 +0000 | [diff] [blame] | 229 | Opts.OptimizeSize == 1 ? Res.push_back("-Os") : Res.push_back("-Oz"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 230 | } else if (Opts.OptimizationLevel != 0) |
| 231 | Res.push_back("-O" + llvm::utostr(Opts.OptimizationLevel)); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 232 | if (!Opts.MainFileName.empty()) |
| 233 | Res.push_back("-main-file-name", Opts.MainFileName); |
Daniel Dunbar | 001f628 | 2011-12-09 23:41:18 +0000 | [diff] [blame] | 234 | if (Opts.NoInfsFPMath) |
| 235 | Res.push_back("-menable-no-infinities"); |
| 236 | if (Opts.NoNaNsFPMath) |
| 237 | Res.push_back("-menable-no-nans"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 238 | // SimplifyLibCalls is only derived. |
| 239 | // TimePasses is only derived. |
| 240 | // UnitAtATime is unused. |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 241 | // Inlining is only derived. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 242 | |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 243 | // UnrollLoops is derived, but also accepts an option, no |
| 244 | // harm in pushing it back here. |
| 245 | if (Opts.UnrollLoops) |
| 246 | Res.push_back("-funroll-loops"); |
Chris Lattner | bbea716 | 2010-04-13 00:38:24 +0000 | [diff] [blame] | 247 | if (Opts.DataSections) |
| 248 | Res.push_back("-fdata-sections"); |
| 249 | if (Opts.FunctionSections) |
| 250 | Res.push_back("-ffunction-sections"); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 251 | if (Opts.AsmVerbose) |
| 252 | Res.push_back("-masm-verbose"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 253 | if (!Opts.CodeModel.empty()) |
| 254 | Res.push_back("-mcode-model", Opts.CodeModel); |
Peter Collingbourne | d51e43a | 2011-10-06 18:29:46 +0000 | [diff] [blame] | 255 | if (Opts.CUDAIsDevice) |
| 256 | Res.push_back("-fcuda-is-device"); |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 257 | if (!Opts.CXAAtExit) |
| 258 | Res.push_back("-fno-use-cxa-atexit"); |
| 259 | if (Opts.CXXCtorDtorAliases) |
| 260 | Res.push_back("-mconstructor-aliases"); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 261 | if (Opts.ObjCAutoRefCountExceptions) |
| 262 | Res.push_back("-fobjc-arc-eh"); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 263 | if (!Opts.DebugPass.empty()) { |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 264 | Res.push_back("-mdebug-pass", Opts.DebugPass); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 265 | } |
| 266 | if (Opts.DisableFPElim) |
| 267 | Res.push_back("-mdisable-fp-elim"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 268 | if (!Opts.FloatABI.empty()) |
| 269 | Res.push_back("-mfloat-abi", Opts.FloatABI); |
| 270 | if (!Opts.LimitFloatPrecision.empty()) |
| 271 | Res.push_back("-mlimit-float-precision", Opts.LimitFloatPrecision); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 272 | if (Opts.NoZeroInitializedInBSS) |
| 273 | Res.push_back("-mno-zero-initialized-bss"); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 274 | switch (Opts.getObjCDispatchMethod()) { |
| 275 | case CodeGenOptions::Legacy: |
| 276 | break; |
| 277 | case CodeGenOptions::Mixed: |
| 278 | Res.push_back("-fobjc-dispatch-method=mixed"); |
| 279 | break; |
| 280 | case CodeGenOptions::NonLegacy: |
| 281 | Res.push_back("-fobjc-dispatch-method=non-legacy"); |
| 282 | break; |
| 283 | } |
Nuno Lopes | def1849 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 284 | if (Opts.BoundsChecking > 0) |
| 285 | Res.push_back("-fbounds-checking=" + llvm::utostr(Opts.BoundsChecking)); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 286 | if (Opts.NumRegisterParameters) |
| 287 | Res.push_back("-mregparm", llvm::utostr(Opts.NumRegisterParameters)); |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 288 | if (Opts.NoGlobalMerge) |
| 289 | Res.push_back("-mno-global-merge"); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 290 | if (Opts.NoExecStack) |
| 291 | Res.push_back("-mnoexecstack"); |
Daniel Dunbar | 4ecc9b7 | 2010-05-27 05:39:39 +0000 | [diff] [blame] | 292 | if (Opts.RelaxAll) |
| 293 | Res.push_back("-mrelax-all"); |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 294 | if (Opts.SaveTempLabels) |
| 295 | Res.push_back("-msave-temp-labels"); |
Rafael Espindola | f24a151 | 2011-04-30 18:35:43 +0000 | [diff] [blame] | 296 | if (Opts.NoDwarf2CFIAsm) |
| 297 | Res.push_back("-fno-dwarf2-cfi-asm"); |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 298 | if (Opts.NoDwarfDirectoryAsm) |
| 299 | Res.push_back("-fno-dwarf-directory-asm"); |
Daniel Dunbar | 3b31526 | 2009-11-30 08:42:00 +0000 | [diff] [blame] | 300 | if (Opts.SoftFloat) |
| 301 | Res.push_back("-msoft-float"); |
Chandler Carruth | 82fe6ae | 2012-03-27 23:58:37 +0000 | [diff] [blame] | 302 | if (Opts.StrictEnums) |
| 303 | Res.push_back("-fstrict-enums"); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 304 | if (Opts.UnwindTables) |
| 305 | Res.push_back("-munwind-tables"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 306 | if (Opts.RelocationModel != "pic") |
| 307 | Res.push_back("-mrelocation-model", Opts.RelocationModel); |
John McCall | b689afb | 2010-02-13 03:50:24 +0000 | [diff] [blame] | 308 | if (!Opts.VerifyModule) |
| 309 | Res.push_back("-disable-llvm-verifier"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 310 | for (unsigned i = 0, e = Opts.BackendOptions.size(); i != e; ++i) |
| 311 | Res.push_back("-backend-option", Opts.BackendOptions[i]); |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 312 | |
| 313 | switch (Opts.DefaultTLSModel) { |
| 314 | case CodeGenOptions::GeneralDynamicTLSModel: |
| 315 | break; |
| 316 | case CodeGenOptions::LocalDynamicTLSModel: |
| 317 | Res.push_back("-ftls-model=local-dynamic"); |
| 318 | break; |
| 319 | case CodeGenOptions::InitialExecTLSModel: |
| 320 | Res.push_back("-ftls-model=initial-exec"); |
| 321 | break; |
| 322 | case CodeGenOptions::LocalExecTLSModel: |
| 323 | Res.push_back("-ftls-model=local-exec"); |
| 324 | break; |
| 325 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void DependencyOutputOptsToArgs(const DependencyOutputOptions &Opts, |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 329 | ToArgsList &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 330 | if (Opts.IncludeSystemHeaders) |
| 331 | Res.push_back("-sys-header-deps"); |
Daniel Dunbar | eef63e0 | 2011-02-02 15:41:17 +0000 | [diff] [blame] | 332 | if (Opts.ShowHeaderIncludes) |
| 333 | Res.push_back("-H"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 334 | if (!Opts.HeaderIncludeOutputFile.empty()) |
| 335 | Res.push_back("-header-include-file", Opts.HeaderIncludeOutputFile); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 336 | if (Opts.UsePhonyTargets) |
| 337 | Res.push_back("-MP"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 338 | if (!Opts.OutputFile.empty()) |
| 339 | Res.push_back("-dependency-file", Opts.OutputFile); |
| 340 | for (unsigned i = 0, e = Opts.Targets.size(); i != e; ++i) |
| 341 | Res.push_back("-MT", Opts.Targets[i]); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts, |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 345 | ToArgsList &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 346 | if (Opts.IgnoreWarnings) |
| 347 | Res.push_back("-w"); |
| 348 | if (Opts.NoRewriteMacros) |
| 349 | Res.push_back("-Wno-rewrite-macros"); |
| 350 | if (Opts.Pedantic) |
| 351 | Res.push_back("-pedantic"); |
| 352 | if (Opts.PedanticErrors) |
| 353 | Res.push_back("-pedantic-errors"); |
| 354 | if (!Opts.ShowColumn) |
| 355 | Res.push_back("-fno-show-column"); |
| 356 | if (!Opts.ShowLocation) |
| 357 | Res.push_back("-fno-show-source-location"); |
| 358 | if (!Opts.ShowCarets) |
| 359 | Res.push_back("-fno-caret-diagnostics"); |
| 360 | if (!Opts.ShowFixits) |
| 361 | Res.push_back("-fno-diagnostics-fixit-info"); |
| 362 | if (Opts.ShowSourceRanges) |
| 363 | Res.push_back("-fdiagnostics-print-source-range-info"); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 364 | if (Opts.ShowParseableFixits) |
| 365 | Res.push_back("-fdiagnostics-parseable-fixits"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 366 | if (Opts.ShowColors) |
| 367 | Res.push_back("-fcolor-diagnostics"); |
| 368 | if (Opts.VerifyDiagnostics) |
| 369 | Res.push_back("-verify"); |
| 370 | if (Opts.ShowOptionNames) |
| 371 | Res.push_back("-fdiagnostics-show-option"); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 372 | if (Opts.ShowCategories == 1) |
| 373 | Res.push_back("-fdiagnostics-show-category=id"); |
| 374 | else if (Opts.ShowCategories == 2) |
| 375 | Res.push_back("-fdiagnostics-show-category=name"); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 376 | switch (Opts.Format) { |
| 377 | case DiagnosticOptions::Clang: |
| 378 | Res.push_back("-fdiagnostics-format=clang"); break; |
| 379 | case DiagnosticOptions::Msvc: |
| 380 | Res.push_back("-fdiagnostics-format=msvc"); break; |
| 381 | case DiagnosticOptions::Vi: |
| 382 | Res.push_back("-fdiagnostics-format=vi"); break; |
| 383 | } |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 384 | if (Opts.ErrorLimit) |
| 385 | Res.push_back("-ferror-limit", llvm::utostr(Opts.ErrorLimit)); |
| 386 | if (!Opts.DiagnosticLogFile.empty()) |
| 387 | Res.push_back("-diagnostic-log-file", Opts.DiagnosticLogFile); |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 388 | if (Opts.MacroBacktraceLimit |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 389 | != DiagnosticOptions::DefaultMacroBacktraceLimit) |
| 390 | Res.push_back("-fmacro-backtrace-limit", |
| 391 | llvm::utostr(Opts.MacroBacktraceLimit)); |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 392 | if (Opts.TemplateBacktraceLimit |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 393 | != DiagnosticOptions::DefaultTemplateBacktraceLimit) |
| 394 | Res.push_back("-ftemplate-backtrace-limit", |
| 395 | llvm::utostr(Opts.TemplateBacktraceLimit)); |
Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 396 | if (Opts.ConstexprBacktraceLimit |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 397 | != DiagnosticOptions::DefaultConstexprBacktraceLimit) |
| 398 | Res.push_back("-fconstexpr-backtrace-limit", |
| 399 | llvm::utostr(Opts.ConstexprBacktraceLimit)); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 400 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 401 | if (Opts.TabStop != DiagnosticOptions::DefaultTabStop) |
| 402 | Res.push_back("-ftabstop", llvm::utostr(Opts.TabStop)); |
| 403 | if (Opts.MessageLength) |
| 404 | Res.push_back("-fmessage-length", llvm::utostr(Opts.MessageLength)); |
| 405 | if (!Opts.DumpBuildInformation.empty()) |
| 406 | Res.push_back("-dump-build-information", Opts.DumpBuildInformation); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 407 | for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) |
| 408 | Res.push_back("-W" + Opts.Warnings[i]); |
| 409 | } |
| 410 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 411 | static const char *getInputKindName(InputKind Kind) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 412 | switch (Kind) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 413 | case IK_None: break; |
| 414 | case IK_AST: return "ast"; |
| 415 | case IK_Asm: return "assembler-with-cpp"; |
| 416 | case IK_C: return "c"; |
| 417 | case IK_CXX: return "c++"; |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 418 | case IK_LLVM_IR: return "ir"; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 419 | case IK_ObjC: return "objective-c"; |
| 420 | case IK_ObjCXX: return "objective-c++"; |
| 421 | case IK_OpenCL: return "cl"; |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 422 | case IK_CUDA: return "cuda"; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 423 | case IK_PreprocessedC: return "cpp-output"; |
| 424 | case IK_PreprocessedCXX: return "c++-cpp-output"; |
| 425 | case IK_PreprocessedObjC: return "objective-c-cpp-output"; |
| 426 | case IK_PreprocessedObjCXX:return "objective-c++-cpp-output"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 429 | llvm_unreachable("Unexpected language kind!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static const char *getActionName(frontend::ActionKind Kind) { |
| 433 | switch (Kind) { |
| 434 | case frontend::PluginAction: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 435 | llvm_unreachable("Invalid kind!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 436 | |
Alexander Kornienko | 171af64 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 437 | case frontend::ASTDeclList: return "-ast-list"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 438 | case frontend::ASTDump: return "-ast-dump"; |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 439 | case frontend::ASTDumpXML: return "-ast-dump-xml"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 440 | case frontend::ASTPrint: return "-ast-print"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 441 | case frontend::ASTView: return "-ast-view"; |
| 442 | case frontend::DumpRawTokens: return "-dump-raw-tokens"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 443 | case frontend::DumpTokens: return "-dump-tokens"; |
| 444 | case frontend::EmitAssembly: return "-S"; |
| 445 | case frontend::EmitBC: return "-emit-llvm-bc"; |
| 446 | case frontend::EmitHTML: return "-emit-html"; |
| 447 | case frontend::EmitLLVM: return "-emit-llvm"; |
| 448 | case frontend::EmitLLVMOnly: return "-emit-llvm-only"; |
Daniel Dunbar | 32148ce | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 449 | case frontend::EmitCodeGenOnly: return "-emit-codegen-only"; |
Daniel Dunbar | da1573f | 2010-02-03 01:18:43 +0000 | [diff] [blame] | 450 | case frontend::EmitObj: return "-emit-obj"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 451 | case frontend::FixIt: return "-fixit"; |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 452 | case frontend::GenerateModule: return "-emit-module"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 453 | case frontend::GeneratePCH: return "-emit-pch"; |
| 454 | case frontend::GeneratePTH: return "-emit-pth"; |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 455 | case frontend::InitOnly: return "-init-only"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 456 | case frontend::ParseSyntaxOnly: return "-fsyntax-only"; |
| 457 | case frontend::PrintDeclContext: return "-print-decl-contexts"; |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 458 | case frontend::PrintPreamble: return "-print-preamble"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 459 | case frontend::PrintPreprocessedInput: return "-E"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 460 | case frontend::RewriteMacros: return "-rewrite-macros"; |
| 461 | case frontend::RewriteObjC: return "-rewrite-objc"; |
| 462 | case frontend::RewriteTest: return "-rewrite-test"; |
| 463 | case frontend::RunAnalysis: return "-analyze"; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 464 | case frontend::MigrateSource: return "-migrate"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 465 | case frontend::RunPreprocessorOnly: return "-Eonly"; |
| 466 | } |
| 467 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 468 | llvm_unreachable("Unexpected language kind!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 471 | static void FileSystemOptsToArgs(const FileSystemOptions &Opts, ToArgsList &Res){ |
| 472 | if (!Opts.WorkingDir.empty()) |
| 473 | Res.push_back("-working-directory", Opts.WorkingDir); |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Dmitri Gribenko | d99ef53 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 476 | static void CodeCompleteOptionsToArgs(const CodeCompleteOptions &Opts, |
| 477 | ToArgsList &Res) { |
| 478 | if (Opts.IncludeMacros) |
| 479 | Res.push_back("-code-completion-macros"); |
| 480 | if (Opts.IncludeCodePatterns) |
| 481 | Res.push_back("-code-completion-patterns"); |
| 482 | if (!Opts.IncludeGlobals) |
| 483 | Res.push_back("-no-code-completion-globals"); |
| 484 | if (Opts.IncludeBriefComments) |
| 485 | Res.push_back("-code-completion-brief-comments"); |
| 486 | } |
| 487 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 488 | static void FrontendOptsToArgs(const FrontendOptions &Opts, ToArgsList &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 489 | if (Opts.DisableFree) |
| 490 | Res.push_back("-disable-free"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 491 | if (Opts.RelocatablePCH) |
| 492 | Res.push_back("-relocatable-pch"); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 493 | if (Opts.ShowHelp) |
| 494 | Res.push_back("-help"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 495 | if (Opts.ShowStats) |
Daniel Dunbar | eb01ac8 | 2009-11-25 10:14:52 +0000 | [diff] [blame] | 496 | Res.push_back("-print-stats"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 497 | if (Opts.ShowTimers) |
| 498 | Res.push_back("-ftime-report"); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 499 | if (Opts.ShowVersion) |
| 500 | Res.push_back("-version"); |
Nick Lewycky | 1450f26 | 2010-08-13 17:31:00 +0000 | [diff] [blame] | 501 | if (Opts.FixWhatYouCan) |
| 502 | Res.push_back("-fix-what-you-can"); |
Argyrios Kyrtzidis | 61d679a | 2012-01-26 02:40:48 +0000 | [diff] [blame] | 503 | if (Opts.FixOnlyWarnings) |
| 504 | Res.push_back("-fix-only-warnings"); |
| 505 | if (Opts.FixAndRecompile) |
| 506 | Res.push_back("-fixit-recompile"); |
| 507 | if (Opts.FixToTemporaries) |
| 508 | Res.push_back("-fixit-to-temporary"); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 509 | switch (Opts.ARCMTAction) { |
| 510 | case FrontendOptions::ARCMT_None: |
| 511 | break; |
| 512 | case FrontendOptions::ARCMT_Check: |
| 513 | Res.push_back("-arcmt-check"); |
| 514 | break; |
| 515 | case FrontendOptions::ARCMT_Modify: |
| 516 | Res.push_back("-arcmt-modify"); |
| 517 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 518 | case FrontendOptions::ARCMT_Migrate: |
| 519 | Res.push_back("-arcmt-migrate"); |
| 520 | break; |
| 521 | } |
Dmitri Gribenko | d99ef53 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 522 | CodeCompleteOptionsToArgs(Opts.CodeCompleteOpts, Res); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 523 | if (!Opts.MTMigrateDir.empty()) |
| 524 | Res.push_back("-mt-migrate-directory", Opts.MTMigrateDir); |
| 525 | if (!Opts.ARCMTMigrateReportOut.empty()) |
| 526 | Res.push_back("-arcmt-migrate-report-output", Opts.ARCMTMigrateReportOut); |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 527 | if (Opts.ARCMTMigrateEmitARCErrors) |
| 528 | Res.push_back("-arcmt-migrate-emit-errors"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 529 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 530 | if (Opts.ObjCMTAction & ~FrontendOptions::ObjCMT_Literals) |
| 531 | Res.push_back("-objcmt-migrate-literals"); |
| 532 | if (Opts.ObjCMTAction & ~FrontendOptions::ObjCMT_Subscripting) |
| 533 | Res.push_back("-objcmt-migrate-subscripting"); |
| 534 | |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 535 | bool NeedLang = false; |
| 536 | for (unsigned i = 0, e = Opts.Inputs.size(); i != e; ++i) |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 537 | if (FrontendOptions::getInputKindForExtension(Opts.Inputs[i].File) != |
| 538 | Opts.Inputs[i].Kind) |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 539 | NeedLang = true; |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 540 | if (NeedLang) |
| 541 | Res.push_back("-x", getInputKindName(Opts.Inputs[0].Kind)); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 542 | for (unsigned i = 0, e = Opts.Inputs.size(); i != e; ++i) { |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 543 | assert((!NeedLang || Opts.Inputs[i].Kind == Opts.Inputs[0].Kind) && |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 544 | "Unable to represent this input vector!"); |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 545 | Res.push_back(Opts.Inputs[i].File); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 548 | if (!Opts.OutputFile.empty()) |
| 549 | Res.push_back("-o", Opts.OutputFile); |
| 550 | if (!Opts.CodeCompletionAt.FileName.empty()) |
| 551 | Res.push_back("-code-completion-at", |
| 552 | Opts.CodeCompletionAt.FileName + ":" + |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 553 | llvm::utostr(Opts.CodeCompletionAt.Line) + ":" + |
| 554 | llvm::utostr(Opts.CodeCompletionAt.Column)); |
Douglas Gregor | 91a230a | 2011-02-17 19:04:40 +0000 | [diff] [blame] | 555 | if (Opts.ProgramAction != frontend::PluginAction) |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 556 | Res.push_back(getActionName(Opts.ProgramAction)); |
| 557 | if (!Opts.ActionName.empty()) { |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 558 | Res.push_back("-plugin", Opts.ActionName); |
| 559 | for(unsigned i = 0, e = Opts.PluginArgs.size(); i != e; ++i) |
| 560 | Res.push_back("-plugin-arg-" + Opts.ActionName, Opts.PluginArgs[i]); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 561 | } |
Alexander Kornienko | e34a052 | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 562 | if (!Opts.ASTDumpFilter.empty()) |
| 563 | Res.push_back("-ast-dump-filter", Opts.ASTDumpFilter); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 564 | for (unsigned i = 0, e = Opts.Plugins.size(); i != e; ++i) |
| 565 | Res.push_back("-load", Opts.Plugins[i]); |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 566 | for (unsigned i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) { |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 567 | Res.push_back("-add-plugin", Opts.AddPluginActions[i]); |
| 568 | for(unsigned ai = 0, ae = Opts.AddPluginArgs.size(); ai != ae; ++ai) |
| 569 | Res.push_back("-plugin-arg-" + Opts.AddPluginActions[i], |
| 570 | Opts.AddPluginArgs[i][ai]); |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 571 | } |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 572 | for (unsigned i = 0, e = Opts.ASTMergeFiles.size(); i != e; ++i) |
| 573 | Res.push_back("-ast-merge", Opts.ASTMergeFiles[i]); |
| 574 | for (unsigned i = 0, e = Opts.LLVMArgs.size(); i != e; ++i) |
| 575 | Res.push_back("-mllvm", Opts.LLVMArgs[i]); |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 576 | if (!Opts.OverrideRecordLayoutsFile.empty()) |
| 577 | Res.push_back("-foverride-record-layout=" + Opts.OverrideRecordLayoutsFile); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts, |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 581 | ToArgsList &Res) { |
Daniel Dunbar | c59dc92 | 2009-11-19 05:32:21 +0000 | [diff] [blame] | 582 | if (Opts.Sysroot != "/") { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 583 | Res.push_back("-isysroot"); |
| 584 | Res.push_back(Opts.Sysroot); |
| 585 | } |
| 586 | |
| 587 | /// User specified include entries. |
| 588 | for (unsigned i = 0, e = Opts.UserEntries.size(); i != e; ++i) { |
| 589 | const HeaderSearchOptions::Entry &E = Opts.UserEntries[i]; |
Daniel Dunbar | d8c7806 | 2009-11-26 02:13:54 +0000 | [diff] [blame] | 590 | if (E.IsFramework && (E.Group != frontend::Angled || !E.IsUserSupplied)) |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 591 | llvm::report_fatal_error("Invalid option set!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 592 | if (E.IsUserSupplied) { |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 593 | switch (E.Group) { |
| 594 | case frontend::After: |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 595 | Res.push_back("-idirafter"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 596 | break; |
| 597 | |
| 598 | case frontend::Quoted: |
Daniel Dunbar | d8c7806 | 2009-11-26 02:13:54 +0000 | [diff] [blame] | 599 | Res.push_back("-iquote"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 600 | break; |
| 601 | |
| 602 | case frontend::System: |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 603 | Res.push_back("-isystem"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 604 | break; |
| 605 | |
| 606 | case frontend::IndexHeaderMap: |
| 607 | Res.push_back("-index-header-map"); |
| 608 | Res.push_back(E.IsFramework? "-F" : "-I"); |
| 609 | break; |
| 610 | |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 611 | case frontend::CSystem: |
| 612 | Res.push_back("-c-isystem"); |
| 613 | break; |
| 614 | |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 615 | case frontend::CXXSystem: |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 616 | Res.push_back("-cxx-isystem"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 617 | break; |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 618 | |
| 619 | case frontend::ObjCSystem: |
| 620 | Res.push_back("-objc-isystem"); |
| 621 | break; |
| 622 | |
| 623 | case frontend::ObjCXXSystem: |
| 624 | Res.push_back("-objcxx-isystem"); |
| 625 | break; |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 626 | |
| 627 | case frontend::Angled: |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 628 | Res.push_back(E.IsFramework ? "-F" : "-I"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 629 | break; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 630 | } |
| 631 | } else { |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 632 | if (E.IsInternal) { |
| 633 | assert(E.Group == frontend::System && "Unexpected header search group"); |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 634 | if (E.ImplicitExternC) |
Chandler Carruth | 103accc | 2011-11-05 09:24:44 +0000 | [diff] [blame] | 635 | Res.push_back("-internal-externc-isystem"); |
| 636 | else |
| 637 | Res.push_back("-internal-isystem"); |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 638 | } else { |
| 639 | if (E.Group != frontend::Angled && E.Group != frontend::System) |
| 640 | llvm::report_fatal_error("Invalid option set!"); |
| 641 | Res.push_back(E.Group == frontend::Angled ? "-iwithprefixbefore" : |
| 642 | "-iwithprefix"); |
| 643 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 644 | } |
| 645 | Res.push_back(E.Path); |
| 646 | } |
| 647 | |
Richard Smith | f122a13 | 2012-06-13 20:27:03 +0000 | [diff] [blame] | 648 | /// User-specified system header prefixes. |
| 649 | for (unsigned i = 0, e = Opts.SystemHeaderPrefixes.size(); i != e; ++i) { |
| 650 | if (Opts.SystemHeaderPrefixes[i].IsSystemHeader) |
| 651 | Res.push_back("-isystem-prefix"); |
| 652 | else |
| 653 | Res.push_back("-ino-system-prefix"); |
| 654 | |
| 655 | Res.push_back(Opts.SystemHeaderPrefixes[i].Prefix); |
| 656 | } |
| 657 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 658 | if (!Opts.ResourceDir.empty()) |
| 659 | Res.push_back("-resource-dir", Opts.ResourceDir); |
| 660 | if (!Opts.ModuleCachePath.empty()) |
| 661 | Res.push_back("-fmodule-cache-path", Opts.ModuleCachePath); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 662 | if (!Opts.UseStandardSystemIncludes) |
| 663 | Res.push_back("-nostdsysteminc"); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 664 | if (!Opts.UseStandardCXXIncludes) |
| 665 | Res.push_back("-nostdinc++"); |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 666 | if (Opts.UseLibcxx) |
| 667 | Res.push_back("-stdlib=libc++"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 668 | if (Opts.Verbose) |
| 669 | Res.push_back("-v"); |
| 670 | } |
| 671 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 672 | static void LangOptsToArgs(const LangOptions &Opts, ToArgsList &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 673 | LangOptions DefaultLangOpts; |
| 674 | |
| 675 | // FIXME: Need to set -std to get all the implicit options. |
| 676 | |
| 677 | // FIXME: We want to only pass options relative to the defaults, which |
| 678 | // requires constructing a target. :( |
| 679 | // |
| 680 | // It would be better to push the all target specific choices into the driver, |
| 681 | // so that everything below that was more uniform. |
| 682 | |
| 683 | if (Opts.Trigraphs) |
| 684 | Res.push_back("-trigraphs"); |
| 685 | // Implicit based on the input kind: |
| 686 | // AsmPreprocessor, CPlusPlus, ObjC1, ObjC2, OpenCL |
| 687 | // Implicit based on the input language standard: |
| 688 | // BCPLComment, C99, CPlusPlus0x, Digraphs, GNUInline, ImplicitInt, GNUMode |
| 689 | if (Opts.DollarIdents) |
| 690 | Res.push_back("-fdollars-in-identifiers"); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 691 | if (Opts.GNUMode && !Opts.GNUKeywords) |
| 692 | Res.push_back("-fno-gnu-keywords"); |
| 693 | if (!Opts.GNUMode && Opts.GNUKeywords) |
| 694 | Res.push_back("-fgnu-keywords"); |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 695 | if (Opts.MicrosoftExt) |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 696 | Res.push_back("-fms-extensions"); |
Douglas Gregor | 0bb935c | 2011-10-24 15:27:23 +0000 | [diff] [blame] | 697 | if (Opts.MicrosoftMode) |
| 698 | Res.push_back("-fms-compatibility"); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 699 | if (Opts.MSCVersion != 0) |
| 700 | Res.push_back("-fmsc-version=" + llvm::utostr(Opts.MSCVersion)); |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 701 | if (Opts.Borland) |
| 702 | Res.push_back("-fborland-extensions"); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 703 | if (Opts.ObjCDefaultSynthProperties) |
| 704 | Res.push_back("-fobjc-default-synthesize-properties"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 705 | // NoInline is implicit. |
| 706 | if (!Opts.CXXOperatorNames) |
| 707 | Res.push_back("-fno-operator-names"); |
| 708 | if (Opts.PascalStrings) |
| 709 | Res.push_back("-fpascal-strings"); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 710 | if (Opts.CatchUndefined) |
| 711 | Res.push_back("-fcatch-undefined-behavior"); |
Kostya Serebryany | b619688 | 2011-11-22 01:28:36 +0000 | [diff] [blame] | 712 | if (Opts.AddressSanitizer) |
| 713 | Res.push_back("-faddress-sanitizer"); |
Kostya Serebryany | 3c93122 | 2012-03-01 22:27:08 +0000 | [diff] [blame] | 714 | if (Opts.ThreadSanitizer) |
| 715 | Res.push_back("-fthread-sanitizer"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 716 | if (Opts.WritableStrings) |
| 717 | Res.push_back("-fwritable-strings"); |
John McCall | 4b7a834 | 2010-03-15 10:54:44 +0000 | [diff] [blame] | 718 | if (Opts.ConstStrings) |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 719 | Res.push_back("-fconst-strings"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 720 | if (!Opts.LaxVectorConversions) |
| 721 | Res.push_back("-fno-lax-vector-conversions"); |
| 722 | if (Opts.AltiVec) |
| 723 | Res.push_back("-faltivec"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 724 | if (Opts.Exceptions) |
| 725 | Res.push_back("-fexceptions"); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 726 | if (Opts.ObjCExceptions) |
| 727 | Res.push_back("-fobjc-exceptions"); |
| 728 | if (Opts.CXXExceptions) |
| 729 | Res.push_back("-fcxx-exceptions"); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 730 | if (Opts.SjLjExceptions) |
| 731 | Res.push_back("-fsjlj-exceptions"); |
Daniel Dunbar | 2ed4228 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 732 | if (Opts.TraditionalCPP) |
| 733 | Res.push_back("-traditional-cpp"); |
Mike Stump | de05057 | 2009-12-02 18:57:08 +0000 | [diff] [blame] | 734 | if (!Opts.RTTI) |
Daniel Dunbar | 4db166b | 2009-11-19 05:32:09 +0000 | [diff] [blame] | 735 | Res.push_back("-fno-rtti"); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 736 | if (Opts.MSBitfields) |
| 737 | Res.push_back("-mms-bitfields"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 738 | if (Opts.Freestanding) |
| 739 | Res.push_back("-ffreestanding"); |
| 740 | if (Opts.NoBuiltin) |
| 741 | Res.push_back("-fno-builtin"); |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 742 | if (!Opts.AssumeSaneOperatorNew) |
| 743 | Res.push_back("-fno-assume-sane-operator-new"); |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 744 | if (!Opts.ThreadsafeStatics) |
| 745 | Res.push_back("-fno-threadsafe-statics"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 746 | if (Opts.POSIXThreads) |
| 747 | Res.push_back("-pthread"); |
Daniel Dunbar | a51ca52 | 2009-11-17 09:15:57 +0000 | [diff] [blame] | 748 | if (Opts.Blocks) |
Daniel Dunbar | e50c167 | 2009-11-29 05:52:21 +0000 | [diff] [blame] | 749 | Res.push_back("-fblocks"); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 750 | if (Opts.BlocksRuntimeOptional) |
| 751 | Res.push_back("-fblocks-runtime-optional"); |
Douglas Gregor | 752c74d | 2012-01-03 17:07:34 +0000 | [diff] [blame] | 752 | if (Opts.Modules) |
| 753 | Res.push_back("-fmodules"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 754 | if (Opts.EmitAllDecls) |
| 755 | Res.push_back("-femit-all-decls"); |
Dan Gohman | c31176d | 2010-01-08 02:20:44 +0000 | [diff] [blame] | 756 | if (Opts.MathErrno) |
| 757 | Res.push_back("-fmath-errno"); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 758 | switch (Opts.getSignedOverflowBehavior()) { |
| 759 | case LangOptions::SOB_Undefined: break; |
| 760 | case LangOptions::SOB_Defined: Res.push_back("-fwrapv"); break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 761 | case LangOptions::SOB_Trapping: |
Douglas Gregor | 21a2516 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 762 | Res.push_back("-ftrapv"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 763 | if (!Opts.OverflowHandler.empty()) |
| 764 | Res.push_back("-ftrapv-handler", Opts.OverflowHandler); |
Douglas Gregor | 21a2516 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 765 | break; |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 766 | } |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 767 | switch (Opts.getFPContractMode()) { |
| 768 | case LangOptions::FPC_Off: Res.push_back("-ffp-contract=off"); break; |
| 769 | case LangOptions::FPC_On: Res.push_back("-ffp-contract=on"); break; |
| 770 | case LangOptions::FPC_Fast: Res.push_back("-ffp-contract=fast"); break; |
| 771 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 772 | if (Opts.HeinousExtensions) |
| 773 | Res.push_back("-fheinous-gnu-extensions"); |
| 774 | // Optimize is implicit. |
| 775 | // OptimizeSize is implicit. |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 776 | if (Opts.FastMath) |
| 777 | Res.push_back("-ffast-math"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 778 | if (Opts.Static) |
| 779 | Res.push_back("-static-define"); |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 780 | if (Opts.DumpRecordLayoutsSimple) |
| 781 | Res.push_back("-fdump-record-layouts-simple"); |
| 782 | else if (Opts.DumpRecordLayouts) |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 783 | Res.push_back("-fdump-record-layouts"); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 784 | if (Opts.DumpVTableLayouts) |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 785 | Res.push_back("-fdump-vtable-layouts"); |
| 786 | if (Opts.NoBitFieldTypeAlign) |
| 787 | Res.push_back("-fno-bitfield-type-alignment"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 788 | if (Opts.PICLevel) |
| 789 | Res.push_back("-pic-level", llvm::utostr(Opts.PICLevel)); |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 790 | if (Opts.PIELevel) |
| 791 | Res.push_back("-pie-level", llvm::utostr(Opts.PIELevel)); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 792 | if (Opts.ObjCGCBitmapPrint) |
| 793 | Res.push_back("-print-ivar-layout"); |
Fariborz Jahanian | 33e982b | 2010-04-22 20:26:39 +0000 | [diff] [blame] | 794 | if (Opts.NoConstantCFStrings) |
| 795 | Res.push_back("-fno-constant-cfstrings"); |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 796 | if (!Opts.AccessControl) |
| 797 | Res.push_back("-fno-access-control"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 798 | if (!Opts.CharIsSigned) |
Daniel Dunbar | e50c167 | 2009-11-29 05:52:21 +0000 | [diff] [blame] | 799 | Res.push_back("-fno-signed-char"); |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 800 | if (Opts.CPlusPlus && !Opts.WChar) |
| 801 | Res.push_back("-fno-wchar"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 802 | if (Opts.ShortWChar) |
| 803 | Res.push_back("-fshort-wchar"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 804 | if (!Opts.ElideConstructors) |
| 805 | Res.push_back("-fno-elide-constructors"); |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 806 | if (Opts.getGC() != LangOptions::NonGC) { |
| 807 | if (Opts.getGC() == LangOptions::HybridGC) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 808 | Res.push_back("-fobjc-gc"); |
| 809 | } else { |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 810 | assert(Opts.getGC() == LangOptions::GCOnly && "Invalid GC mode!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 811 | Res.push_back("-fobjc-gc-only"); |
| 812 | } |
| 813 | } |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 814 | Res.push_back("-fobjc-runtime=" + Opts.ObjCRuntime.getAsString()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 815 | if (Opts.ObjCAutoRefCount) |
| 816 | Res.push_back("-fobjc-arc"); |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 817 | if (Opts.ObjCARCWeak) |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 818 | Res.push_back("-fobjc-runtime-has-weak"); |
Douglas Gregor | 74da19f | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 819 | if (!Opts.ObjCInferRelatedResultType) |
| 820 | Res.push_back("-fno-objc-infer-related-result-type"); |
| 821 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 822 | if (Opts.AppleKext) |
| 823 | Res.push_back("-fapple-kext"); |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 824 | |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 825 | if (Opts.getVisibilityMode() != DefaultVisibility) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 826 | Res.push_back("-fvisibility"); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 827 | if (Opts.getVisibilityMode() == HiddenVisibility) { |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 828 | Res.push_back("hidden"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 829 | } else { |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 830 | assert(Opts.getVisibilityMode() == ProtectedVisibility && |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 831 | "Invalid visibility!"); |
| 832 | Res.push_back("protected"); |
| 833 | } |
| 834 | } |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 835 | if (Opts.InlineVisibilityHidden) |
| 836 | Res.push_back("-fvisibility-inlines-hidden"); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 837 | |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 838 | if (Opts.getStackProtector() != 0) |
| 839 | Res.push_back("-stack-protector", llvm::utostr(Opts.getStackProtector())); |
| 840 | if (Opts.InstantiationDepth != DefaultLangOpts.InstantiationDepth) |
| 841 | Res.push_back("-ftemplate-depth", llvm::utostr(Opts.InstantiationDepth)); |
| 842 | if (Opts.ConstexprCallDepth != DefaultLangOpts.ConstexprCallDepth) |
| 843 | Res.push_back("-fconstexpr-depth", llvm::utostr(Opts.ConstexprCallDepth)); |
| 844 | if (!Opts.ObjCConstantStringClass.empty()) |
| 845 | Res.push_back("-fconstant-string-class", Opts.ObjCConstantStringClass); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 846 | if (Opts.FakeAddressSpaceMap) |
| 847 | Res.push_back("-ffake-address-space-map"); |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 848 | if (Opts.ParseUnknownAnytype) |
| 849 | Res.push_back("-funknown-anytype"); |
John McCall | 48218c6 | 2011-07-13 17:56:40 +0000 | [diff] [blame] | 850 | if (Opts.DebuggerSupport) |
| 851 | Res.push_back("-fdebugger-support"); |
Sean Callanan | 50a9a12 | 2012-02-04 01:29:37 +0000 | [diff] [blame] | 852 | if (Opts.DebuggerCastResultToId) |
| 853 | Res.push_back("-fdebugger-cast-result-to-id"); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 854 | if (Opts.DebuggerObjCLiteral) |
| 855 | Res.push_back("-fdebugger-objc-literal"); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 856 | if (Opts.DelayedTemplateParsing) |
| 857 | Res.push_back("-fdelayed-template-parsing"); |
Chandler Carruth | f8c247d | 2011-04-23 19:48:40 +0000 | [diff] [blame] | 858 | if (Opts.Deprecated) |
| 859 | Res.push_back("-fdeprecated-macro"); |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 860 | if (Opts.ApplePragmaPack) |
| 861 | Res.push_back("-fapple-pragma-pack"); |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 862 | if (!Opts.CurrentModule.empty()) |
| 863 | Res.push_back("-fmodule-name=" + Opts.CurrentModule); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts, |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 867 | ToArgsList &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 868 | for (unsigned i = 0, e = Opts.Macros.size(); i != e; ++i) |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 869 | Res.push_back(std::string(Opts.Macros[i].second ? "-U" : "-D") + |
| 870 | Opts.Macros[i].first); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 871 | for (unsigned i = 0, e = Opts.Includes.size(); i != e; ++i) { |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 872 | // FIXME: We need to avoid reincluding the implicit PCH and PTH includes. |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 873 | Res.push_back("-include", Opts.Includes[i]); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 874 | } |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 875 | for (unsigned i = 0, e = Opts.MacroIncludes.size(); i != e; ++i) |
| 876 | Res.push_back("-imacros", Opts.MacroIncludes[i]); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 877 | if (!Opts.UsePredefines) |
| 878 | Res.push_back("-undef"); |
Douglas Gregor | 94dc8f6 | 2010-03-19 16:15:56 +0000 | [diff] [blame] | 879 | if (Opts.DetailedRecord) |
| 880 | Res.push_back("-detailed-preprocessing-record"); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 881 | if (!Opts.ImplicitPCHInclude.empty()) |
| 882 | Res.push_back("-include-pch", Opts.ImplicitPCHInclude); |
| 883 | if (!Opts.ImplicitPTHInclude.empty()) |
| 884 | Res.push_back("-include-pth", Opts.ImplicitPTHInclude); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 885 | if (!Opts.TokenCache.empty()) { |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 886 | if (Opts.ImplicitPTHInclude.empty()) |
| 887 | Res.push_back("-token-cache", Opts.TokenCache); |
| 888 | else |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 889 | assert(Opts.ImplicitPTHInclude == Opts.TokenCache && |
| 890 | "Unsupported option combination!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 891 | } |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 892 | for (unsigned i = 0, e = Opts.ChainedIncludes.size(); i != e; ++i) |
| 893 | Res.push_back("-chain-include", Opts.ChainedIncludes[i]); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 894 | for (unsigned i = 0, e = Opts.RemappedFiles.size(); i != e; ++i) { |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 895 | Res.push_back("-remap-file", Opts.RemappedFiles[i].first + ";" + |
| 896 | Opts.RemappedFiles[i].second); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 897 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | static void PreprocessorOutputOptsToArgs(const PreprocessorOutputOptions &Opts, |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 901 | ToArgsList &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 902 | if (!Opts.ShowCPP && !Opts.ShowMacros) |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 903 | llvm::report_fatal_error("Invalid option combination!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 904 | |
| 905 | if (Opts.ShowCPP && Opts.ShowMacros) |
| 906 | Res.push_back("-dD"); |
| 907 | else if (!Opts.ShowCPP && Opts.ShowMacros) |
| 908 | Res.push_back("-dM"); |
| 909 | |
| 910 | if (!Opts.ShowLineMarkers) |
| 911 | Res.push_back("-P"); |
| 912 | if (Opts.ShowComments) |
| 913 | Res.push_back("-C"); |
| 914 | if (Opts.ShowMacroComments) |
| 915 | Res.push_back("-CC"); |
| 916 | } |
| 917 | |
| 918 | static void TargetOptsToArgs(const TargetOptions &Opts, |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 919 | ToArgsList &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 920 | Res.push_back("-triple"); |
| 921 | Res.push_back(Opts.Triple); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 922 | if (!Opts.CPU.empty()) |
| 923 | Res.push_back("-target-cpu", Opts.CPU); |
| 924 | if (!Opts.ABI.empty()) |
| 925 | Res.push_back("-target-abi", Opts.ABI); |
| 926 | if (!Opts.LinkerVersion.empty()) |
| 927 | Res.push_back("-target-linker-version", Opts.LinkerVersion); |
| 928 | if (!Opts.CXXABI.empty()) |
| 929 | Res.push_back("-cxx-abi", Opts.CXXABI); |
| 930 | for (unsigned i = 0, e = Opts.Features.size(); i != e; ++i) |
| 931 | Res.push_back("-target-feature", Opts.Features[i]); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Argyrios Kyrtzidis | 7ed25df | 2012-06-11 03:34:26 +0000 | [diff] [blame] | 934 | void CompilerInvocation::toArgs(std::vector<std::string> &Res) const { |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 935 | ToArgsList List(Res); |
Ted Kremenek | 45796b1 | 2012-08-31 04:36:05 +0000 | [diff] [blame] | 936 | AnalyzerOptsToArgs(*getAnalyzerOpts(), List); |
Benjamin Kramer | dccb9bb | 2012-03-26 15:39:31 +0000 | [diff] [blame] | 937 | CodeGenOptsToArgs(getCodeGenOpts(), List); |
| 938 | DependencyOutputOptsToArgs(getDependencyOutputOpts(), List); |
| 939 | DiagnosticOptsToArgs(getDiagnosticOpts(), List); |
| 940 | FileSystemOptsToArgs(getFileSystemOpts(), List); |
| 941 | FrontendOptsToArgs(getFrontendOpts(), List); |
| 942 | HeaderSearchOptsToArgs(getHeaderSearchOpts(), List); |
| 943 | LangOptsToArgs(*getLangOpts(), List); |
| 944 | PreprocessorOptsToArgs(getPreprocessorOpts(), List); |
| 945 | PreprocessorOutputOptsToArgs(getPreprocessorOutputOpts(), List); |
| 946 | TargetOptsToArgs(getTargetOpts(), List); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 947 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 948 | |
| 949 | //===----------------------------------------------------------------------===// |
| 950 | // Deserialization (to args) |
| 951 | //===----------------------------------------------------------------------===// |
| 952 | |
| 953 | using namespace clang::driver; |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 954 | using namespace clang::driver::options; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 955 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 956 | // |
| 957 | |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 958 | static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 959 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 61e0786 | 2010-12-04 01:50:45 +0000 | [diff] [blame] | 960 | unsigned DefaultOpt = 0; |
| 961 | if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable)) |
| 962 | DefaultOpt = 2; |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 963 | |
| 964 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
| 965 | if (A->getOption().matches(options::OPT_O0)) |
| 966 | return 0; |
| 967 | |
| 968 | assert (A->getOption().matches(options::OPT_O)); |
| 969 | |
| 970 | llvm::StringRef S(A->getValue(Args)); |
| 971 | if (S == "s" || S == "z" || S.empty()) |
| 972 | return 2; |
| 973 | |
| 974 | return Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags); |
| 975 | } |
| 976 | |
| 977 | return DefaultOpt; |
| 978 | } |
| 979 | |
| 980 | static unsigned getOptimizationLevelSize(ArgList &Args, InputKind IK, |
| 981 | DiagnosticsEngine &Diags) { |
| 982 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
| 983 | if (A->getOption().matches(options::OPT_O)) { |
| 984 | switch (A->getValue(Args)[0]) { |
| 985 | default: |
| 986 | return 0; |
| 987 | case 's': |
| 988 | return 1; |
| 989 | case 'z': |
| 990 | return 2; |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static void addWarningArgs(ArgList &Args, std::vector<std::string> &Warnings) { |
| 998 | for (arg_iterator I = Args.filtered_begin(OPT_W_Group), |
| 999 | E = Args.filtered_end(); I != E; ++I) { |
| 1000 | Arg *A = *I; |
| 1001 | // If the argument is a pure flag, add its name (minus the "-W" at the beginning) |
| 1002 | // to the warning list. Else, add its value (for the OPT_W case). |
| 1003 | if (A->getOption().getKind() == Option::FlagClass) { |
| 1004 | Warnings.push_back(A->getOption().getName().substr(2)); |
| 1005 | } else { |
| 1006 | for (unsigned Idx = 0, End = A->getNumValues(); |
| 1007 | Idx < End; ++Idx) { |
| 1008 | StringRef V = A->getValue(Args, Idx); |
| 1009 | // "-Wl," and such are not warning options. |
| 1010 | // FIXME: Should be handled by putting these in separate flags. |
| 1011 | if (V.startswith("l,") || V.startswith("a,") || V.startswith("p,")) |
| 1012 | continue; |
| 1013 | |
| 1014 | Warnings.push_back(V); |
| 1015 | } |
| 1016 | } |
| 1017 | } |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1020 | static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1021 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1022 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1023 | bool Success = true; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1024 | if (Arg *A = Args.getLastArg(OPT_analyzer_store)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1025 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1026 | AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name) |
| 1027 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \ |
| 1028 | .Case(CMDFLAG, NAME##Model) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 1029 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1030 | .Default(NumStores); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1031 | if (Value == NumStores) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1032 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 1033 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1034 | Success = false; |
| 1035 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1036 | Opts.AnalysisStoreOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1037 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1041 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1042 | AnalysisConstraints Value = llvm::StringSwitch<AnalysisConstraints>(Name) |
| 1043 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \ |
| 1044 | .Case(CMDFLAG, NAME##Model) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 1045 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1046 | .Default(NumConstraints); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1047 | if (Value == NumConstraints) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1048 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 1049 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1050 | Success = false; |
| 1051 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1052 | Opts.AnalysisConstraintsOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1053 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | if (Arg *A = Args.getLastArg(OPT_analyzer_output)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1057 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1058 | AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name) |
| 1059 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) \ |
| 1060 | .Case(CMDFLAG, PD_##NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 1061 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1062 | .Default(NUM_ANALYSIS_DIAG_CLIENTS); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1063 | if (Value == NUM_ANALYSIS_DIAG_CLIENTS) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1064 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 1065 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1066 | Success = false; |
| 1067 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1068 | Opts.AnalysisDiagOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1069 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 1072 | if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) { |
| 1073 | StringRef Name = A->getValue(Args); |
| 1074 | AnalysisPurgeMode Value = llvm::StringSwitch<AnalysisPurgeMode>(Name) |
| 1075 | #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \ |
| 1076 | .Case(CMDFLAG, NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 1077 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 1078 | .Default(NumPurgeModes); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1079 | if (Value == NumPurgeModes) { |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 1080 | Diags.Report(diag::err_drv_invalid_value) |
| 1081 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1082 | Success = false; |
| 1083 | } else { |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 1084 | Opts.AnalysisPurgeOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1085 | } |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 1088 | if (Arg *A = Args.getLastArg(OPT_analyzer_ipa)) { |
| 1089 | StringRef Name = A->getValue(Args); |
| 1090 | AnalysisIPAMode Value = llvm::StringSwitch<AnalysisIPAMode>(Name) |
| 1091 | #define ANALYSIS_IPA(NAME, CMDFLAG, DESC) \ |
| 1092 | .Case(CMDFLAG, NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 1093 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 1094 | .Default(NumIPAModes); |
| 1095 | if (Value == NumIPAModes) { |
| 1096 | Diags.Report(diag::err_drv_invalid_value) |
| 1097 | << A->getAsString(Args) << Name; |
| 1098 | Success = false; |
| 1099 | } else { |
| 1100 | Opts.IPAMode = Value; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | if (Arg *A = Args.getLastArg(OPT_analyzer_inlining_mode)) { |
| 1105 | StringRef Name = A->getValue(Args); |
| 1106 | AnalysisInliningMode Value = llvm::StringSwitch<AnalysisInliningMode>(Name) |
| 1107 | #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) \ |
| 1108 | .Case(CMDFLAG, NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 1109 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 1110 | .Default(NumInliningModes); |
| 1111 | if (Value == NumInliningModes) { |
| 1112 | Diags.Report(diag::err_drv_invalid_value) |
| 1113 | << A->getAsString(Args) << Name; |
| 1114 | Success = false; |
| 1115 | } else { |
| 1116 | Opts.InliningMode = Value; |
| 1117 | } |
| 1118 | } |
| 1119 | |
Argyrios Kyrtzidis | 116f364 | 2011-02-25 00:09:51 +0000 | [diff] [blame] | 1120 | Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help); |
Ted Kremenek | 3b8a040 | 2012-08-30 19:26:53 +0000 | [diff] [blame] | 1121 | Opts.visualizeExplodedGraphWithGraphViz = |
| 1122 | Args.hasArg(OPT_analyzer_viz_egraph_graphviz); |
| 1123 | Opts.visualizeExplodedGraphWithUbiGraph = |
| 1124 | Args.hasArg(OPT_analyzer_viz_egraph_ubigraph); |
Anna Zaks | b47dbcb | 2012-03-28 19:59:16 +0000 | [diff] [blame] | 1125 | Opts.NoRetryExhausted = Args.hasArg(OPT_analyzer_disable_retry_exhausted); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1126 | Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers); |
| 1127 | Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress); |
Ted Kremenek | fc57651 | 2009-12-07 22:06:12 +0000 | [diff] [blame] | 1128 | Opts.AnalyzeNestedBlocks = |
| 1129 | Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks); |
Ted Kremenek | 0caa2d4 | 2012-08-30 19:26:48 +0000 | [diff] [blame] | 1130 | Opts.eagerlyAssumeBinOpBifurcation = Args.hasArg(OPT_analyzer_eagerly_assume); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1131 | Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function); |
Ted Kremenek | 9b823e8 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 1132 | Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1133 | Opts.TrimGraph = Args.hasArg(OPT_trim_egraph); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1134 | Opts.MaxNodes = Args.getLastArgIntValue(OPT_analyzer_max_nodes, 150000,Diags); |
Ted Kremenek | 2fa9d72 | 2012-08-30 19:26:56 +0000 | [diff] [blame] | 1135 | Opts.maxBlockVisitOnPath = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags); |
Ted Kremenek | 255d4d4 | 2012-08-30 19:26:43 +0000 | [diff] [blame] | 1136 | Opts.eagerlyTrimExplodedGraph = !Args.hasArg(OPT_analyzer_no_eagerly_trim_egraph); |
Anna Zaks | 81fb169 | 2012-02-27 21:33:16 +0000 | [diff] [blame] | 1137 | Opts.PrintStats = Args.hasArg(OPT_analyzer_stats); |
Anna Zaks | 8235f9c | 2012-03-02 19:05:03 +0000 | [diff] [blame] | 1138 | Opts.InlineMaxStackDepth = |
| 1139 | Args.getLastArgIntValue(OPT_analyzer_inline_max_stack_depth, |
| 1140 | Opts.InlineMaxStackDepth, Diags); |
| 1141 | Opts.InlineMaxFunctionSize = |
| 1142 | Args.getLastArgIntValue(OPT_analyzer_inline_max_function_size, |
| 1143 | Opts.InlineMaxFunctionSize, Diags); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 1144 | |
| 1145 | Opts.CheckersControlList.clear(); |
| 1146 | for (arg_iterator it = Args.filtered_begin(OPT_analyzer_checker, |
| 1147 | OPT_analyzer_disable_checker), |
| 1148 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1149 | const Arg *A = *it; |
| 1150 | A->claim(); |
| 1151 | bool enable = (A->getOption().getID() == OPT_analyzer_checker); |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 1152 | // We can have a list of comma separated checker names, e.g: |
| 1153 | // '-analyzer-checker=cocoa,unix' |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1154 | StringRef checkerList = A->getValue(Args); |
| 1155 | SmallVector<StringRef, 4> checkers; |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 1156 | checkerList.split(checkers, ","); |
| 1157 | for (unsigned i = 0, e = checkers.size(); i != e; ++i) |
| 1158 | Opts.CheckersControlList.push_back(std::make_pair(checkers[i], enable)); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 1159 | } |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 1160 | |
| 1161 | // Go through the analyzer configuration options. |
| 1162 | for (arg_iterator it = Args.filtered_begin(OPT_analyzer_config), |
| 1163 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1164 | const Arg *A = *it; |
| 1165 | A->claim(); |
| 1166 | // We can have a list of comma separated config names, e.g: |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 1167 | // '-analyzer-config key1=val1,key2=val2' |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 1168 | StringRef configList = A->getValue(Args); |
| 1169 | SmallVector<StringRef, 4> configVals; |
| 1170 | configList.split(configVals, ","); |
| 1171 | for (unsigned i = 0, e = configVals.size(); i != e; ++i) { |
| 1172 | StringRef key, val; |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 1173 | llvm::tie(key, val) = configVals[i].split("="); |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 1174 | if (val.empty()) { |
| 1175 | Diags.Report(SourceLocation(), |
| 1176 | diag::err_analyzer_config_no_value) << configVals[i]; |
| 1177 | Success = false; |
| 1178 | break; |
| 1179 | } |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 1180 | if (val.find('=') != StringRef::npos) { |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 1181 | Diags.Report(SourceLocation(), |
| 1182 | diag::err_analyzer_config_multiple_values) |
| 1183 | << configVals[i]; |
| 1184 | Success = false; |
| 1185 | break; |
| 1186 | } |
| 1187 | Opts.Config[key] = val; |
| 1188 | } |
| 1189 | } |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1190 | |
| 1191 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 1194 | static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) { |
| 1195 | Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error); |
Fariborz Jahanian | bbdfad5 | 2012-01-26 20:57:58 +0000 | [diff] [blame] | 1196 | Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal); |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 1197 | return true; |
| 1198 | } |
| 1199 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1200 | static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1201 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1202 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1203 | bool Success = true; |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1204 | |
Aaron Ballman | e6cc51d | 2012-02-06 00:40:31 +0000 | [diff] [blame] | 1205 | unsigned OptLevel = getOptimizationLevel(Args, IK, Diags); |
| 1206 | if (OptLevel > 3) { |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1207 | Diags.Report(diag::err_drv_invalid_value) |
Aaron Ballman | e6cc51d | 2012-02-06 00:40:31 +0000 | [diff] [blame] | 1208 | << Args.getLastArg(OPT_O)->getAsString(Args) << OptLevel; |
| 1209 | OptLevel = 3; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1210 | Success = false; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1211 | } |
Aaron Ballman | e6cc51d | 2012-02-06 00:40:31 +0000 | [diff] [blame] | 1212 | Opts.OptimizationLevel = OptLevel; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1213 | |
| 1214 | // We must always run at least the always inlining pass. |
| 1215 | Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining |
| 1216 | : CodeGenOptions::OnlyAlwaysInlining; |
Chad Rosier | 634a4b1 | 2012-03-06 21:17:19 +0000 | [diff] [blame] | 1217 | // -fno-inline-functions overrides OptimizationLevel > 1. |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 1218 | Opts.NoInline = Args.hasArg(OPT_fno_inline); |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 1219 | Opts.Inlining = Args.hasArg(OPT_fno_inline_functions) ? |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 1220 | CodeGenOptions::OnlyAlwaysInlining : Opts.Inlining; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1221 | |
Alexey Samsonov | fd00eec | 2012-05-04 07:39:27 +0000 | [diff] [blame] | 1222 | if (Args.hasArg(OPT_gline_tables_only)) { |
| 1223 | Opts.DebugInfo = CodeGenOptions::DebugLineTablesOnly; |
| 1224 | } else if (Args.hasArg(OPT_g_Flag)) { |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 1225 | if (Args.hasFlag(OPT_flimit_debug_info, OPT_fno_limit_debug_info, true)) |
| 1226 | Opts.DebugInfo = CodeGenOptions::LimitedDebugInfo; |
| 1227 | else |
| 1228 | Opts.DebugInfo = CodeGenOptions::FullDebugInfo; |
| 1229 | } |
| 1230 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1231 | Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); |
| 1232 | Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 1233 | Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); |
Daniel Dunbar | e26bdb9 | 2011-06-21 18:54:46 +0000 | [diff] [blame] | 1234 | Opts.UseRegisterSizedBitfieldAccess = Args.hasArg( |
| 1235 | OPT_fuse_register_sized_bitfield_access); |
Dan Gohman | 4d5625e | 2010-10-14 22:36:56 +0000 | [diff] [blame] | 1236 | Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1237 | Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1238 | Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants); |
| 1239 | Opts.NoCommon = Args.hasArg(OPT_fno_common); |
| 1240 | Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1241 | Opts.OptimizeSize = getOptimizationLevelSize(Args, IK, Diags); |
Daniel Dunbar | 6b0cf67 | 2010-06-07 23:19:17 +0000 | [diff] [blame] | 1242 | Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) || |
| 1243 | Args.hasArg(OPT_ffreestanding)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1244 | Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) || |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 1245 | (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1246 | |
| 1247 | Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1248 | Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); |
Peter Collingbourne | d51e43a | 2011-10-06 18:29:46 +0000 | [diff] [blame] | 1249 | Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device); |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1250 | Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit); |
| 1251 | Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1252 | Opts.CodeModel = Args.getLastArgValue(OPT_mcode_model); |
| 1253 | Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1254 | Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim); |
Nick Lewycky | 1db772b | 2012-01-23 08:29:12 +0000 | [diff] [blame] | 1255 | Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1256 | Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); |
John McCall | 279b5eb | 2010-08-12 23:36:15 +0000 | [diff] [blame] | 1257 | Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables); |
Peter Collingbourne | 4400cb8 | 2010-12-04 01:51:33 +0000 | [diff] [blame] | 1258 | Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1259 | Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); |
Daniel Dunbar | 001f628 | 2011-12-09 23:41:18 +0000 | [diff] [blame] | 1260 | Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) || |
| 1261 | Args.hasArg(OPT_cl_finite_math_only)|| |
| 1262 | Args.hasArg(OPT_cl_fast_relaxed_math)); |
| 1263 | Opts.NoNaNsFPMath = (Args.hasArg(OPT_menable_no_nans) || |
| 1264 | Args.hasArg(OPT_cl_finite_math_only)|| |
| 1265 | Args.hasArg(OPT_cl_fast_relaxed_math)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1266 | Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 1267 | Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option); |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 1268 | Opts.NumRegisterParameters = Args.getLastArgIntValue(OPT_mregparm, 0, Diags); |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 1269 | Opts.NoGlobalMerge = Args.hasArg(OPT_mno_global_merge); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 1270 | Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); |
Daniel Dunbar | 4ecc9b7 | 2010-05-27 05:39:39 +0000 | [diff] [blame] | 1271 | Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 1272 | Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 1273 | Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); |
Rafael Espindola | f24a151 | 2011-04-30 18:35:43 +0000 | [diff] [blame] | 1274 | Opts.NoDwarf2CFIAsm = Args.hasArg(OPT_fno_dwarf2_cfi_asm); |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 1275 | Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1276 | Opts.SoftFloat = Args.hasArg(OPT_msoft_float); |
Chandler Carruth | 82fe6ae | 2012-03-27 23:58:37 +0000 | [diff] [blame] | 1277 | Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1278 | Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) || |
| 1279 | Args.hasArg(OPT_cl_unsafe_math_optimizations) || |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 1280 | Args.hasArg(OPT_cl_fast_relaxed_math); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1281 | Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1282 | Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); |
Bob Wilson | 71fd6cc | 2012-02-03 06:27:22 +0000 | [diff] [blame] | 1283 | Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ); |
Nuno Lopes | def1849 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 1284 | Opts.BoundsChecking = Args.getLastArgIntValue(OPT_fbounds_checking_EQ, 0, |
| 1285 | Diags); |
Rafael Espindola | 8af669f | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 1286 | Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1287 | |
Chris Lattner | bbea716 | 2010-04-13 00:38:24 +0000 | [diff] [blame] | 1288 | Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections); |
| 1289 | Opts.DataSections = Args.hasArg(OPT_fdata_sections); |
| 1290 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1291 | Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); |
John McCall | 824e19e | 2010-02-12 23:47:27 +0000 | [diff] [blame] | 1292 | Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1293 | |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 1294 | Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 1295 | Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 1296 | Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); |
| 1297 | Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); |
Tanya Lattner | 198871c | 2012-07-11 23:02:10 +0000 | [diff] [blame] | 1298 | Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); |
Nick Lewycky | 3dc0541 | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 1299 | Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 1300 | Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); |
Peter Collingbourne | 22a7dfe | 2011-10-30 17:30:44 +0000 | [diff] [blame] | 1301 | Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file); |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 1302 | Opts.SSPBufferSize = |
| 1303 | Args.getLastArgIntValue(OPT_stack_protector_buffer_size, 8, Diags); |
Nick Lewycky | 4e785c9 | 2011-12-06 03:33:03 +0000 | [diff] [blame] | 1304 | Opts.StackRealignment = Args.hasArg(OPT_mstackrealign); |
Joerg Sonnenberger | e9d11db | 2011-12-05 23:05:23 +0000 | [diff] [blame] | 1305 | if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) { |
| 1306 | StringRef Val = A->getValue(Args); |
| 1307 | Val.getAsInteger(10, Opts.StackAlignment); |
| 1308 | } |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 1309 | |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1310 | if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1311 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1312 | unsigned Method = llvm::StringSwitch<unsigned>(Name) |
| 1313 | .Case("legacy", CodeGenOptions::Legacy) |
| 1314 | .Case("non-legacy", CodeGenOptions::NonLegacy) |
| 1315 | .Case("mixed", CodeGenOptions::Mixed) |
| 1316 | .Default(~0U); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1317 | if (Method == ~0U) { |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1318 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1319 | Success = false; |
| 1320 | } else { |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1321 | Opts.ObjCDispatchMethod = Method; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1322 | } |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1323 | } |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1324 | |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 1325 | if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) { |
| 1326 | StringRef Name = A->getValue(Args); |
| 1327 | unsigned Model = llvm::StringSwitch<unsigned>(Name) |
| 1328 | .Case("global-dynamic", CodeGenOptions::GeneralDynamicTLSModel) |
| 1329 | .Case("local-dynamic", CodeGenOptions::LocalDynamicTLSModel) |
| 1330 | .Case("initial-exec", CodeGenOptions::InitialExecTLSModel) |
| 1331 | .Case("local-exec", CodeGenOptions::LocalExecTLSModel) |
| 1332 | .Default(~0U); |
| 1333 | if (Model == ~0U) { |
| 1334 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 1335 | Success = false; |
| 1336 | } else { |
| 1337 | Opts.DefaultTLSModel = static_cast<CodeGenOptions::TLSModel>(Model); |
| 1338 | } |
| 1339 | } |
| 1340 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1341 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, |
| 1345 | ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1346 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1347 | Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file); |
| 1348 | Opts.Targets = Args.getAllArgValues(OPT_MT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1349 | Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps); |
| 1350 | Opts.UsePhonyTargets = Args.hasArg(OPT_MP); |
Daniel Dunbar | eef63e0 | 2011-02-02 15:41:17 +0000 | [diff] [blame] | 1351 | Opts.ShowHeaderIncludes = Args.hasArg(OPT_H); |
Daniel Dunbar | b34d69b | 2011-02-02 21:11:31 +0000 | [diff] [blame] | 1352 | Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file); |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 1353 | Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG); |
Douglas Gregor | 773303a | 2012-02-02 23:45:13 +0000 | [diff] [blame] | 1354 | Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 1357 | bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, |
| 1358 | DiagnosticsEngine *Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1359 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1360 | bool Success = true; |
| 1361 | |
Daniel Dunbar | 08c6695 | 2011-04-07 18:11:14 +0000 | [diff] [blame] | 1362 | Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file); |
Ted Kremenek | 7800212 | 2011-10-29 00:12:39 +0000 | [diff] [blame] | 1363 | Opts.DiagnosticSerializationFile = |
| 1364 | Args.getLastArgValue(OPT_diagnostic_serialized_file); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1365 | Opts.IgnoreWarnings = Args.hasArg(OPT_w); |
| 1366 | Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros); |
| 1367 | Opts.Pedantic = Args.hasArg(OPT_pedantic); |
| 1368 | Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors); |
| 1369 | Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics); |
| 1370 | Opts.ShowColors = Args.hasArg(OPT_fcolor_diagnostics); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1371 | Opts.ShowColumn = Args.hasFlag(OPT_fshow_column, |
| 1372 | OPT_fno_show_column, |
| 1373 | /*Default=*/true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1374 | Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); |
| 1375 | Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); |
| 1376 | Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1377 | |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 1378 | // Default behavior is to not to show note include stacks. |
| 1379 | Opts.ShowNoteIncludeStack = false; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 1380 | if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack, |
| 1381 | OPT_fno_diagnostics_show_note_include_stack)) |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 1382 | if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack)) |
| 1383 | Opts.ShowNoteIncludeStack = true; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 1384 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1385 | StringRef ShowOverloads = |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1386 | Args.getLastArgValue(OPT_fshow_overloads_EQ, "all"); |
| 1387 | if (ShowOverloads == "best") |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1388 | Opts.ShowOverloads = DiagnosticsEngine::Ovl_Best; |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1389 | else if (ShowOverloads == "all") |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1390 | Opts.ShowOverloads = DiagnosticsEngine::Ovl_All; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1391 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 1392 | Success = false; |
| 1393 | if (Diags) |
| 1394 | Diags->Report(diag::err_drv_invalid_value) |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1395 | << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args) |
| 1396 | << ShowOverloads; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1397 | } |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1398 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1399 | StringRef ShowCategory = |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1400 | Args.getLastArgValue(OPT_fdiagnostics_show_category, "none"); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 1401 | if (ShowCategory == "none") |
| 1402 | Opts.ShowCategories = 0; |
| 1403 | else if (ShowCategory == "id") |
| 1404 | Opts.ShowCategories = 1; |
| 1405 | else if (ShowCategory == "name") |
| 1406 | Opts.ShowCategories = 2; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1407 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 1408 | Success = false; |
| 1409 | if (Diags) |
| 1410 | Diags->Report(diag::err_drv_invalid_value) |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 1411 | << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) |
| 1412 | << ShowCategory; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1413 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1414 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1415 | StringRef Format = |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1416 | Args.getLastArgValue(OPT_fdiagnostics_format, "clang"); |
| 1417 | if (Format == "clang") |
| 1418 | Opts.Format = DiagnosticOptions::Clang; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1419 | else if (Format == "msvc") |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1420 | Opts.Format = DiagnosticOptions::Msvc; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1421 | else if (Format == "vi") |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1422 | Opts.Format = DiagnosticOptions::Vi; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1423 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 1424 | Success = false; |
| 1425 | if (Diags) |
| 1426 | Diags->Report(diag::err_drv_invalid_value) |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1427 | << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) |
| 1428 | << Format; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1429 | } |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1430 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1431 | Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 1432 | Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1433 | Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); |
Richard Trieu | 246b6aa | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 1434 | Opts.ElideType = !Args.hasArg(OPT_fno_elide_type); |
| 1435 | Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1436 | Opts.ErrorLimit = Args.getLastArgIntValue(OPT_ferror_limit, 0, Diags); |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 1437 | Opts.MacroBacktraceLimit |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1438 | = Args.getLastArgIntValue(OPT_fmacro_backtrace_limit, |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 1439 | DiagnosticOptions::DefaultMacroBacktraceLimit, Diags); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 1440 | Opts.TemplateBacktraceLimit |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1441 | = Args.getLastArgIntValue(OPT_ftemplate_backtrace_limit, |
| 1442 | DiagnosticOptions::DefaultTemplateBacktraceLimit, |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 1443 | Diags); |
Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 1444 | Opts.ConstexprBacktraceLimit |
| 1445 | = Args.getLastArgIntValue(OPT_fconstexpr_backtrace_limit, |
| 1446 | DiagnosticOptions::DefaultConstexprBacktraceLimit, |
| 1447 | Diags); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1448 | Opts.TabStop = Args.getLastArgIntValue(OPT_ftabstop, |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 1449 | DiagnosticOptions::DefaultTabStop, Diags); |
| 1450 | if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) { |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 1451 | Opts.TabStop = DiagnosticOptions::DefaultTabStop; |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 1452 | if (Diags) |
| 1453 | Diags->Report(diag::warn_ignoring_ftabstop_value) |
| 1454 | << Opts.TabStop << DiagnosticOptions::DefaultTabStop; |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 1455 | } |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1456 | Opts.MessageLength = Args.getLastArgIntValue(OPT_fmessage_length, 0, Diags); |
| 1457 | Opts.DumpBuildInformation = Args.getLastArgValue(OPT_dump_build_information); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1458 | addWarningArgs(Args, Opts.Warnings); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1459 | |
| 1460 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1463 | static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) { |
| 1464 | Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory); |
| 1465 | } |
| 1466 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1467 | static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1468 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1469 | using namespace options; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1470 | Opts.ProgramAction = frontend::ParseSyntaxOnly; |
| 1471 | if (const Arg *A = Args.getLastArg(OPT_Action_Group)) { |
| 1472 | switch (A->getOption().getID()) { |
| 1473 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1474 | llvm_unreachable("Invalid option in group!"); |
Alexander Kornienko | 171af64 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 1475 | case OPT_ast_list: |
| 1476 | Opts.ProgramAction = frontend::ASTDeclList; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1477 | case OPT_ast_dump: |
| 1478 | Opts.ProgramAction = frontend::ASTDump; break; |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 1479 | case OPT_ast_dump_xml: |
| 1480 | Opts.ProgramAction = frontend::ASTDumpXML; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1481 | case OPT_ast_print: |
| 1482 | Opts.ProgramAction = frontend::ASTPrint; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1483 | case OPT_ast_view: |
| 1484 | Opts.ProgramAction = frontend::ASTView; break; |
| 1485 | case OPT_dump_raw_tokens: |
| 1486 | Opts.ProgramAction = frontend::DumpRawTokens; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1487 | case OPT_dump_tokens: |
| 1488 | Opts.ProgramAction = frontend::DumpTokens; break; |
| 1489 | case OPT_S: |
| 1490 | Opts.ProgramAction = frontend::EmitAssembly; break; |
| 1491 | case OPT_emit_llvm_bc: |
| 1492 | Opts.ProgramAction = frontend::EmitBC; break; |
| 1493 | case OPT_emit_html: |
| 1494 | Opts.ProgramAction = frontend::EmitHTML; break; |
| 1495 | case OPT_emit_llvm: |
| 1496 | Opts.ProgramAction = frontend::EmitLLVM; break; |
| 1497 | case OPT_emit_llvm_only: |
| 1498 | Opts.ProgramAction = frontend::EmitLLVMOnly; break; |
Daniel Dunbar | 32148ce | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 1499 | case OPT_emit_codegen_only: |
| 1500 | Opts.ProgramAction = frontend::EmitCodeGenOnly; break; |
Daniel Dunbar | da1573f | 2010-02-03 01:18:43 +0000 | [diff] [blame] | 1501 | case OPT_emit_obj: |
| 1502 | Opts.ProgramAction = frontend::EmitObj; break; |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 1503 | case OPT_fixit_EQ: |
| 1504 | Opts.FixItSuffix = A->getValue(Args); |
| 1505 | // fall-through! |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1506 | case OPT_fixit: |
| 1507 | Opts.ProgramAction = frontend::FixIt; break; |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 1508 | case OPT_emit_module: |
| 1509 | Opts.ProgramAction = frontend::GenerateModule; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1510 | case OPT_emit_pch: |
| 1511 | Opts.ProgramAction = frontend::GeneratePCH; break; |
| 1512 | case OPT_emit_pth: |
| 1513 | Opts.ProgramAction = frontend::GeneratePTH; break; |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 1514 | case OPT_init_only: |
| 1515 | Opts.ProgramAction = frontend::InitOnly; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1516 | case OPT_fsyntax_only: |
| 1517 | Opts.ProgramAction = frontend::ParseSyntaxOnly; break; |
| 1518 | case OPT_print_decl_contexts: |
| 1519 | Opts.ProgramAction = frontend::PrintDeclContext; break; |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 1520 | case OPT_print_preamble: |
| 1521 | Opts.ProgramAction = frontend::PrintPreamble; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1522 | case OPT_E: |
| 1523 | Opts.ProgramAction = frontend::PrintPreprocessedInput; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1524 | case OPT_rewrite_macros: |
| 1525 | Opts.ProgramAction = frontend::RewriteMacros; break; |
| 1526 | case OPT_rewrite_objc: |
| 1527 | Opts.ProgramAction = frontend::RewriteObjC; break; |
| 1528 | case OPT_rewrite_test: |
| 1529 | Opts.ProgramAction = frontend::RewriteTest; break; |
| 1530 | case OPT_analyze: |
| 1531 | Opts.ProgramAction = frontend::RunAnalysis; break; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1532 | case OPT_migrate: |
| 1533 | Opts.ProgramAction = frontend::MigrateSource; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1534 | case OPT_Eonly: |
| 1535 | Opts.ProgramAction = frontend::RunPreprocessorOnly; break; |
| 1536 | } |
| 1537 | } |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 1538 | |
| 1539 | if (const Arg* A = Args.getLastArg(OPT_plugin)) { |
| 1540 | Opts.Plugins.push_back(A->getValue(Args,0)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1541 | Opts.ProgramAction = frontend::PluginAction; |
| 1542 | Opts.ActionName = A->getValue(Args); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 1543 | |
| 1544 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 1545 | end = Args.filtered_end(); it != end; ++it) { |
| 1546 | if ((*it)->getValue(Args, 0) == Opts.ActionName) |
| 1547 | Opts.PluginArgs.push_back((*it)->getValue(Args, 1)); |
| 1548 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 1551 | Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 1552 | Opts.AddPluginArgs.resize(Opts.AddPluginActions.size()); |
| 1553 | for (int i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) { |
| 1554 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 1555 | end = Args.filtered_end(); it != end; ++it) { |
| 1556 | if ((*it)->getValue(Args, 0) == Opts.AddPluginActions[i]) |
| 1557 | Opts.AddPluginArgs[i].push_back((*it)->getValue(Args, 1)); |
| 1558 | } |
| 1559 | } |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 1560 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1561 | if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) { |
| 1562 | Opts.CodeCompletionAt = |
| 1563 | ParsedSourceLocation::FromString(A->getValue(Args)); |
| 1564 | if (Opts.CodeCompletionAt.FileName.empty()) |
| 1565 | Diags.Report(diag::err_drv_invalid_value) |
| 1566 | << A->getAsString(Args) << A->getValue(Args); |
| 1567 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1568 | Opts.DisableFree = Args.hasArg(OPT_disable_free); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1569 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1570 | Opts.OutputFile = Args.getLastArgValue(OPT_o); |
| 1571 | Opts.Plugins = Args.getAllArgValues(OPT_load); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1572 | Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 1573 | Opts.ShowHelp = Args.hasArg(OPT_help); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1574 | Opts.ShowStats = Args.hasArg(OPT_print_stats); |
| 1575 | Opts.ShowTimers = Args.hasArg(OPT_ftime_report); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 1576 | Opts.ShowVersion = Args.hasArg(OPT_version); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1577 | Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge); |
| 1578 | Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); |
Nick Lewycky | 1450f26 | 2010-08-13 17:31:00 +0000 | [diff] [blame] | 1579 | Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can); |
Argyrios Kyrtzidis | 61d679a | 2012-01-26 02:40:48 +0000 | [diff] [blame] | 1580 | Opts.FixOnlyWarnings = Args.hasArg(OPT_fix_only_warnings); |
| 1581 | Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile); |
| 1582 | Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp); |
Alexander Kornienko | e34a052 | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 1583 | Opts.ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter); |
Dmitri Gribenko | d99ef53 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 1584 | |
| 1585 | Opts.CodeCompleteOpts.IncludeMacros |
| 1586 | = Args.hasArg(OPT_code_completion_macros); |
| 1587 | Opts.CodeCompleteOpts.IncludeCodePatterns |
| 1588 | = Args.hasArg(OPT_code_completion_patterns); |
| 1589 | Opts.CodeCompleteOpts.IncludeGlobals |
| 1590 | = !Args.hasArg(OPT_no_code_completion_globals); |
| 1591 | Opts.CodeCompleteOpts.IncludeBriefComments |
| 1592 | = Args.hasArg(OPT_code_completion_brief_comments); |
| 1593 | |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 1594 | Opts.OverrideRecordLayoutsFile |
| 1595 | = Args.getLastArgValue(OPT_foverride_record_layout_EQ); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1596 | if (const Arg *A = Args.getLastArg(OPT_arcmt_check, |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 1597 | OPT_arcmt_modify, |
| 1598 | OPT_arcmt_migrate)) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1599 | switch (A->getOption().getID()) { |
| 1600 | default: |
| 1601 | llvm_unreachable("missed a case"); |
| 1602 | case OPT_arcmt_check: |
| 1603 | Opts.ARCMTAction = FrontendOptions::ARCMT_Check; |
| 1604 | break; |
| 1605 | case OPT_arcmt_modify: |
| 1606 | Opts.ARCMTAction = FrontendOptions::ARCMT_Modify; |
| 1607 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 1608 | case OPT_arcmt_migrate: |
| 1609 | Opts.ARCMTAction = FrontendOptions::ARCMT_Migrate; |
| 1610 | break; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1611 | } |
| 1612 | } |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1613 | Opts.MTMigrateDir = Args.getLastArgValue(OPT_mt_migrate_directory); |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 1614 | Opts.ARCMTMigrateReportOut |
| 1615 | = Args.getLastArgValue(OPT_arcmt_migrate_report_output); |
| 1616 | Opts.ARCMTMigrateEmitARCErrors |
| 1617 | = Args.hasArg(OPT_arcmt_migrate_emit_arc_errors); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1618 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1619 | if (Args.hasArg(OPT_objcmt_migrate_literals)) |
| 1620 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Literals; |
| 1621 | if (Args.hasArg(OPT_objcmt_migrate_subscripting)) |
| 1622 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Subscripting; |
| 1623 | |
| 1624 | if (Opts.ARCMTAction != FrontendOptions::ARCMT_None && |
| 1625 | Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) { |
| 1626 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1627 | << "ARC migration" << "ObjC migration"; |
| 1628 | } |
| 1629 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1630 | InputKind DashX = IK_None; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1631 | if (const Arg *A = Args.getLastArg(OPT_x)) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1632 | DashX = llvm::StringSwitch<InputKind>(A->getValue(Args)) |
| 1633 | .Case("c", IK_C) |
| 1634 | .Case("cl", IK_OpenCL) |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1635 | .Case("cuda", IK_CUDA) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1636 | .Case("c++", IK_CXX) |
| 1637 | .Case("objective-c", IK_ObjC) |
| 1638 | .Case("objective-c++", IK_ObjCXX) |
| 1639 | .Case("cpp-output", IK_PreprocessedC) |
| 1640 | .Case("assembler-with-cpp", IK_Asm) |
| 1641 | .Case("c++-cpp-output", IK_PreprocessedCXX) |
| 1642 | .Case("objective-c-cpp-output", IK_PreprocessedObjC) |
Chris Lattner | 919f2ca | 2011-04-09 07:09:31 +0000 | [diff] [blame] | 1643 | .Case("objc-cpp-output", IK_PreprocessedObjC) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1644 | .Case("objective-c++-cpp-output", IK_PreprocessedObjCXX) |
Nico Weber | 1f7957d | 2011-08-13 19:03:50 +0000 | [diff] [blame] | 1645 | .Case("objc++-cpp-output", IK_PreprocessedObjCXX) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1646 | .Case("c-header", IK_C) |
Peter Collingbourne | ae57ead | 2011-10-09 22:03:19 +0000 | [diff] [blame] | 1647 | .Case("cl-header", IK_OpenCL) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1648 | .Case("objective-c-header", IK_ObjC) |
| 1649 | .Case("c++-header", IK_CXX) |
| 1650 | .Case("objective-c++-header", IK_ObjCXX) |
| 1651 | .Case("ast", IK_AST) |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 1652 | .Case("ir", IK_LLVM_IR) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1653 | .Default(IK_None); |
| 1654 | if (DashX == IK_None) |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1655 | Diags.Report(diag::err_drv_invalid_value) |
| 1656 | << A->getAsString(Args) << A->getValue(Args); |
| 1657 | } |
| 1658 | |
| 1659 | // '-' is the default input if none is given. |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1660 | std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1661 | Opts.Inputs.clear(); |
| 1662 | if (Inputs.empty()) |
| 1663 | Inputs.push_back("-"); |
| 1664 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1665 | InputKind IK = DashX; |
| 1666 | if (IK == IK_None) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1667 | IK = FrontendOptions::getInputKindForExtension( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1668 | StringRef(Inputs[i]).rsplit('.').second); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1669 | // FIXME: Remove this hack. |
| 1670 | if (i == 0) |
| 1671 | DashX = IK; |
| 1672 | } |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 1673 | Opts.Inputs.push_back(FrontendInputFile(Inputs[i], IK)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | return DashX; |
| 1677 | } |
| 1678 | |
Daniel Dunbar | 8b9adfe | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 1679 | std::string CompilerInvocation::GetResourcesPath(const char *Argv0, |
| 1680 | void *MainAddr) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1681 | llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); |
| 1682 | |
| 1683 | if (!P.isEmpty()) { |
| 1684 | P.eraseComponent(); // Remove /clang from foo/bin/clang |
| 1685 | P.eraseComponent(); // Remove /bin from foo/bin |
| 1686 | |
| 1687 | // Get foo/lib/clang/<version>/include |
| 1688 | P.appendComponent("lib"); |
| 1689 | P.appendComponent("clang"); |
| 1690 | P.appendComponent(CLANG_VERSION_STRING); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | return P.str(); |
| 1694 | } |
| 1695 | |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 1696 | static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1697 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1698 | Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1699 | Opts.Verbose = Args.hasArg(OPT_v); |
Francois Pichet | c91562c | 2011-10-10 20:34:10 +0000 | [diff] [blame] | 1700 | Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 1701 | Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 1702 | Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx); |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 1703 | if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ)) |
| 1704 | Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1705 | Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir); |
Douglas Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 1706 | Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodule_cache_path); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1707 | Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash); |
Douglas Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 1708 | |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 1709 | // Add -I..., -F..., and -index-header-map options in order. |
| 1710 | bool IsIndexHeaderMap = false; |
| 1711 | for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F, |
| 1712 | OPT_index_header_map), |
| 1713 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1714 | if ((*it)->getOption().matches(OPT_index_header_map)) { |
| 1715 | // -index-header-map applies to the next -I or -F. |
| 1716 | IsIndexHeaderMap = true; |
| 1717 | continue; |
| 1718 | } |
| 1719 | |
| 1720 | frontend::IncludeDirGroup Group |
| 1721 | = IsIndexHeaderMap? frontend::IndexHeaderMap : frontend::Angled; |
| 1722 | |
| 1723 | Opts.AddPath((*it)->getValue(Args), Group, true, |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1724 | /*IsFramework=*/ (*it)->getOption().matches(OPT_F), false); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 1725 | IsIndexHeaderMap = false; |
| 1726 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1727 | |
| 1728 | // Add -iprefix/-iwith-prefix/-iwithprefixbefore options. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1729 | StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1730 | for (arg_iterator it = Args.filtered_begin(OPT_iprefix, OPT_iwithprefix, |
| 1731 | OPT_iwithprefixbefore), |
| 1732 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1733 | const Arg *A = *it; |
| 1734 | if (A->getOption().matches(OPT_iprefix)) |
| 1735 | Prefix = A->getValue(Args); |
| 1736 | else if (A->getOption().matches(OPT_iwithprefix)) |
| 1737 | Opts.AddPath(Prefix.str() + A->getValue(Args), |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1738 | frontend::System, false, false, false); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1739 | else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1740 | Opts.AddPath(Prefix.str() + A->getValue(Args), |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1741 | frontend::Angled, false, false, false); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | for (arg_iterator it = Args.filtered_begin(OPT_idirafter), |
| 1745 | ie = Args.filtered_end(); it != ie; ++it) |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1746 | Opts.AddPath((*it)->getValue(Args), frontend::After, true, false, false); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1747 | for (arg_iterator it = Args.filtered_begin(OPT_iquote), |
| 1748 | ie = Args.filtered_end(); it != ie; ++it) |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1749 | Opts.AddPath((*it)->getValue(Args), frontend::Quoted, true, false, false); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1750 | for (arg_iterator it = Args.filtered_begin(OPT_isystem, |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1751 | OPT_iwithsysroot), ie = Args.filtered_end(); it != ie; ++it) |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1752 | Opts.AddPath((*it)->getValue(Args), frontend::System, true, false, |
| 1753 | !(*it)->getOption().matches(OPT_iwithsysroot)); |
Daniel Dunbar | 024f4be | 2011-10-18 20:40:38 +0000 | [diff] [blame] | 1754 | for (arg_iterator it = Args.filtered_begin(OPT_iframework), |
| 1755 | ie = Args.filtered_end(); it != ie; ++it) |
| 1756 | Opts.AddPath((*it)->getValue(Args), frontend::System, true, true, |
| 1757 | true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1758 | |
| 1759 | // Add the paths for the various language specific isystem flags. |
| 1760 | for (arg_iterator it = Args.filtered_begin(OPT_c_isystem), |
| 1761 | ie = Args.filtered_end(); it != ie; ++it) |
| 1762 | Opts.AddPath((*it)->getValue(Args), frontend::CSystem, true, false, true); |
| 1763 | for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem), |
| 1764 | ie = Args.filtered_end(); it != ie; ++it) |
| 1765 | Opts.AddPath((*it)->getValue(Args), frontend::CXXSystem, true, false, true); |
| 1766 | for (arg_iterator it = Args.filtered_begin(OPT_objc_isystem), |
| 1767 | ie = Args.filtered_end(); it != ie; ++it) |
| 1768 | Opts.AddPath((*it)->getValue(Args), frontend::ObjCSystem, true, false,true); |
| 1769 | for (arg_iterator it = Args.filtered_begin(OPT_objcxx_isystem), |
| 1770 | ie = Args.filtered_end(); it != ie; ++it) |
| 1771 | Opts.AddPath((*it)->getValue(Args), frontend::ObjCXXSystem, true, false, |
| 1772 | true); |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1773 | |
| 1774 | // Add the internal paths from a driver that detects standard include paths. |
| 1775 | for (arg_iterator I = Args.filtered_begin(OPT_internal_isystem, |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 1776 | OPT_internal_externc_isystem), |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1777 | E = Args.filtered_end(); |
| 1778 | I != E; ++I) |
| 1779 | Opts.AddPath((*I)->getValue(Args), frontend::System, |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 1780 | false, false, /*IgnoreSysRoot=*/true, /*IsInternal=*/true, |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1781 | (*I)->getOption().matches(OPT_internal_externc_isystem)); |
Richard Smith | f122a13 | 2012-06-13 20:27:03 +0000 | [diff] [blame] | 1782 | |
| 1783 | // Add the path prefixes which are implicitly treated as being system headers. |
| 1784 | for (arg_iterator I = Args.filtered_begin(OPT_isystem_prefix, |
| 1785 | OPT_ino_system_prefix), |
| 1786 | E = Args.filtered_end(); |
| 1787 | I != E; ++I) |
| 1788 | Opts.AddSystemHeaderPrefix((*I)->getValue(Args), |
| 1789 | (*I)->getOption().matches(OPT_isystem_prefix)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1792 | void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, |
| 1793 | LangStandard::Kind LangStd) { |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1794 | // Set some properties which depend solely on the input kind; it would be nice |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1795 | // to move these to the language standard, and have the driver resolve the |
| 1796 | // input kind + language standard. |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1797 | if (IK == IK_Asm) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1798 | Opts.AsmPreprocessor = 1; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1799 | } else if (IK == IK_ObjC || |
| 1800 | IK == IK_ObjCXX || |
| 1801 | IK == IK_PreprocessedObjC || |
| 1802 | IK == IK_PreprocessedObjCXX) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1803 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 1804 | } |
| 1805 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1806 | if (LangStd == LangStandard::lang_unspecified) { |
| 1807 | // Based on the base language, pick one. |
| 1808 | switch (IK) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1809 | case IK_None: |
| 1810 | case IK_AST: |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 1811 | case IK_LLVM_IR: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1812 | llvm_unreachable("Invalid input kind!"); |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1813 | case IK_OpenCL: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1814 | LangStd = LangStandard::lang_opencl; |
| 1815 | break; |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1816 | case IK_CUDA: |
| 1817 | LangStd = LangStandard::lang_cuda; |
| 1818 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1819 | case IK_Asm: |
| 1820 | case IK_C: |
| 1821 | case IK_PreprocessedC: |
| 1822 | case IK_ObjC: |
| 1823 | case IK_PreprocessedObjC: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1824 | LangStd = LangStandard::lang_gnu99; |
| 1825 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1826 | case IK_CXX: |
| 1827 | case IK_PreprocessedCXX: |
| 1828 | case IK_ObjCXX: |
| 1829 | case IK_PreprocessedObjCXX: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1830 | LangStd = LangStandard::lang_gnucxx98; |
| 1831 | break; |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 1836 | Opts.BCPLComment = Std.hasBCPLComments(); |
| 1837 | Opts.C99 = Std.isC99(); |
Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 1838 | Opts.C11 = Std.isC11(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1839 | Opts.CPlusPlus = Std.isCPlusPlus(); |
| 1840 | Opts.CPlusPlus0x = Std.isCPlusPlus0x(); |
| 1841 | Opts.Digraphs = Std.hasDigraphs(); |
| 1842 | Opts.GNUMode = Std.isGNUMode(); |
| 1843 | Opts.GNUInline = !Std.isC99(); |
| 1844 | Opts.HexFloats = Std.hasHexFloats(); |
| 1845 | Opts.ImplicitInt = Std.hasImplicitInt(); |
| 1846 | |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 1847 | // Set OpenCL Version. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1848 | if (LangStd == LangStandard::lang_opencl) { |
| 1849 | Opts.OpenCL = 1; |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 1850 | Opts.OpenCLVersion = 100; |
| 1851 | } |
| 1852 | else if (LangStd == LangStandard::lang_opencl11) { |
| 1853 | Opts.OpenCL = 1; |
| 1854 | Opts.OpenCLVersion = 110; |
| 1855 | } |
| 1856 | else if (LangStd == LangStandard::lang_opencl12) { |
| 1857 | Opts.OpenCL = 1; |
| 1858 | Opts.OpenCLVersion = 120; |
| 1859 | } |
| 1860 | |
| 1861 | // OpenCL has some additional defaults. |
| 1862 | if (Opts.OpenCL) { |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 1863 | Opts.AltiVec = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1864 | Opts.CXXOperatorNames = 1; |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 1865 | Opts.LaxVectorConversions = 0; |
Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1866 | Opts.DefaultFPContract = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1869 | if (LangStd == LangStandard::lang_cuda) |
| 1870 | Opts.CUDA = 1; |
| 1871 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1872 | // OpenCL and C++ both have bool, true, false keywords. |
| 1873 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
| 1874 | |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 1875 | // C++ has wchar_t keyword. |
| 1876 | Opts.WChar = Opts.CPlusPlus; |
| 1877 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1878 | Opts.GNUKeywords = Opts.GNUMode; |
| 1879 | Opts.CXXOperatorNames = Opts.CPlusPlus; |
| 1880 | |
| 1881 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 1882 | // is specified, or -std is set to a conforming mode. |
| 1883 | Opts.Trigraphs = !Opts.GNUMode; |
| 1884 | |
| 1885 | Opts.DollarIdents = !Opts.AsmPreprocessor; |
| 1886 | } |
| 1887 | |
| 1888 | static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1889 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1890 | // FIXME: Cleanup per-file based stuff. |
| 1891 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 1892 | if (const Arg *A = Args.getLastArg(OPT_std_EQ)) { |
| 1893 | LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue(Args)) |
| 1894 | #define LANGSTANDARD(id, name, desc, features) \ |
| 1895 | .Case(name, LangStandard::lang_##id) |
| 1896 | #include "clang/Frontend/LangStandards.def" |
| 1897 | .Default(LangStandard::lang_unspecified); |
| 1898 | if (LangStd == LangStandard::lang_unspecified) |
| 1899 | Diags.Report(diag::err_drv_invalid_value) |
| 1900 | << A->getAsString(Args) << A->getValue(Args); |
Chad Rosier | b2dba4b | 2011-05-02 19:24:53 +0000 | [diff] [blame] | 1901 | else { |
| 1902 | // Valid standard, check to make sure language and standard are compatable. |
| 1903 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 1904 | switch (IK) { |
| 1905 | case IK_C: |
| 1906 | case IK_ObjC: |
| 1907 | case IK_PreprocessedC: |
| 1908 | case IK_PreprocessedObjC: |
| 1909 | if (!(Std.isC89() || Std.isC99())) |
| 1910 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1911 | << A->getAsString(Args) << "C/ObjC"; |
| 1912 | break; |
| 1913 | case IK_CXX: |
| 1914 | case IK_ObjCXX: |
| 1915 | case IK_PreprocessedCXX: |
| 1916 | case IK_PreprocessedObjCXX: |
| 1917 | if (!Std.isCPlusPlus()) |
| 1918 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1919 | << A->getAsString(Args) << "C++/ObjC++"; |
| 1920 | break; |
| 1921 | case IK_OpenCL: |
| 1922 | if (!Std.isC99()) |
| 1923 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1924 | << A->getAsString(Args) << "OpenCL"; |
| 1925 | break; |
| 1926 | case IK_CUDA: |
| 1927 | if (!Std.isCPlusPlus()) |
| 1928 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1929 | << A->getAsString(Args) << "CUDA"; |
| 1930 | break; |
| 1931 | default: |
| 1932 | break; |
| 1933 | } |
| 1934 | } |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1937 | // -cl-std only applies for OpenCL language standards. |
| 1938 | // Override the -std option in this case. |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1939 | if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1940 | LangStandard::Kind OpenCLLangStd |
| 1941 | = llvm::StringSwitch<LangStandard::Kind>(A->getValue(Args)) |
| 1942 | .Case("CL", LangStandard::lang_opencl) |
| 1943 | .Case("CL1.1", LangStandard::lang_opencl11) |
| 1944 | .Case("CL1.2", LangStandard::lang_opencl12) |
| 1945 | .Default(LangStandard::lang_unspecified); |
| 1946 | |
| 1947 | if (OpenCLLangStd == LangStandard::lang_unspecified) { |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1948 | Diags.Report(diag::err_drv_invalid_value) |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1949 | << A->getAsString(Args) << A->getValue(Args); |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1950 | } |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1951 | else |
| 1952 | LangStd = OpenCLLangStd; |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1953 | } |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1954 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1955 | CompilerInvocation::setLangDefaults(Opts, IK, LangStd); |
| 1956 | |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1957 | // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension |
| 1958 | // keywords. This behavior is provided by GCC's poorly named '-fasm' flag, |
| 1959 | // while a subset (the non-C++ GNU keywords) is provided by GCC's |
| 1960 | // '-fgnu-keywords'. Clang conflates the two for simplicity under the single |
| 1961 | // name, as it doesn't seem a useful distinction. |
| 1962 | Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1963 | Opts.GNUKeywords); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1964 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1965 | if (Args.hasArg(OPT_fno_operator_names)) |
| 1966 | Opts.CXXOperatorNames = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1967 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1968 | if (Opts.ObjC1) { |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1969 | if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) { |
| 1970 | StringRef value = arg->getValue(Args); |
| 1971 | if (Opts.ObjCRuntime.tryParse(value)) |
| 1972 | Diags.Report(diag::err_drv_unknown_objc_runtime) << value; |
| 1973 | } |
| 1974 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1975 | if (Args.hasArg(OPT_fobjc_gc_only)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1976 | Opts.setGC(LangOptions::GCOnly); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1977 | else if (Args.hasArg(OPT_fobjc_gc)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1978 | Opts.setGC(LangOptions::HybridGC); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1979 | else if (Args.hasArg(OPT_fobjc_arc)) { |
| 1980 | Opts.ObjCAutoRefCount = 1; |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1981 | if (!Opts.ObjCRuntime.allowsARC()) |
| 1982 | Diags.Report(diag::err_arc_unsupported_on_runtime); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1983 | |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1984 | // Only set ObjCARCWeak if ARC is enabled. |
| 1985 | if (Args.hasArg(OPT_fobjc_runtime_has_weak)) |
| 1986 | Opts.ObjCARCWeak = 1; |
| 1987 | else |
| 1988 | Opts.ObjCARCWeak = Opts.ObjCRuntime.allowsWeak(); |
| 1989 | } |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 1990 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1991 | if (Args.hasArg(OPT_fno_objc_infer_related_result_type)) |
| 1992 | Opts.ObjCInferRelatedResultType = 0; |
| 1993 | } |
| 1994 | |
Rafael Espindola | fb3f4aa | 2011-06-02 16:13:27 +0000 | [diff] [blame] | 1995 | if (Args.hasArg(OPT_fgnu89_inline)) |
| 1996 | Opts.GNUInline = 1; |
| 1997 | |
Fariborz Jahanian | 142f9e9 | 2011-02-04 00:01:24 +0000 | [diff] [blame] | 1998 | if (Args.hasArg(OPT_fapple_kext)) { |
| 1999 | if (!Opts.CPlusPlus) |
| 2000 | Diags.Report(diag::warn_c_kext); |
| 2001 | else |
| 2002 | Opts.AppleKext = 1; |
| 2003 | } |
| 2004 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2005 | if (Args.hasArg(OPT_print_ivar_layout)) |
| 2006 | Opts.ObjCGCBitmapPrint = 1; |
Fariborz Jahanian | 33e982b | 2010-04-22 20:26:39 +0000 | [diff] [blame] | 2007 | if (Args.hasArg(OPT_fno_constant_cfstrings)) |
| 2008 | Opts.NoConstantCFStrings = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2009 | |
| 2010 | if (Args.hasArg(OPT_faltivec)) |
| 2011 | Opts.AltiVec = 1; |
| 2012 | |
| 2013 | if (Args.hasArg(OPT_pthread)) |
| 2014 | Opts.POSIXThreads = 1; |
| 2015 | |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2016 | if (Args.hasArg(OPT_fdelayed_template_parsing)) |
| 2017 | Opts.DelayedTemplateParsing = 1; |
| 2018 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2019 | StringRef Vis = Args.getLastArgValue(OPT_fvisibility, "default"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2020 | if (Vis == "default") |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2021 | Opts.setVisibilityMode(DefaultVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2022 | else if (Vis == "hidden") |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2023 | Opts.setVisibilityMode(HiddenVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2024 | else if (Vis == "protected") |
John McCall | 4188760 | 2012-01-29 01:20:30 +0000 | [diff] [blame] | 2025 | // FIXME: diagnose if target does not support protected visibility |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2026 | Opts.setVisibilityMode(ProtectedVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2027 | else |
| 2028 | Diags.Report(diag::err_drv_invalid_value) |
| 2029 | << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; |
| 2030 | |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 2031 | if (Arg *A = Args.getLastArg(OPT_ffp_contract)) { |
| 2032 | StringRef Val = A->getValue(Args); |
| 2033 | if (Val == "fast") |
| 2034 | Opts.setFPContractMode(LangOptions::FPC_Fast); |
| 2035 | else if (Val == "on") |
| 2036 | Opts.setFPContractMode(LangOptions::FPC_On); |
| 2037 | else if (Val == "off") |
| 2038 | Opts.setFPContractMode(LangOptions::FPC_Off); |
| 2039 | else |
| 2040 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; |
| 2041 | } |
| 2042 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 2043 | if (Args.hasArg(OPT_fvisibility_inlines_hidden)) |
| 2044 | Opts.InlineVisibilityHidden = 1; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2045 | |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 2046 | if (Args.hasArg(OPT_ftrapv)) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2047 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 2048 | // Set the handler, if one is specified. |
| 2049 | Opts.OverflowHandler = |
| 2050 | Args.getLastArgValue(OPT_ftrapv_handler); |
| 2051 | } |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2052 | else if (Args.hasArg(OPT_fwrapv)) |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2053 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2054 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2055 | if (Args.hasArg(OPT_trigraphs)) |
| 2056 | Opts.Trigraphs = 1; |
| 2057 | |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 2058 | Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, |
| 2059 | OPT_fno_dollars_in_identifiers, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 2060 | Opts.DollarIdents); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2061 | Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); |
Douglas Gregor | 0bb935c | 2011-10-24 15:27:23 +0000 | [diff] [blame] | 2062 | Opts.MicrosoftExt |
| 2063 | = Args.hasArg(OPT_fms_extensions) || Args.hasArg(OPT_fms_compatibility); |
Francois Pichet | ae55608 | 2011-09-17 04:32:15 +0000 | [diff] [blame] | 2064 | Opts.MicrosoftMode = Args.hasArg(OPT_fms_compatibility); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2065 | Opts.MSCVersion = Args.getLastArgIntValue(OPT_fmsc_version, 0, Diags); |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 2066 | Opts.Borland = Args.hasArg(OPT_fborland_extensions); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2067 | Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 2068 | Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings, |
| 2069 | Opts.ConstStrings); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2070 | if (Args.hasArg(OPT_fno_lax_vector_conversions)) |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 2071 | Opts.LaxVectorConversions = 0; |
| 2072 | if (Args.hasArg(OPT_fno_threadsafe_statics)) |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 2073 | Opts.ThreadsafeStatics = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2074 | Opts.Exceptions = Args.hasArg(OPT_fexceptions); |
Anders Carlsson | e9b801f | 2011-02-22 01:52:06 +0000 | [diff] [blame] | 2075 | Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 2076 | Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions); |
| 2077 | Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); |
Daniel Dunbar | 2ed4228 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 2078 | Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 2079 | |
Mike Stump | de05057 | 2009-12-02 18:57:08 +0000 | [diff] [blame] | 2080 | Opts.RTTI = !Args.hasArg(OPT_fno_rtti); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2081 | Opts.Blocks = Args.hasArg(OPT_fblocks); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 2082 | Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); |
Douglas Gregor | 752c74d | 2012-01-03 17:07:34 +0000 | [diff] [blame] | 2083 | Opts.Modules = Args.hasArg(OPT_fmodules); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2084 | Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char); |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 2085 | Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2086 | Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 2087 | Opts.ShortEnums = Args.hasArg(OPT_fshort_enums); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2088 | Opts.Freestanding = Args.hasArg(OPT_ffreestanding); |
| 2089 | Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 2090 | Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2091 | Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 2092 | Opts.AccessControl = !Args.hasArg(OPT_fno_access_control); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2093 | Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); |
Dan Gohman | c31176d | 2010-01-08 02:20:44 +0000 | [diff] [blame] | 2094 | Opts.MathErrno = Args.hasArg(OPT_fmath_errno); |
Douglas Gregor | 8f4783c | 2012-07-02 19:56:23 +0000 | [diff] [blame] | 2095 | Opts.InstantiationDepth = Args.getLastArgIntValue(OPT_ftemplate_depth, 512, |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 2096 | Diags); |
| 2097 | Opts.ConstexprCallDepth = Args.getLastArgIntValue(OPT_fconstexpr_depth, 512, |
| 2098 | Diags); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2099 | Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 2100 | Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy_EQ, |
Argyrios Kyrtzidis | 3532fdd | 2010-11-17 23:11:54 +0000 | [diff] [blame] | 2101 | 0, Diags); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2102 | Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2103 | Opts.ObjCConstantStringClass = |
| 2104 | Args.getLastArgValue(OPT_fconstant_string_class); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2105 | Opts.ObjCDefaultSynthProperties = |
| 2106 | Args.hasArg(OPT_fobjc_default_synthesize_properties); |
Nuno Lopes | def1849 | 2012-05-22 17:19:45 +0000 | [diff] [blame] | 2107 | Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2108 | Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 2109 | Opts.PackStruct = Args.getLastArgIntValue(OPT_fpack_struct_EQ, 0, Diags); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2110 | Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags); |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 2111 | Opts.PIELevel = Args.getLastArgIntValue(OPT_pie_level, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2112 | Opts.Static = Args.hasArg(OPT_static_define); |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 2113 | Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple); |
| 2114 | Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple |
| 2115 | || Args.hasArg(OPT_fdump_record_layouts); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 2116 | Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 2117 | Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking); |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 2118 | Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); |
Peter Collingbourne | 0982136 | 2010-12-04 01:50:56 +0000 | [diff] [blame] | 2119 | Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 2120 | Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 2121 | Opts.MRTD = Args.hasArg(OPT_mrtd); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2122 | Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 2123 | Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map); |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 2124 | Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype); |
John McCall | 48218c6 | 2011-07-13 17:56:40 +0000 | [diff] [blame] | 2125 | Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support); |
Sean Callanan | 50a9a12 | 2012-02-04 01:29:37 +0000 | [diff] [blame] | 2126 | Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2127 | Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal); |
Kostya Serebryany | b619688 | 2011-11-22 01:28:36 +0000 | [diff] [blame] | 2128 | Opts.AddressSanitizer = Args.hasArg(OPT_faddress_sanitizer); |
Kostya Serebryany | 3c93122 | 2012-03-01 22:27:08 +0000 | [diff] [blame] | 2129 | Opts.ThreadSanitizer = Args.hasArg(OPT_fthread_sanitizer); |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 2130 | Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack); |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 2131 | Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2132 | |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 2133 | // Record whether the __DEPRECATED define was requested. |
| 2134 | Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro, |
| 2135 | OPT_fno_deprecated_macro, |
| 2136 | Opts.Deprecated); |
| 2137 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2138 | // FIXME: Eliminate this dependency. |
Dylan Noblesmith | f23e8d2 | 2012-08-08 16:09:15 +0000 | [diff] [blame] | 2139 | unsigned Opt = getOptimizationLevel(Args, IK, Diags), |
| 2140 | OptSize = getOptimizationLevelSize(Args, IK, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2141 | Opts.Optimize = Opt != 0; |
Dylan Noblesmith | f23e8d2 | 2012-08-08 16:09:15 +0000 | [diff] [blame] | 2142 | Opts.OptimizeSize = OptSize != 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2143 | |
| 2144 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 2145 | // optimization level and -fno-inline, not actually whether the backend has |
| 2146 | // inlining enabled. |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 2147 | Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2148 | |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2149 | Opts.FastMath = Args.hasArg(OPT_ffast_math); |
Bob Wilson | 455e72e | 2012-07-19 03:52:53 +0000 | [diff] [blame] | 2150 | Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2151 | |
Chad Rosier | 56d7f23 | 2012-08-24 21:42:51 +0000 | [diff] [blame] | 2152 | Opts.EmitMicrosoftInlineAsm = Args.hasArg(OPT_fenable_experimental_ms_inline_asm); |
| 2153 | |
Ted Kremenek | 127ff2e | 2012-09-13 06:41:18 +0000 | [diff] [blame] | 2154 | Opts.RetainCommentsFromSystemHeaders = |
| 2155 | Args.hasArg(OPT_fretain_comments_from_system_headers); |
| 2156 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2157 | unsigned SSP = Args.getLastArgIntValue(OPT_stack_protector, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2158 | switch (SSP) { |
| 2159 | default: |
| 2160 | Diags.Report(diag::err_drv_invalid_value) |
| 2161 | << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; |
| 2162 | break; |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 2163 | case 0: Opts.setStackProtector(LangOptions::SSPOff); break; |
| 2164 | case 1: Opts.setStackProtector(LangOptions::SSPOn); break; |
| 2165 | case 2: Opts.setStackProtector(LangOptions::SSPReq); break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 2169 | static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2170 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2171 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 2172 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2173 | Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch); |
| 2174 | Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2175 | if (const Arg *A = Args.getLastArg(OPT_token_cache)) |
| 2176 | Opts.TokenCache = A->getValue(Args); |
| 2177 | else |
| 2178 | Opts.TokenCache = Opts.ImplicitPTHInclude; |
| 2179 | Opts.UsePredefines = !Args.hasArg(OPT_undef); |
Douglas Gregor | 94dc8f6 | 2010-03-19 16:15:56 +0000 | [diff] [blame] | 2180 | Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2181 | Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 2182 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 2183 | Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 2184 | for (arg_iterator it = Args.filtered_begin(OPT_error_on_deserialized_pch_decl), |
| 2185 | ie = Args.filtered_end(); it != ie; ++it) { |
| 2186 | const Arg *A = *it; |
| 2187 | Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue(Args)); |
| 2188 | } |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2189 | |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 2190 | if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2191 | StringRef Value(A->getValue(Args)); |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 2192 | size_t Comma = Value.find(','); |
| 2193 | unsigned Bytes = 0; |
| 2194 | unsigned EndOfLine = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2195 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2196 | if (Comma == StringRef::npos || |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 2197 | Value.substr(0, Comma).getAsInteger(10, Bytes) || |
| 2198 | Value.substr(Comma + 1).getAsInteger(10, EndOfLine)) |
| 2199 | Diags.Report(diag::err_drv_preamble_format); |
| 2200 | else { |
| 2201 | Opts.PrecompiledPreambleBytes.first = Bytes; |
| 2202 | Opts.PrecompiledPreambleBytes.second = (EndOfLine != 0); |
| 2203 | } |
| 2204 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2205 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2206 | // Add macros from the command line. |
| 2207 | for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U), |
| 2208 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2209 | if ((*it)->getOption().matches(OPT_D)) |
| 2210 | Opts.addMacroDef((*it)->getValue(Args)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2211 | else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2212 | Opts.addMacroUndef((*it)->getValue(Args)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2215 | Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2216 | |
| 2217 | // Add the ordered list of -includes. |
| 2218 | for (arg_iterator it = Args.filtered_begin(OPT_include, OPT_include_pch, |
| 2219 | OPT_include_pth), |
| 2220 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2221 | const Arg *A = *it; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2222 | // PCH is handled specially, we need to extra the original include path. |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2223 | if (A->getOption().matches(OPT_include_pch)) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2224 | std::string OriginalFile = |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2225 | ASTReader::getOriginalSourceFile(A->getValue(Args), FileMgr, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2226 | if (OriginalFile.empty()) |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2227 | continue; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2228 | |
| 2229 | Opts.Includes.push_back(OriginalFile); |
| 2230 | } else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2231 | Opts.Includes.push_back(A->getValue(Args)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2232 | } |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 2233 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2234 | for (arg_iterator it = Args.filtered_begin(OPT_chain_include), |
| 2235 | ie = Args.filtered_end(); it != ie; ++it) { |
| 2236 | const Arg *A = *it; |
| 2237 | Opts.ChainedIncludes.push_back(A->getValue(Args)); |
| 2238 | } |
| 2239 | |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 2240 | // Include 'altivec.h' if -faltivec option present |
| 2241 | if (Args.hasArg(OPT_faltivec)) |
| 2242 | Opts.Includes.push_back("altivec.h"); |
| 2243 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 2244 | for (arg_iterator it = Args.filtered_begin(OPT_remap_file), |
| 2245 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2246 | const Arg *A = *it; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2247 | std::pair<StringRef,StringRef> Split = |
| 2248 | StringRef(A->getValue(Args)).split(';'); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 2249 | |
| 2250 | if (Split.second.empty()) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2251 | Diags.Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 2252 | continue; |
| 2253 | } |
| 2254 | |
| 2255 | Opts.addRemappedFile(Split.first, Split.second); |
| 2256 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2257 | |
| 2258 | if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2259 | StringRef Name = A->getValue(Args); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2260 | unsigned Library = llvm::StringSwitch<unsigned>(Name) |
| 2261 | .Case("libc++", ARCXX_libcxx) |
| 2262 | .Case("libstdc++", ARCXX_libstdcxx) |
| 2263 | .Case("none", ARCXX_nolib) |
| 2264 | .Default(~0U); |
| 2265 | if (Library == ~0U) |
| 2266 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 2267 | else |
| 2268 | Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library; |
| 2269 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, |
| 2273 | ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 2274 | using namespace options; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2275 | Opts.ShowCPP = !Args.hasArg(OPT_dM); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2276 | Opts.ShowComments = Args.hasArg(OPT_C); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 2277 | Opts.ShowLineMarkers = !Args.hasArg(OPT_P); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2278 | Opts.ShowMacroComments = Args.hasArg(OPT_CC); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 2279 | Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD); |
David Blaikie | f1492f9 | 2012-06-14 17:36:09 +0000 | [diff] [blame] | 2280 | Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 2284 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2285 | Opts.ABI = Args.getLastArgValue(OPT_target_abi); |
Charles Davis | 98b7c5c | 2010-06-11 01:06:47 +0000 | [diff] [blame] | 2286 | Opts.CXXABI = Args.getLastArgValue(OPT_cxx_abi); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2287 | Opts.CPU = Args.getLastArgValue(OPT_target_cpu); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 2288 | Opts.Features = Args.getAllArgValues(OPT_target_feature); |
Daniel Dunbar | 39065a5 | 2010-08-11 23:07:42 +0000 | [diff] [blame] | 2289 | Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version); |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 2290 | Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2291 | |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 2292 | // Use the default target triple if unspecified. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2293 | if (Opts.Triple.empty()) |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 2294 | Opts.Triple = llvm::sys::getDefaultTargetTriple(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | // |
| 2298 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2299 | bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2300 | const char *const *ArgBegin, |
| 2301 | const char *const *ArgEnd, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2302 | DiagnosticsEngine &Diags) { |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2303 | bool Success = true; |
| 2304 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2305 | // Parse the arguments. |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 2306 | OwningPtr<OptTable> Opts(createDriverOptTable()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2307 | unsigned MissingArgIndex, MissingArgCount; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 2308 | OwningPtr<InputArgList> Args( |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2309 | Opts->ParseArgs(ArgBegin, ArgEnd,MissingArgIndex, MissingArgCount)); |
| 2310 | |
| 2311 | // Check for missing argument error. |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2312 | if (MissingArgCount) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2313 | Diags.Report(diag::err_drv_missing_argument) |
| 2314 | << Args->getArgString(MissingArgIndex) << MissingArgCount; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2315 | Success = false; |
| 2316 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2317 | |
| 2318 | // Issue errors on unknown arguments. |
| 2319 | for (arg_iterator it = Args->filtered_begin(OPT_UNKNOWN), |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2320 | ie = Args->filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2321 | Diags.Report(diag::err_drv_unknown_argument) << (*it)->getAsString(*Args); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2322 | Success = false; |
| 2323 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2324 | |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 2325 | // Issue errors on arguments that are not valid for CC1. |
| 2326 | for (ArgList::iterator I = Args->begin(), E = Args->end(); |
| 2327 | I != E; ++I) { |
| 2328 | if (!(*I)->getOption().isCC1Option()) { |
| 2329 | Diags.Report(diag::err_drv_unknown_argument) << (*I)->getAsString(*Args); |
| 2330 | Success = false; |
| 2331 | } |
| 2332 | } |
| 2333 | |
Ted Kremenek | 45796b1 | 2012-08-31 04:36:05 +0000 | [diff] [blame] | 2334 | Success = ParseAnalyzerArgs(*Res.getAnalyzerOpts(), *Args, Diags) && Success; |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 2335 | Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2336 | ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args); |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 2337 | Success = ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, &Diags) |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2338 | && Success; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2339 | ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 2340 | // FIXME: We shouldn't have to pass the DashX option around here |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 2341 | InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2342 | Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags) |
| 2343 | && Success; |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 2344 | ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 2345 | if (DashX != IK_AST && DashX != IK_LLVM_IR) { |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2346 | ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 2347 | if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC) |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2348 | Res.getLangOpts()->ObjCExceptions = 1; |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 2349 | } |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2350 | // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of |
| 2351 | // PCH file and find the original header name. Remove the need to do that in |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2352 | // ParsePreprocessorArgs and remove the FileManager |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2353 | // parameters from the function and the "FileManager.h" #include. |
Chris Lattner | 7ad97ff | 2010-11-23 07:51:02 +0000 | [diff] [blame] | 2354 | FileManager FileMgr(Res.getFileSystemOpts()); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2355 | ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2356 | ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args); |
| 2357 | ParseTargetArgs(Res.getTargetOpts(), *Args); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 2358 | |
| 2359 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2360 | } |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2361 | |
| 2362 | namespace { |
| 2363 | |
| 2364 | class ModuleSignature { |
| 2365 | llvm::SmallVector<uint64_t, 16> Data; |
| 2366 | unsigned CurBit; |
| 2367 | uint64_t CurValue; |
| 2368 | |
| 2369 | public: |
| 2370 | ModuleSignature() : CurBit(0), CurValue(0) { } |
| 2371 | |
| 2372 | void add(uint64_t Value, unsigned Bits); |
| 2373 | void add(StringRef Value); |
| 2374 | void flush(); |
| 2375 | |
| 2376 | llvm::APInt getAsInteger() const; |
| 2377 | }; |
| 2378 | } |
| 2379 | |
| 2380 | void ModuleSignature::add(uint64_t Value, unsigned int NumBits) { |
| 2381 | CurValue |= Value << CurBit; |
| 2382 | if (CurBit + NumBits < 64) { |
| 2383 | CurBit += NumBits; |
| 2384 | return; |
| 2385 | } |
| 2386 | |
| 2387 | // Add the current word. |
| 2388 | Data.push_back(CurValue); |
| 2389 | |
| 2390 | if (CurBit) |
| 2391 | CurValue = Value >> (64-CurBit); |
| 2392 | else |
| 2393 | CurValue = 0; |
| 2394 | CurBit = (CurBit+NumBits) & 63; |
| 2395 | } |
| 2396 | |
| 2397 | void ModuleSignature::flush() { |
| 2398 | if (CurBit == 0) |
| 2399 | return; |
| 2400 | |
| 2401 | Data.push_back(CurValue); |
| 2402 | CurBit = 0; |
| 2403 | CurValue = 0; |
| 2404 | } |
| 2405 | |
| 2406 | void ModuleSignature::add(StringRef Value) { |
| 2407 | for (StringRef::iterator I = Value.begin(), IEnd = Value.end(); I != IEnd;++I) |
| 2408 | add(*I, 8); |
| 2409 | } |
| 2410 | |
| 2411 | llvm::APInt ModuleSignature::getAsInteger() const { |
| 2412 | return llvm::APInt(Data.size() * 64, Data); |
| 2413 | } |
| 2414 | |
| 2415 | std::string CompilerInvocation::getModuleHash() const { |
| 2416 | ModuleSignature Signature; |
| 2417 | |
| 2418 | // Start the signature with the compiler version. |
Bob Wilson | e286d9b | 2012-03-07 23:50:05 +0000 | [diff] [blame] | 2419 | // FIXME: The full version string can be quite long. Omit it from the |
| 2420 | // module hash for now to avoid failures where the path name becomes too |
| 2421 | // long. An MD5 or similar checksum would work well here. |
| 2422 | // Signature.add(getClangFullRepositoryVersion()); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2423 | |
| 2424 | // Extend the signature with the language options |
| 2425 | #define LANGOPT(Name, Bits, Default, Description) \ |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2426 | Signature.add(LangOpts->Name, Bits); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2427 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2428 | Signature.add(static_cast<unsigned>(LangOpts->get##Name()), Bits); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2429 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 2430 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 2431 | #include "clang/Basic/LangOptions.def" |
| 2432 | |
| 2433 | // Extend the signature with the target triple |
| 2434 | llvm::Triple T(TargetOpts.Triple); |
| 2435 | Signature.add((unsigned)T.getArch(), 5); |
| 2436 | Signature.add((unsigned)T.getVendor(), 4); |
| 2437 | Signature.add((unsigned)T.getOS(), 5); |
| 2438 | Signature.add((unsigned)T.getEnvironment(), 4); |
| 2439 | |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 2440 | // Extend the signature with preprocessor options. |
| 2441 | Signature.add(getPreprocessorOpts().UsePredefines, 1); |
| 2442 | Signature.add(getPreprocessorOpts().DetailedRecord, 1); |
| 2443 | |
Douglas Gregor | 05edf66 | 2011-10-17 14:55:37 +0000 | [diff] [blame] | 2444 | // Hash the preprocessor defines. |
| 2445 | // FIXME: This is terrible. Use an MD5 sum of the preprocessor defines. |
| 2446 | std::vector<StringRef> MacroDefs; |
| 2447 | for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator |
| 2448 | I = getPreprocessorOpts().Macros.begin(), |
| 2449 | IEnd = getPreprocessorOpts().Macros.end(); |
| 2450 | I != IEnd; ++I) { |
| 2451 | if (!I->second) |
| 2452 | MacroDefs.push_back(I->first); |
| 2453 | } |
| 2454 | llvm::array_pod_sort(MacroDefs.begin(), MacroDefs.end()); |
| 2455 | |
| 2456 | unsigned PPHashResult = 0; |
| 2457 | for (unsigned I = 0, N = MacroDefs.size(); I != N; ++I) |
| 2458 | PPHashResult = llvm::HashString(MacroDefs[I], PPHashResult); |
| 2459 | Signature.add(PPHashResult, 32); |
| 2460 | |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2461 | // We've generated the signature. Treat it as one large APInt that we'll |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 2462 | // encode in base-36 and return. |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2463 | Signature.flush(); |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 2464 | return Signature.getAsInteger().toString(36, /*Signed=*/false); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2465 | } |