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 | |
Roman Divacky | 95f38f6 | 2012-12-21 17:23:52 +0000 | [diff] [blame] | 10 | #include "clang/Frontend/CompilerInvocation.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 11 | #include "clang/Basic/Diagnostic.h" |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 12 | #include "clang/Basic/FileManager.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 13 | #include "clang/Basic/Version.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" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 16 | #include "clang/Driver/DriverDiagnostic.h" |
| 17 | #include "clang/Driver/OptTable.h" |
| 18 | #include "clang/Driver/Option.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Options.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/LangStandard.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/Lex/HeaderSearchOptions.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 22 | #include "clang/Serialization/ASTReader.h" |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Hashing.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/OwningPtr.h" |
| 25 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringSwitch.h" |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/Triple.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Host.h" |
| 31 | #include "llvm/Support/Path.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Initialization. |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 38 | CompilerInvocationBase::CompilerInvocationBase() |
Douglas Gregor | 02c23eb | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 39 | : LangOpts(new LangOptions()), TargetOpts(new TargetOptions()), |
Douglas Gregor | c042edd | 2012-10-24 16:19:39 +0000 | [diff] [blame] | 40 | DiagnosticOpts(new DiagnosticOptions()), |
Douglas Gregor | 14e71f0 | 2012-10-24 17:01:35 +0000 | [diff] [blame] | 41 | HeaderSearchOpts(new HeaderSearchOptions()), |
| 42 | PreprocessorOpts(new PreprocessorOptions()) {} |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 43 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 44 | CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X) |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 45 | : RefCountedBase<CompilerInvocation>(), |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 46 | LangOpts(new LangOptions(*X.getLangOpts())), |
Douglas Gregor | 02c23eb | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 47 | TargetOpts(new TargetOptions(X.getTargetOpts())), |
Douglas Gregor | c042edd | 2012-10-24 16:19:39 +0000 | [diff] [blame] | 48 | DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())), |
Douglas Gregor | 14e71f0 | 2012-10-24 17:01:35 +0000 | [diff] [blame] | 49 | HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())), |
| 50 | PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {} |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 51 | |
| 52 | //===----------------------------------------------------------------------===// |
Richard Smith | 7c3f8b3 | 2012-11-01 03:48:49 +0000 | [diff] [blame] | 53 | // Deserialization (from args) |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 54 | //===----------------------------------------------------------------------===// |
| 55 | |
| 56 | using namespace clang::driver; |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 57 | using namespace clang::driver::options; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 58 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 59 | // |
| 60 | |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 61 | static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 62 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 61e0786 | 2010-12-04 01:50:45 +0000 | [diff] [blame] | 63 | unsigned DefaultOpt = 0; |
| 64 | if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable)) |
| 65 | DefaultOpt = 2; |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 66 | |
| 67 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
| 68 | if (A->getOption().matches(options::OPT_O0)) |
| 69 | return 0; |
| 70 | |
| 71 | assert (A->getOption().matches(options::OPT_O)); |
| 72 | |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 73 | StringRef S(A->getValue()); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 74 | if (S == "s" || S == "z" || S.empty()) |
| 75 | return 2; |
| 76 | |
| 77 | return Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags); |
| 78 | } |
| 79 | |
| 80 | return DefaultOpt; |
| 81 | } |
| 82 | |
| 83 | static unsigned getOptimizationLevelSize(ArgList &Args, InputKind IK, |
| 84 | DiagnosticsEngine &Diags) { |
| 85 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
| 86 | if (A->getOption().matches(options::OPT_O)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 87 | switch (A->getValue()[0]) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 88 | default: |
| 89 | return 0; |
| 90 | case 's': |
| 91 | return 1; |
| 92 | case 'z': |
| 93 | return 2; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static void addWarningArgs(ArgList &Args, std::vector<std::string> &Warnings) { |
| 101 | for (arg_iterator I = Args.filtered_begin(OPT_W_Group), |
| 102 | E = Args.filtered_end(); I != E; ++I) { |
| 103 | Arg *A = *I; |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 104 | // If the argument is a pure flag, add its name (minus the "W" at the beginning) |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 105 | // to the warning list. Else, add its value (for the OPT_W case). |
| 106 | if (A->getOption().getKind() == Option::FlagClass) { |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 107 | Warnings.push_back(A->getOption().getName().substr(1)); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 108 | } else { |
| 109 | for (unsigned Idx = 0, End = A->getNumValues(); |
| 110 | Idx < End; ++Idx) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 111 | StringRef V = A->getValue(Idx); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 112 | // "-Wl," and such are not warning options. |
| 113 | // FIXME: Should be handled by putting these in separate flags. |
| 114 | if (V.startswith("l,") || V.startswith("a,") || V.startswith("p,")) |
| 115 | continue; |
| 116 | |
| 117 | Warnings.push_back(V); |
| 118 | } |
| 119 | } |
| 120 | } |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 123 | static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 124 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 125 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 126 | bool Success = true; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 127 | if (Arg *A = Args.getLastArg(OPT_analyzer_store)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 128 | StringRef Name = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 129 | AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name) |
| 130 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \ |
| 131 | .Case(CMDFLAG, NAME##Model) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 132 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 133 | .Default(NumStores); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 134 | if (Value == NumStores) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 135 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 136 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 137 | Success = false; |
| 138 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 139 | Opts.AnalysisStoreOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 140 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 144 | StringRef Name = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 145 | AnalysisConstraints Value = llvm::StringSwitch<AnalysisConstraints>(Name) |
| 146 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \ |
| 147 | .Case(CMDFLAG, NAME##Model) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 148 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 149 | .Default(NumConstraints); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 150 | if (Value == NumConstraints) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 151 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 152 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 153 | Success = false; |
| 154 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 155 | Opts.AnalysisConstraintsOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 156 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | if (Arg *A = Args.getLastArg(OPT_analyzer_output)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 160 | StringRef Name = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 161 | AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name) |
| 162 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) \ |
| 163 | .Case(CMDFLAG, PD_##NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 164 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 165 | .Default(NUM_ANALYSIS_DIAG_CLIENTS); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 166 | if (Value == NUM_ANALYSIS_DIAG_CLIENTS) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 167 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 168 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 169 | Success = false; |
| 170 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 171 | Opts.AnalysisDiagOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 172 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 175 | if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 176 | StringRef Name = A->getValue(); |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 177 | AnalysisPurgeMode Value = llvm::StringSwitch<AnalysisPurgeMode>(Name) |
| 178 | #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \ |
| 179 | .Case(CMDFLAG, NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 180 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 181 | .Default(NumPurgeModes); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 182 | if (Value == NumPurgeModes) { |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 183 | Diags.Report(diag::err_drv_invalid_value) |
| 184 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 185 | Success = false; |
| 186 | } else { |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 187 | Opts.AnalysisPurgeOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 188 | } |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 191 | if (Arg *A = Args.getLastArg(OPT_analyzer_inlining_mode)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 192 | StringRef Name = A->getValue(); |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 193 | AnalysisInliningMode Value = llvm::StringSwitch<AnalysisInliningMode>(Name) |
| 194 | #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) \ |
| 195 | .Case(CMDFLAG, NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 196 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 197 | .Default(NumInliningModes); |
| 198 | if (Value == NumInliningModes) { |
| 199 | Diags.Report(diag::err_drv_invalid_value) |
| 200 | << A->getAsString(Args) << Name; |
| 201 | Success = false; |
| 202 | } else { |
| 203 | Opts.InliningMode = Value; |
| 204 | } |
| 205 | } |
| 206 | |
Argyrios Kyrtzidis | 116f364 | 2011-02-25 00:09:51 +0000 | [diff] [blame] | 207 | Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help); |
Ted Kremenek | 3b8a040 | 2012-08-30 19:26:53 +0000 | [diff] [blame] | 208 | Opts.visualizeExplodedGraphWithGraphViz = |
| 209 | Args.hasArg(OPT_analyzer_viz_egraph_graphviz); |
| 210 | Opts.visualizeExplodedGraphWithUbiGraph = |
| 211 | Args.hasArg(OPT_analyzer_viz_egraph_ubigraph); |
Anna Zaks | b47dbcb | 2012-03-28 19:59:16 +0000 | [diff] [blame] | 212 | Opts.NoRetryExhausted = Args.hasArg(OPT_analyzer_disable_retry_exhausted); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 213 | Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers); |
| 214 | Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress); |
Ted Kremenek | fc57651 | 2009-12-07 22:06:12 +0000 | [diff] [blame] | 215 | Opts.AnalyzeNestedBlocks = |
| 216 | Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks); |
Ted Kremenek | 0caa2d4 | 2012-08-30 19:26:48 +0000 | [diff] [blame] | 217 | Opts.eagerlyAssumeBinOpBifurcation = Args.hasArg(OPT_analyzer_eagerly_assume); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 218 | Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function); |
Ted Kremenek | 9b823e8 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 219 | Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 220 | Opts.TrimGraph = Args.hasArg(OPT_trim_egraph); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 221 | Opts.MaxNodes = Args.getLastArgIntValue(OPT_analyzer_max_nodes, 150000,Diags); |
Ted Kremenek | 2fa9d72 | 2012-08-30 19:26:56 +0000 | [diff] [blame] | 222 | Opts.maxBlockVisitOnPath = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags); |
Anna Zaks | 81fb169 | 2012-02-27 21:33:16 +0000 | [diff] [blame] | 223 | Opts.PrintStats = Args.hasArg(OPT_analyzer_stats); |
Anna Zaks | 8235f9c | 2012-03-02 19:05:03 +0000 | [diff] [blame] | 224 | Opts.InlineMaxStackDepth = |
| 225 | Args.getLastArgIntValue(OPT_analyzer_inline_max_stack_depth, |
| 226 | Opts.InlineMaxStackDepth, Diags); |
| 227 | Opts.InlineMaxFunctionSize = |
| 228 | Args.getLastArgIntValue(OPT_analyzer_inline_max_function_size, |
| 229 | Opts.InlineMaxFunctionSize, Diags); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 230 | |
| 231 | Opts.CheckersControlList.clear(); |
| 232 | for (arg_iterator it = Args.filtered_begin(OPT_analyzer_checker, |
| 233 | OPT_analyzer_disable_checker), |
| 234 | ie = Args.filtered_end(); it != ie; ++it) { |
| 235 | const Arg *A = *it; |
| 236 | A->claim(); |
| 237 | bool enable = (A->getOption().getID() == OPT_analyzer_checker); |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 238 | // We can have a list of comma separated checker names, e.g: |
| 239 | // '-analyzer-checker=cocoa,unix' |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 240 | StringRef checkerList = A->getValue(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 241 | SmallVector<StringRef, 4> checkers; |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 242 | checkerList.split(checkers, ","); |
| 243 | for (unsigned i = 0, e = checkers.size(); i != e; ++i) |
| 244 | Opts.CheckersControlList.push_back(std::make_pair(checkers[i], enable)); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 245 | } |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 246 | |
| 247 | // Go through the analyzer configuration options. |
| 248 | for (arg_iterator it = Args.filtered_begin(OPT_analyzer_config), |
| 249 | ie = Args.filtered_end(); it != ie; ++it) { |
| 250 | const Arg *A = *it; |
| 251 | A->claim(); |
| 252 | // We can have a list of comma separated config names, e.g: |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 253 | // '-analyzer-config key1=val1,key2=val2' |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 254 | StringRef configList = A->getValue(); |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 255 | SmallVector<StringRef, 4> configVals; |
| 256 | configList.split(configVals, ","); |
| 257 | for (unsigned i = 0, e = configVals.size(); i != e; ++i) { |
| 258 | StringRef key, val; |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 259 | llvm::tie(key, val) = configVals[i].split("="); |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 260 | if (val.empty()) { |
| 261 | Diags.Report(SourceLocation(), |
| 262 | diag::err_analyzer_config_no_value) << configVals[i]; |
| 263 | Success = false; |
| 264 | break; |
| 265 | } |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 266 | if (val.find('=') != StringRef::npos) { |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 267 | Diags.Report(SourceLocation(), |
| 268 | diag::err_analyzer_config_multiple_values) |
| 269 | << configVals[i]; |
| 270 | Success = false; |
| 271 | break; |
| 272 | } |
| 273 | Opts.Config[key] = val; |
| 274 | } |
| 275 | } |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 276 | |
| 277 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 280 | static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) { |
| 281 | Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error); |
Fariborz Jahanian | bbdfad5 | 2012-01-26 20:57:58 +0000 | [diff] [blame] | 282 | Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal); |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 283 | return true; |
| 284 | } |
| 285 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 286 | static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 287 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 288 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 289 | bool Success = true; |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 290 | |
Aaron Ballman | e6cc51d | 2012-02-06 00:40:31 +0000 | [diff] [blame] | 291 | unsigned OptLevel = getOptimizationLevel(Args, IK, Diags); |
| 292 | if (OptLevel > 3) { |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 293 | Diags.Report(diag::err_drv_invalid_value) |
Aaron Ballman | e6cc51d | 2012-02-06 00:40:31 +0000 | [diff] [blame] | 294 | << Args.getLastArg(OPT_O)->getAsString(Args) << OptLevel; |
| 295 | OptLevel = 3; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 296 | Success = false; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 297 | } |
Aaron Ballman | e6cc51d | 2012-02-06 00:40:31 +0000 | [diff] [blame] | 298 | Opts.OptimizationLevel = OptLevel; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 299 | |
| 300 | // We must always run at least the always inlining pass. |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 301 | Opts.setInlining( |
| 302 | (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining |
| 303 | : CodeGenOptions::OnlyAlwaysInlining); |
Chad Rosier | 634a4b1 | 2012-03-06 21:17:19 +0000 | [diff] [blame] | 304 | // -fno-inline-functions overrides OptimizationLevel > 1. |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 305 | Opts.NoInline = Args.hasArg(OPT_fno_inline); |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 306 | Opts.setInlining(Args.hasArg(OPT_fno_inline_functions) ? |
| 307 | CodeGenOptions::OnlyAlwaysInlining : Opts.getInlining()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 308 | |
Alexey Samsonov | fd00eec | 2012-05-04 07:39:27 +0000 | [diff] [blame] | 309 | if (Args.hasArg(OPT_gline_tables_only)) { |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 310 | Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly); |
Alexey Samsonov | fd00eec | 2012-05-04 07:39:27 +0000 | [diff] [blame] | 311 | } else if (Args.hasArg(OPT_g_Flag)) { |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 312 | if (Args.hasFlag(OPT_flimit_debug_info, OPT_fno_limit_debug_info, true)) |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 313 | Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo); |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 314 | else |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 315 | Opts.setDebugInfo(CodeGenOptions::FullDebugInfo); |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 316 | } |
Eric Christopher | da3301e | 2012-10-18 21:52:18 +0000 | [diff] [blame] | 317 | Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info); |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 318 | |
Douglas Gregor | f43b721 | 2013-01-16 01:23:41 +0000 | [diff] [blame] | 319 | Opts.ModulesAutolink = Args.hasArg(OPT_fmodules_autolink); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 320 | Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); |
| 321 | Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 322 | Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); |
Daniel Dunbar | e26bdb9 | 2011-06-21 18:54:46 +0000 | [diff] [blame] | 323 | Opts.UseRegisterSizedBitfieldAccess = Args.hasArg( |
| 324 | OPT_fuse_register_sized_bitfield_access); |
Dan Gohman | 4d5625e | 2010-10-14 22:36:56 +0000 | [diff] [blame] | 325 | Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 326 | Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 327 | Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants); |
| 328 | Opts.NoCommon = Args.hasArg(OPT_fno_common); |
| 329 | Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 330 | Opts.OptimizeSize = getOptimizationLevelSize(Args, IK, Diags); |
Daniel Dunbar | 6b0cf67 | 2010-06-07 23:19:17 +0000 | [diff] [blame] | 331 | Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) || |
| 332 | Args.hasArg(OPT_ffreestanding)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 333 | Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) || |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 334 | (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 335 | |
| 336 | Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 337 | Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); |
Peter Collingbourne | d51e43a | 2011-10-06 18:29:46 +0000 | [diff] [blame] | 338 | Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device); |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 339 | Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit); |
| 340 | Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 341 | Opts.CodeModel = Args.getLastArgValue(OPT_mcode_model); |
| 342 | Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 343 | Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim); |
Nick Lewycky | 1db772b | 2012-01-23 08:29:12 +0000 | [diff] [blame] | 344 | Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 345 | Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); |
John McCall | 279b5eb | 2010-08-12 23:36:15 +0000 | [diff] [blame] | 346 | Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables); |
Peter Collingbourne | 4400cb8 | 2010-12-04 01:51:33 +0000 | [diff] [blame] | 347 | Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 348 | Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); |
Daniel Dunbar | 001f628 | 2011-12-09 23:41:18 +0000 | [diff] [blame] | 349 | Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) || |
| 350 | Args.hasArg(OPT_cl_finite_math_only)|| |
| 351 | Args.hasArg(OPT_cl_fast_relaxed_math)); |
| 352 | Opts.NoNaNsFPMath = (Args.hasArg(OPT_menable_no_nans) || |
| 353 | Args.hasArg(OPT_cl_finite_math_only)|| |
| 354 | Args.hasArg(OPT_cl_fast_relaxed_math)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 355 | Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 356 | Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option); |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 357 | Opts.NumRegisterParameters = Args.getLastArgIntValue(OPT_mregparm, 0, Diags); |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 358 | Opts.NoGlobalMerge = Args.hasArg(OPT_mno_global_merge); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 359 | Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); |
Daniel Dunbar | 4ecc9b7 | 2010-05-27 05:39:39 +0000 | [diff] [blame] | 360 | Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 361 | Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 362 | Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); |
Rafael Espindola | f24a151 | 2011-04-30 18:35:43 +0000 | [diff] [blame] | 363 | Opts.NoDwarf2CFIAsm = Args.hasArg(OPT_fno_dwarf2_cfi_asm); |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 364 | Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 365 | Opts.SoftFloat = Args.hasArg(OPT_msoft_float); |
Chandler Carruth | 82fe6ae | 2012-03-27 23:58:37 +0000 | [diff] [blame] | 366 | Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 367 | Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) || |
| 368 | Args.hasArg(OPT_cl_unsafe_math_optimizations) || |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 369 | Args.hasArg(OPT_cl_fast_relaxed_math); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 370 | Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 371 | Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); |
Bob Wilson | 71fd6cc | 2012-02-03 06:27:22 +0000 | [diff] [blame] | 372 | Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ); |
Rafael Espindola | 8af669f | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 373 | Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 374 | |
Chris Lattner | bbea716 | 2010-04-13 00:38:24 +0000 | [diff] [blame] | 375 | Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections); |
| 376 | Opts.DataSections = Args.hasArg(OPT_fdata_sections); |
| 377 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 378 | Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); |
John McCall | 824e19e | 2010-02-12 23:47:27 +0000 | [diff] [blame] | 379 | Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier); |
Will Dietz | 2d382d1 | 2012-12-30 20:53:28 +0000 | [diff] [blame] | 380 | Opts.SanitizeRecover = !Args.hasArg(OPT_fno_sanitize_recover); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 381 | |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 382 | Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 383 | Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 384 | Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); |
| 385 | Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); |
Tanya Lattner | 198871c | 2012-07-11 23:02:10 +0000 | [diff] [blame] | 386 | Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); |
Nick Lewycky | 3dc0541 | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 387 | Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 388 | Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); |
Peter Collingbourne | 22a7dfe | 2011-10-30 17:30:44 +0000 | [diff] [blame] | 389 | Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file); |
Alexey Samsonov | 91ecfa6 | 2012-12-03 19:12:58 +0000 | [diff] [blame] | 390 | Opts.SanitizerBlacklistFile = Args.getLastArgValue(OPT_fsanitize_blacklist); |
Alexey Samsonov | 4bdc604 | 2013-01-20 13:12:12 +0000 | [diff] [blame] | 391 | Opts.SanitizeMemoryTrackOrigins = |
Evgeniy Stepanov | 34ef11b | 2012-12-24 08:42:34 +0000 | [diff] [blame] | 392 | Args.hasArg(OPT_fsanitize_memory_track_origins); |
Alexey Samsonov | 4bdc604 | 2013-01-20 13:12:12 +0000 | [diff] [blame] | 393 | Opts.SanitizeAddressZeroBaseShadow = |
| 394 | Args.hasArg(OPT_fsanitize_address_zero_base_shadow); |
Chad Rosier | 78d85b1 | 2013-01-29 23:31:22 +0000 | [diff] [blame] | 395 | Opts.SanitizeUndefinedTrapOnError = |
| 396 | Args.hasArg(OPT_fsanitize_undefined_trap_on_error); |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 397 | Opts.SSPBufferSize = |
| 398 | Args.getLastArgIntValue(OPT_stack_protector_buffer_size, 8, Diags); |
Nick Lewycky | 4e785c9 | 2011-12-06 03:33:03 +0000 | [diff] [blame] | 399 | Opts.StackRealignment = Args.hasArg(OPT_mstackrealign); |
Joerg Sonnenberger | e9d11db | 2011-12-05 23:05:23 +0000 | [diff] [blame] | 400 | if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 401 | StringRef Val = A->getValue(); |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 402 | unsigned StackAlignment = Opts.StackAlignment; |
| 403 | Val.getAsInteger(10, StackAlignment); |
| 404 | Opts.StackAlignment = StackAlignment; |
Joerg Sonnenberger | e9d11db | 2011-12-05 23:05:23 +0000 | [diff] [blame] | 405 | } |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 406 | |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 407 | if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 408 | StringRef Name = A->getValue(); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 409 | unsigned Method = llvm::StringSwitch<unsigned>(Name) |
| 410 | .Case("legacy", CodeGenOptions::Legacy) |
| 411 | .Case("non-legacy", CodeGenOptions::NonLegacy) |
| 412 | .Case("mixed", CodeGenOptions::Mixed) |
| 413 | .Default(~0U); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 414 | if (Method == ~0U) { |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 415 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 416 | Success = false; |
| 417 | } else { |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 418 | Opts.setObjCDispatchMethod( |
| 419 | static_cast<CodeGenOptions::ObjCDispatchMethodKind>(Method)); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 420 | } |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 421 | } |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 422 | |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 423 | if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 424 | StringRef Name = A->getValue(); |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 425 | unsigned Model = llvm::StringSwitch<unsigned>(Name) |
| 426 | .Case("global-dynamic", CodeGenOptions::GeneralDynamicTLSModel) |
| 427 | .Case("local-dynamic", CodeGenOptions::LocalDynamicTLSModel) |
| 428 | .Case("initial-exec", CodeGenOptions::InitialExecTLSModel) |
| 429 | .Case("local-exec", CodeGenOptions::LocalExecTLSModel) |
| 430 | .Default(~0U); |
| 431 | if (Model == ~0U) { |
| 432 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 433 | Success = false; |
| 434 | } else { |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 435 | Opts.setDefaultTLSModel(static_cast<CodeGenOptions::TLSModel>(Model)); |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
Lang Hames | 931c083 | 2012-11-15 07:51:26 +0000 | [diff] [blame] | 439 | if (Arg *A = Args.getLastArg(OPT_ffp_contract)) { |
| 440 | StringRef Val = A->getValue(); |
| 441 | if (Val == "fast") |
| 442 | Opts.setFPContractMode(CodeGenOptions::FPC_Fast); |
| 443 | else if (Val == "on") |
| 444 | Opts.setFPContractMode(CodeGenOptions::FPC_On); |
| 445 | else if (Val == "off") |
| 446 | Opts.setFPContractMode(CodeGenOptions::FPC_Off); |
| 447 | else |
| 448 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; |
| 449 | } |
| 450 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 451 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, |
| 455 | ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 456 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 457 | Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file); |
| 458 | Opts.Targets = Args.getAllArgValues(OPT_MT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 459 | Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps); |
| 460 | Opts.UsePhonyTargets = Args.hasArg(OPT_MP); |
Daniel Dunbar | eef63e0 | 2011-02-02 15:41:17 +0000 | [diff] [blame] | 461 | Opts.ShowHeaderIncludes = Args.hasArg(OPT_H); |
Daniel Dunbar | b34d69b | 2011-02-02 21:11:31 +0000 | [diff] [blame] | 462 | Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file); |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 463 | Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG); |
Douglas Gregor | 773303a | 2012-02-02 23:45:13 +0000 | [diff] [blame] | 464 | Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 467 | bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, |
| 468 | DiagnosticsEngine *Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 469 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 470 | bool Success = true; |
| 471 | |
Daniel Dunbar | 08c6695 | 2011-04-07 18:11:14 +0000 | [diff] [blame] | 472 | Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file); |
Ted Kremenek | 7800212 | 2011-10-29 00:12:39 +0000 | [diff] [blame] | 473 | Opts.DiagnosticSerializationFile = |
| 474 | Args.getLastArgValue(OPT_diagnostic_serialized_file); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 475 | Opts.IgnoreWarnings = Args.hasArg(OPT_w); |
| 476 | Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros); |
| 477 | Opts.Pedantic = Args.hasArg(OPT_pedantic); |
| 478 | Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors); |
| 479 | Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics); |
| 480 | Opts.ShowColors = Args.hasArg(OPT_fcolor_diagnostics); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 481 | Opts.ShowColumn = Args.hasFlag(OPT_fshow_column, |
| 482 | OPT_fno_show_column, |
| 483 | /*Default=*/true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 484 | Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); |
| 485 | Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); |
| 486 | Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 487 | |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 488 | // Default behavior is to not to show note include stacks. |
| 489 | Opts.ShowNoteIncludeStack = false; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 490 | if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack, |
| 491 | OPT_fno_diagnostics_show_note_include_stack)) |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 492 | if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack)) |
| 493 | Opts.ShowNoteIncludeStack = true; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 494 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 495 | StringRef ShowOverloads = |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 496 | Args.getLastArgValue(OPT_fshow_overloads_EQ, "all"); |
| 497 | if (ShowOverloads == "best") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 498 | Opts.setShowOverloads(Ovl_Best); |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 499 | else if (ShowOverloads == "all") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 500 | Opts.setShowOverloads(Ovl_All); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 501 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 502 | Success = false; |
| 503 | if (Diags) |
| 504 | Diags->Report(diag::err_drv_invalid_value) |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 505 | << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args) |
| 506 | << ShowOverloads; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 507 | } |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 508 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 509 | StringRef ShowCategory = |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 510 | Args.getLastArgValue(OPT_fdiagnostics_show_category, "none"); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 511 | if (ShowCategory == "none") |
| 512 | Opts.ShowCategories = 0; |
| 513 | else if (ShowCategory == "id") |
| 514 | Opts.ShowCategories = 1; |
| 515 | else if (ShowCategory == "name") |
| 516 | Opts.ShowCategories = 2; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 517 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 518 | Success = false; |
| 519 | if (Diags) |
| 520 | Diags->Report(diag::err_drv_invalid_value) |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 521 | << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) |
| 522 | << ShowCategory; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 523 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 524 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 525 | StringRef Format = |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 526 | Args.getLastArgValue(OPT_fdiagnostics_format, "clang"); |
| 527 | if (Format == "clang") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 528 | Opts.setFormat(DiagnosticOptions::Clang); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 529 | else if (Format == "msvc") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 530 | Opts.setFormat(DiagnosticOptions::Msvc); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 531 | else if (Format == "vi") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 532 | Opts.setFormat(DiagnosticOptions::Vi); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 533 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 534 | Success = false; |
| 535 | if (Diags) |
| 536 | Diags->Report(diag::err_drv_invalid_value) |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 537 | << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) |
| 538 | << Format; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 539 | } |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 540 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 541 | Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 542 | Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); |
Richard Smith | 62221b1 | 2012-11-14 23:55:25 +0000 | [diff] [blame] | 543 | Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 544 | Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); |
Richard Trieu | 246b6aa | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 545 | Opts.ElideType = !Args.hasArg(OPT_fno_elide_type); |
| 546 | Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 547 | Opts.ErrorLimit = Args.getLastArgIntValue(OPT_ferror_limit, 0, Diags); |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 548 | Opts.MacroBacktraceLimit |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 549 | = Args.getLastArgIntValue(OPT_fmacro_backtrace_limit, |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 550 | DiagnosticOptions::DefaultMacroBacktraceLimit, Diags); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 551 | Opts.TemplateBacktraceLimit |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 552 | = Args.getLastArgIntValue(OPT_ftemplate_backtrace_limit, |
| 553 | DiagnosticOptions::DefaultTemplateBacktraceLimit, |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 554 | Diags); |
Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 555 | Opts.ConstexprBacktraceLimit |
| 556 | = Args.getLastArgIntValue(OPT_fconstexpr_backtrace_limit, |
| 557 | DiagnosticOptions::DefaultConstexprBacktraceLimit, |
| 558 | Diags); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 559 | Opts.TabStop = Args.getLastArgIntValue(OPT_ftabstop, |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 560 | DiagnosticOptions::DefaultTabStop, Diags); |
| 561 | if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) { |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 562 | Opts.TabStop = DiagnosticOptions::DefaultTabStop; |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 563 | if (Diags) |
| 564 | Diags->Report(diag::warn_ignoring_ftabstop_value) |
| 565 | << Opts.TabStop << DiagnosticOptions::DefaultTabStop; |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 566 | } |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 567 | Opts.MessageLength = Args.getLastArgIntValue(OPT_fmessage_length, 0, Diags); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 568 | addWarningArgs(Args, Opts.Warnings); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 569 | |
| 570 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 573 | static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) { |
| 574 | Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory); |
| 575 | } |
| 576 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 577 | static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 578 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 579 | using namespace options; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 580 | Opts.ProgramAction = frontend::ParseSyntaxOnly; |
| 581 | if (const Arg *A = Args.getLastArg(OPT_Action_Group)) { |
| 582 | switch (A->getOption().getID()) { |
| 583 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 584 | llvm_unreachable("Invalid option in group!"); |
Alexander Kornienko | 171af64 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 585 | case OPT_ast_list: |
| 586 | Opts.ProgramAction = frontend::ASTDeclList; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 587 | case OPT_ast_dump: |
| 588 | Opts.ProgramAction = frontend::ASTDump; break; |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 589 | case OPT_ast_dump_xml: |
| 590 | Opts.ProgramAction = frontend::ASTDumpXML; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 591 | case OPT_ast_print: |
| 592 | Opts.ProgramAction = frontend::ASTPrint; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 593 | case OPT_ast_view: |
| 594 | Opts.ProgramAction = frontend::ASTView; break; |
| 595 | case OPT_dump_raw_tokens: |
| 596 | Opts.ProgramAction = frontend::DumpRawTokens; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 597 | case OPT_dump_tokens: |
| 598 | Opts.ProgramAction = frontend::DumpTokens; break; |
| 599 | case OPT_S: |
| 600 | Opts.ProgramAction = frontend::EmitAssembly; break; |
| 601 | case OPT_emit_llvm_bc: |
| 602 | Opts.ProgramAction = frontend::EmitBC; break; |
| 603 | case OPT_emit_html: |
| 604 | Opts.ProgramAction = frontend::EmitHTML; break; |
| 605 | case OPT_emit_llvm: |
| 606 | Opts.ProgramAction = frontend::EmitLLVM; break; |
| 607 | case OPT_emit_llvm_only: |
| 608 | Opts.ProgramAction = frontend::EmitLLVMOnly; break; |
Daniel Dunbar | 32148ce | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 609 | case OPT_emit_codegen_only: |
| 610 | Opts.ProgramAction = frontend::EmitCodeGenOnly; break; |
Daniel Dunbar | da1573f | 2010-02-03 01:18:43 +0000 | [diff] [blame] | 611 | case OPT_emit_obj: |
| 612 | Opts.ProgramAction = frontend::EmitObj; break; |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 613 | case OPT_fixit_EQ: |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 614 | Opts.FixItSuffix = A->getValue(); |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 615 | // fall-through! |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 616 | case OPT_fixit: |
| 617 | Opts.ProgramAction = frontend::FixIt; break; |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 618 | case OPT_emit_module: |
| 619 | Opts.ProgramAction = frontend::GenerateModule; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 620 | case OPT_emit_pch: |
| 621 | Opts.ProgramAction = frontend::GeneratePCH; break; |
| 622 | case OPT_emit_pth: |
| 623 | Opts.ProgramAction = frontend::GeneratePTH; break; |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 624 | case OPT_init_only: |
| 625 | Opts.ProgramAction = frontend::InitOnly; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 626 | case OPT_fsyntax_only: |
| 627 | Opts.ProgramAction = frontend::ParseSyntaxOnly; break; |
| 628 | case OPT_print_decl_contexts: |
| 629 | Opts.ProgramAction = frontend::PrintDeclContext; break; |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 630 | case OPT_print_preamble: |
| 631 | Opts.ProgramAction = frontend::PrintPreamble; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 632 | case OPT_E: |
| 633 | Opts.ProgramAction = frontend::PrintPreprocessedInput; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 634 | case OPT_rewrite_macros: |
| 635 | Opts.ProgramAction = frontend::RewriteMacros; break; |
| 636 | case OPT_rewrite_objc: |
| 637 | Opts.ProgramAction = frontend::RewriteObjC; break; |
| 638 | case OPT_rewrite_test: |
| 639 | Opts.ProgramAction = frontend::RewriteTest; break; |
| 640 | case OPT_analyze: |
| 641 | Opts.ProgramAction = frontend::RunAnalysis; break; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 642 | case OPT_migrate: |
| 643 | Opts.ProgramAction = frontend::MigrateSource; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 644 | case OPT_Eonly: |
| 645 | Opts.ProgramAction = frontend::RunPreprocessorOnly; break; |
| 646 | } |
| 647 | } |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 648 | |
| 649 | if (const Arg* A = Args.getLastArg(OPT_plugin)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 650 | Opts.Plugins.push_back(A->getValue(0)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 651 | Opts.ProgramAction = frontend::PluginAction; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 652 | Opts.ActionName = A->getValue(); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 653 | |
| 654 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 655 | end = Args.filtered_end(); it != end; ++it) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 656 | if ((*it)->getValue(0) == Opts.ActionName) |
| 657 | Opts.PluginArgs.push_back((*it)->getValue(1)); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 658 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 661 | Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 662 | Opts.AddPluginArgs.resize(Opts.AddPluginActions.size()); |
| 663 | for (int i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) { |
| 664 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 665 | end = Args.filtered_end(); it != end; ++it) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 666 | if ((*it)->getValue(0) == Opts.AddPluginActions[i]) |
| 667 | Opts.AddPluginArgs[i].push_back((*it)->getValue(1)); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 668 | } |
| 669 | } |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 670 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 671 | if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) { |
| 672 | Opts.CodeCompletionAt = |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 673 | ParsedSourceLocation::FromString(A->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 674 | if (Opts.CodeCompletionAt.FileName.empty()) |
| 675 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 676 | << A->getAsString(Args) << A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 677 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 678 | Opts.DisableFree = Args.hasArg(OPT_disable_free); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 679 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 680 | Opts.OutputFile = Args.getLastArgValue(OPT_o); |
| 681 | Opts.Plugins = Args.getAllArgValues(OPT_load); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 682 | Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 683 | Opts.ShowHelp = Args.hasArg(OPT_help); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 684 | Opts.ShowStats = Args.hasArg(OPT_print_stats); |
| 685 | Opts.ShowTimers = Args.hasArg(OPT_ftime_report); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 686 | Opts.ShowVersion = Args.hasArg(OPT_version); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 687 | Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge); |
| 688 | Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); |
Nick Lewycky | 1450f26 | 2010-08-13 17:31:00 +0000 | [diff] [blame] | 689 | Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can); |
Argyrios Kyrtzidis | 61d679a | 2012-01-26 02:40:48 +0000 | [diff] [blame] | 690 | Opts.FixOnlyWarnings = Args.hasArg(OPT_fix_only_warnings); |
| 691 | Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile); |
| 692 | Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp); |
Alexander Kornienko | e34a052 | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 693 | Opts.ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter); |
Douglas Gregor | 20c6f2e | 2013-01-28 18:38:02 +0000 | [diff] [blame] | 694 | Opts.UseGlobalModuleIndex = !Args.hasArg(OPT_fno_modules_global_index); |
Douglas Gregor | f575d6e | 2013-01-25 00:45:27 +0000 | [diff] [blame] | 695 | Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex; |
Douglas Gregor | a6b00fc | 2013-01-23 22:38:11 +0000 | [diff] [blame] | 696 | |
Dmitri Gribenko | d99ef53 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 697 | Opts.CodeCompleteOpts.IncludeMacros |
| 698 | = Args.hasArg(OPT_code_completion_macros); |
| 699 | Opts.CodeCompleteOpts.IncludeCodePatterns |
| 700 | = Args.hasArg(OPT_code_completion_patterns); |
| 701 | Opts.CodeCompleteOpts.IncludeGlobals |
| 702 | = !Args.hasArg(OPT_no_code_completion_globals); |
| 703 | Opts.CodeCompleteOpts.IncludeBriefComments |
| 704 | = Args.hasArg(OPT_code_completion_brief_comments); |
| 705 | |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 706 | Opts.OverrideRecordLayoutsFile |
| 707 | = Args.getLastArgValue(OPT_foverride_record_layout_EQ); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 708 | if (const Arg *A = Args.getLastArg(OPT_arcmt_check, |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 709 | OPT_arcmt_modify, |
| 710 | OPT_arcmt_migrate)) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 711 | switch (A->getOption().getID()) { |
| 712 | default: |
| 713 | llvm_unreachable("missed a case"); |
| 714 | case OPT_arcmt_check: |
| 715 | Opts.ARCMTAction = FrontendOptions::ARCMT_Check; |
| 716 | break; |
| 717 | case OPT_arcmt_modify: |
| 718 | Opts.ARCMTAction = FrontendOptions::ARCMT_Modify; |
| 719 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 720 | case OPT_arcmt_migrate: |
| 721 | Opts.ARCMTAction = FrontendOptions::ARCMT_Migrate; |
| 722 | break; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 723 | } |
| 724 | } |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 725 | Opts.MTMigrateDir = Args.getLastArgValue(OPT_mt_migrate_directory); |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 726 | Opts.ARCMTMigrateReportOut |
| 727 | = Args.getLastArgValue(OPT_arcmt_migrate_report_output); |
| 728 | Opts.ARCMTMigrateEmitARCErrors |
| 729 | = Args.hasArg(OPT_arcmt_migrate_emit_arc_errors); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 730 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 731 | if (Args.hasArg(OPT_objcmt_migrate_literals)) |
| 732 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Literals; |
| 733 | if (Args.hasArg(OPT_objcmt_migrate_subscripting)) |
| 734 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Subscripting; |
| 735 | |
| 736 | if (Opts.ARCMTAction != FrontendOptions::ARCMT_None && |
| 737 | Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) { |
| 738 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 739 | << "ARC migration" << "ObjC migration"; |
| 740 | } |
| 741 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 742 | InputKind DashX = IK_None; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 743 | if (const Arg *A = Args.getLastArg(OPT_x)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 744 | DashX = llvm::StringSwitch<InputKind>(A->getValue()) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 745 | .Case("c", IK_C) |
| 746 | .Case("cl", IK_OpenCL) |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 747 | .Case("cuda", IK_CUDA) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 748 | .Case("c++", IK_CXX) |
| 749 | .Case("objective-c", IK_ObjC) |
| 750 | .Case("objective-c++", IK_ObjCXX) |
| 751 | .Case("cpp-output", IK_PreprocessedC) |
| 752 | .Case("assembler-with-cpp", IK_Asm) |
| 753 | .Case("c++-cpp-output", IK_PreprocessedCXX) |
| 754 | .Case("objective-c-cpp-output", IK_PreprocessedObjC) |
Chris Lattner | 919f2ca | 2011-04-09 07:09:31 +0000 | [diff] [blame] | 755 | .Case("objc-cpp-output", IK_PreprocessedObjC) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 756 | .Case("objective-c++-cpp-output", IK_PreprocessedObjCXX) |
Nico Weber | 1f7957d | 2011-08-13 19:03:50 +0000 | [diff] [blame] | 757 | .Case("objc++-cpp-output", IK_PreprocessedObjCXX) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 758 | .Case("c-header", IK_C) |
Peter Collingbourne | ae57ead | 2011-10-09 22:03:19 +0000 | [diff] [blame] | 759 | .Case("cl-header", IK_OpenCL) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 760 | .Case("objective-c-header", IK_ObjC) |
| 761 | .Case("c++-header", IK_CXX) |
| 762 | .Case("objective-c++-header", IK_ObjCXX) |
| 763 | .Case("ast", IK_AST) |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 764 | .Case("ir", IK_LLVM_IR) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 765 | .Default(IK_None); |
| 766 | if (DashX == IK_None) |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 767 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 768 | << A->getAsString(Args) << A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | // '-' is the default input if none is given. |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 772 | std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 773 | Opts.Inputs.clear(); |
| 774 | if (Inputs.empty()) |
| 775 | Inputs.push_back("-"); |
| 776 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 777 | InputKind IK = DashX; |
| 778 | if (IK == IK_None) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 779 | IK = FrontendOptions::getInputKindForExtension( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 780 | StringRef(Inputs[i]).rsplit('.').second); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 781 | // FIXME: Remove this hack. |
| 782 | if (i == 0) |
| 783 | DashX = IK; |
| 784 | } |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 785 | Opts.Inputs.push_back(FrontendInputFile(Inputs[i], IK)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | return DashX; |
| 789 | } |
| 790 | |
Daniel Dunbar | 8b9adfe | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 791 | std::string CompilerInvocation::GetResourcesPath(const char *Argv0, |
| 792 | void *MainAddr) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 793 | llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); |
| 794 | |
| 795 | if (!P.isEmpty()) { |
| 796 | P.eraseComponent(); // Remove /clang from foo/bin/clang |
| 797 | P.eraseComponent(); // Remove /bin from foo/bin |
| 798 | |
| 799 | // Get foo/lib/clang/<version>/include |
| 800 | P.appendComponent("lib"); |
| 801 | P.appendComponent("clang"); |
| 802 | P.appendComponent(CLANG_VERSION_STRING); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | return P.str(); |
| 806 | } |
| 807 | |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 808 | static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 809 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 810 | Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 811 | Opts.Verbose = Args.hasArg(OPT_v); |
Francois Pichet | c91562c | 2011-10-10 20:34:10 +0000 | [diff] [blame] | 812 | Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 813 | Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 814 | Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx); |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 815 | if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 816 | Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 817 | Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir); |
Douglas Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 818 | Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodule_cache_path); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 819 | Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash); |
Douglas Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 820 | |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 821 | // Add -I..., -F..., and -index-header-map options in order. |
| 822 | bool IsIndexHeaderMap = false; |
| 823 | for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F, |
| 824 | OPT_index_header_map), |
| 825 | ie = Args.filtered_end(); it != ie; ++it) { |
| 826 | if ((*it)->getOption().matches(OPT_index_header_map)) { |
| 827 | // -index-header-map applies to the next -I or -F. |
| 828 | IsIndexHeaderMap = true; |
| 829 | continue; |
| 830 | } |
| 831 | |
| 832 | frontend::IncludeDirGroup Group |
| 833 | = IsIndexHeaderMap? frontend::IndexHeaderMap : frontend::Angled; |
| 834 | |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 835 | Opts.AddPath((*it)->getValue(), Group, |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame^] | 836 | /*IsFramework=*/ (*it)->getOption().matches(OPT_F), true); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 837 | IsIndexHeaderMap = false; |
| 838 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 839 | |
Daniel Dunbar | f3fc21f | 2013-01-25 01:50:34 +0000 | [diff] [blame] | 840 | // Add -iprefix/-iwithprefix/-iwithprefixbefore options. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 841 | StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 842 | for (arg_iterator it = Args.filtered_begin(OPT_iprefix, OPT_iwithprefix, |
| 843 | OPT_iwithprefixbefore), |
| 844 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 845 | const Arg *A = *it; |
| 846 | if (A->getOption().matches(OPT_iprefix)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 847 | Prefix = A->getValue(); |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 848 | else if (A->getOption().matches(OPT_iwithprefix)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 849 | Opts.AddPath(Prefix.str() + A->getValue(), |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame^] | 850 | frontend::After, false, true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 851 | else |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 852 | Opts.AddPath(Prefix.str() + A->getValue(), |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame^] | 853 | frontend::Angled, false, true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | for (arg_iterator it = Args.filtered_begin(OPT_idirafter), |
| 857 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame^] | 858 | Opts.AddPath((*it)->getValue(), frontend::After, false, true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 859 | for (arg_iterator it = Args.filtered_begin(OPT_iquote), |
| 860 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame^] | 861 | Opts.AddPath((*it)->getValue(), frontend::Quoted, false, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 862 | for (arg_iterator it = Args.filtered_begin(OPT_isystem, |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 863 | OPT_iwithsysroot), ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 864 | Opts.AddPath((*it)->getValue(), frontend::System, false, |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 865 | !(*it)->getOption().matches(OPT_iwithsysroot)); |
Daniel Dunbar | 024f4be | 2011-10-18 20:40:38 +0000 | [diff] [blame] | 866 | for (arg_iterator it = Args.filtered_begin(OPT_iframework), |
| 867 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 868 | Opts.AddPath((*it)->getValue(), frontend::System, true, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 869 | |
| 870 | // Add the paths for the various language specific isystem flags. |
| 871 | for (arg_iterator it = Args.filtered_begin(OPT_c_isystem), |
| 872 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 873 | Opts.AddPath((*it)->getValue(), frontend::CSystem, false, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 874 | for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem), |
| 875 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 876 | Opts.AddPath((*it)->getValue(), frontend::CXXSystem, false, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 877 | for (arg_iterator it = Args.filtered_begin(OPT_objc_isystem), |
| 878 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 879 | Opts.AddPath((*it)->getValue(), frontend::ObjCSystem, false,true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 880 | for (arg_iterator it = Args.filtered_begin(OPT_objcxx_isystem), |
| 881 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 882 | Opts.AddPath((*it)->getValue(), frontend::ObjCXXSystem, false, true); |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 883 | |
| 884 | // Add the internal paths from a driver that detects standard include paths. |
| 885 | for (arg_iterator I = Args.filtered_begin(OPT_internal_isystem, |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 886 | OPT_internal_externc_isystem), |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 887 | E = Args.filtered_end(); |
| 888 | I != E; ++I) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 889 | Opts.AddPath((*I)->getValue(), frontend::System, |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 890 | false, /*IgnoreSysRoot=*/true, /*IsInternal=*/true, |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 891 | (*I)->getOption().matches(OPT_internal_externc_isystem)); |
Richard Smith | f122a13 | 2012-06-13 20:27:03 +0000 | [diff] [blame] | 892 | |
| 893 | // Add the path prefixes which are implicitly treated as being system headers. |
| 894 | for (arg_iterator I = Args.filtered_begin(OPT_isystem_prefix, |
| 895 | OPT_ino_system_prefix), |
| 896 | E = Args.filtered_end(); |
| 897 | I != E; ++I) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 898 | Opts.AddSystemHeaderPrefix((*I)->getValue(), |
Richard Smith | f122a13 | 2012-06-13 20:27:03 +0000 | [diff] [blame] | 899 | (*I)->getOption().matches(OPT_isystem_prefix)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 902 | void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, |
| 903 | LangStandard::Kind LangStd) { |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 904 | // 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] | 905 | // to move these to the language standard, and have the driver resolve the |
| 906 | // input kind + language standard. |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 907 | if (IK == IK_Asm) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 908 | Opts.AsmPreprocessor = 1; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 909 | } else if (IK == IK_ObjC || |
| 910 | IK == IK_ObjCXX || |
| 911 | IK == IK_PreprocessedObjC || |
| 912 | IK == IK_PreprocessedObjCXX) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 913 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 914 | } |
| 915 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 916 | if (LangStd == LangStandard::lang_unspecified) { |
| 917 | // Based on the base language, pick one. |
| 918 | switch (IK) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 919 | case IK_None: |
| 920 | case IK_AST: |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 921 | case IK_LLVM_IR: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 922 | llvm_unreachable("Invalid input kind!"); |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 923 | case IK_OpenCL: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 924 | LangStd = LangStandard::lang_opencl; |
| 925 | break; |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 926 | case IK_CUDA: |
| 927 | LangStd = LangStandard::lang_cuda; |
| 928 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 929 | case IK_Asm: |
| 930 | case IK_C: |
| 931 | case IK_PreprocessedC: |
| 932 | case IK_ObjC: |
| 933 | case IK_PreprocessedObjC: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 934 | LangStd = LangStandard::lang_gnu99; |
| 935 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 936 | case IK_CXX: |
| 937 | case IK_PreprocessedCXX: |
| 938 | case IK_ObjCXX: |
| 939 | case IK_PreprocessedObjCXX: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 940 | LangStd = LangStandard::lang_gnucxx98; |
| 941 | break; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
Nico Weber | bb23628 | 2012-11-11 07:02:14 +0000 | [diff] [blame] | 946 | Opts.LineComment = Std.hasLineComments(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 947 | Opts.C99 = Std.isC99(); |
Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 948 | Opts.C11 = Std.isC11(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 949 | Opts.CPlusPlus = Std.isCPlusPlus(); |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 950 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); |
Richard Smith | 5ba49c0 | 2012-10-17 23:07:52 +0000 | [diff] [blame] | 951 | Opts.CPlusPlus1y = Std.isCPlusPlus1y(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 952 | Opts.Digraphs = Std.hasDigraphs(); |
| 953 | Opts.GNUMode = Std.isGNUMode(); |
| 954 | Opts.GNUInline = !Std.isC99(); |
| 955 | Opts.HexFloats = Std.hasHexFloats(); |
| 956 | Opts.ImplicitInt = Std.hasImplicitInt(); |
| 957 | |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 958 | // Set OpenCL Version. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 959 | if (LangStd == LangStandard::lang_opencl) { |
| 960 | Opts.OpenCL = 1; |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 961 | Opts.OpenCLVersion = 100; |
| 962 | } |
| 963 | else if (LangStd == LangStandard::lang_opencl11) { |
| 964 | Opts.OpenCL = 1; |
| 965 | Opts.OpenCLVersion = 110; |
| 966 | } |
| 967 | else if (LangStd == LangStandard::lang_opencl12) { |
| 968 | Opts.OpenCL = 1; |
| 969 | Opts.OpenCLVersion = 120; |
| 970 | } |
| 971 | |
| 972 | // OpenCL has some additional defaults. |
| 973 | if (Opts.OpenCL) { |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 974 | Opts.AltiVec = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 975 | Opts.CXXOperatorNames = 1; |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 976 | Opts.LaxVectorConversions = 0; |
Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 977 | Opts.DefaultFPContract = 1; |
Joey Gouly | 19dbb20 | 2013-01-23 11:56:20 +0000 | [diff] [blame] | 978 | Opts.NativeHalfType = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 981 | if (LangStd == LangStandard::lang_cuda) |
| 982 | Opts.CUDA = 1; |
| 983 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 984 | // OpenCL and C++ both have bool, true, false keywords. |
| 985 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
| 986 | |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 987 | // C++ has wchar_t keyword. |
| 988 | Opts.WChar = Opts.CPlusPlus; |
| 989 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 990 | Opts.GNUKeywords = Opts.GNUMode; |
| 991 | Opts.CXXOperatorNames = Opts.CPlusPlus; |
| 992 | |
| 993 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 994 | // is specified, or -std is set to a conforming mode. |
| 995 | Opts.Trigraphs = !Opts.GNUMode; |
| 996 | |
| 997 | Opts.DollarIdents = !Opts.AsmPreprocessor; |
| 998 | } |
| 999 | |
| 1000 | static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1001 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1002 | // FIXME: Cleanup per-file based stuff. |
| 1003 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 1004 | if (const Arg *A = Args.getLastArg(OPT_std_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1005 | LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1006 | #define LANGSTANDARD(id, name, desc, features) \ |
| 1007 | .Case(name, LangStandard::lang_##id) |
| 1008 | #include "clang/Frontend/LangStandards.def" |
| 1009 | .Default(LangStandard::lang_unspecified); |
| 1010 | if (LangStd == LangStandard::lang_unspecified) |
| 1011 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1012 | << A->getAsString(Args) << A->getValue(); |
Chad Rosier | b2dba4b | 2011-05-02 19:24:53 +0000 | [diff] [blame] | 1013 | else { |
| 1014 | // Valid standard, check to make sure language and standard are compatable. |
| 1015 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 1016 | switch (IK) { |
| 1017 | case IK_C: |
| 1018 | case IK_ObjC: |
| 1019 | case IK_PreprocessedC: |
| 1020 | case IK_PreprocessedObjC: |
| 1021 | if (!(Std.isC89() || Std.isC99())) |
| 1022 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1023 | << A->getAsString(Args) << "C/ObjC"; |
| 1024 | break; |
| 1025 | case IK_CXX: |
| 1026 | case IK_ObjCXX: |
| 1027 | case IK_PreprocessedCXX: |
| 1028 | case IK_PreprocessedObjCXX: |
| 1029 | if (!Std.isCPlusPlus()) |
| 1030 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1031 | << A->getAsString(Args) << "C++/ObjC++"; |
| 1032 | break; |
| 1033 | case IK_OpenCL: |
| 1034 | if (!Std.isC99()) |
| 1035 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1036 | << A->getAsString(Args) << "OpenCL"; |
| 1037 | break; |
| 1038 | case IK_CUDA: |
| 1039 | if (!Std.isCPlusPlus()) |
| 1040 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1041 | << A->getAsString(Args) << "CUDA"; |
| 1042 | break; |
| 1043 | default: |
| 1044 | break; |
| 1045 | } |
| 1046 | } |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1049 | // -cl-std only applies for OpenCL language standards. |
| 1050 | // Override the -std option in this case. |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1051 | if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1052 | LangStandard::Kind OpenCLLangStd |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1053 | = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1054 | .Case("CL", LangStandard::lang_opencl) |
| 1055 | .Case("CL1.1", LangStandard::lang_opencl11) |
| 1056 | .Case("CL1.2", LangStandard::lang_opencl12) |
| 1057 | .Default(LangStandard::lang_unspecified); |
| 1058 | |
| 1059 | if (OpenCLLangStd == LangStandard::lang_unspecified) { |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1060 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1061 | << A->getAsString(Args) << A->getValue(); |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1062 | } |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1063 | else |
| 1064 | LangStd = OpenCLLangStd; |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1065 | } |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1066 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1067 | CompilerInvocation::setLangDefaults(Opts, IK, LangStd); |
| 1068 | |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1069 | // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension |
| 1070 | // keywords. This behavior is provided by GCC's poorly named '-fasm' flag, |
| 1071 | // while a subset (the non-C++ GNU keywords) is provided by GCC's |
| 1072 | // '-fgnu-keywords'. Clang conflates the two for simplicity under the single |
| 1073 | // name, as it doesn't seem a useful distinction. |
| 1074 | Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1075 | Opts.GNUKeywords); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1076 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1077 | if (Args.hasArg(OPT_fno_operator_names)) |
| 1078 | Opts.CXXOperatorNames = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1079 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1080 | if (Opts.ObjC1) { |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1081 | if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1082 | StringRef value = arg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1083 | if (Opts.ObjCRuntime.tryParse(value)) |
| 1084 | Diags.Report(diag::err_drv_unknown_objc_runtime) << value; |
| 1085 | } |
| 1086 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1087 | if (Args.hasArg(OPT_fobjc_gc_only)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1088 | Opts.setGC(LangOptions::GCOnly); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1089 | else if (Args.hasArg(OPT_fobjc_gc)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1090 | Opts.setGC(LangOptions::HybridGC); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1091 | else if (Args.hasArg(OPT_fobjc_arc)) { |
| 1092 | Opts.ObjCAutoRefCount = 1; |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1093 | if (!Opts.ObjCRuntime.allowsARC()) |
| 1094 | Diags.Report(diag::err_arc_unsupported_on_runtime); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1095 | |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1096 | // Only set ObjCARCWeak if ARC is enabled. |
| 1097 | if (Args.hasArg(OPT_fobjc_runtime_has_weak)) |
| 1098 | Opts.ObjCARCWeak = 1; |
| 1099 | else |
| 1100 | Opts.ObjCARCWeak = Opts.ObjCRuntime.allowsWeak(); |
| 1101 | } |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 1102 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1103 | if (Args.hasArg(OPT_fno_objc_infer_related_result_type)) |
| 1104 | Opts.ObjCInferRelatedResultType = 0; |
| 1105 | } |
| 1106 | |
Rafael Espindola | fb3f4aa | 2011-06-02 16:13:27 +0000 | [diff] [blame] | 1107 | if (Args.hasArg(OPT_fgnu89_inline)) |
| 1108 | Opts.GNUInline = 1; |
| 1109 | |
Fariborz Jahanian | 142f9e9 | 2011-02-04 00:01:24 +0000 | [diff] [blame] | 1110 | if (Args.hasArg(OPT_fapple_kext)) { |
| 1111 | if (!Opts.CPlusPlus) |
| 1112 | Diags.Report(diag::warn_c_kext); |
| 1113 | else |
| 1114 | Opts.AppleKext = 1; |
| 1115 | } |
| 1116 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1117 | if (Args.hasArg(OPT_print_ivar_layout)) |
| 1118 | Opts.ObjCGCBitmapPrint = 1; |
Fariborz Jahanian | 33e982b | 2010-04-22 20:26:39 +0000 | [diff] [blame] | 1119 | if (Args.hasArg(OPT_fno_constant_cfstrings)) |
| 1120 | Opts.NoConstantCFStrings = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1121 | |
| 1122 | if (Args.hasArg(OPT_faltivec)) |
| 1123 | Opts.AltiVec = 1; |
| 1124 | |
| 1125 | if (Args.hasArg(OPT_pthread)) |
| 1126 | Opts.POSIXThreads = 1; |
| 1127 | |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1128 | if (Args.hasArg(OPT_fdelayed_template_parsing)) |
| 1129 | Opts.DelayedTemplateParsing = 1; |
| 1130 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1131 | StringRef Vis = Args.getLastArgValue(OPT_fvisibility, "default"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1132 | if (Vis == "default") |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 1133 | Opts.setVisibilityMode(DefaultVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1134 | else if (Vis == "hidden") |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 1135 | Opts.setVisibilityMode(HiddenVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1136 | else if (Vis == "protected") |
John McCall | 4188760 | 2012-01-29 01:20:30 +0000 | [diff] [blame] | 1137 | // FIXME: diagnose if target does not support protected visibility |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 1138 | Opts.setVisibilityMode(ProtectedVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1139 | else |
| 1140 | Diags.Report(diag::err_drv_invalid_value) |
| 1141 | << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; |
| 1142 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 1143 | if (Args.hasArg(OPT_fvisibility_inlines_hidden)) |
| 1144 | Opts.InlineVisibilityHidden = 1; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1145 | |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 1146 | if (Args.hasArg(OPT_ftrapv)) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1147 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 1148 | // Set the handler, if one is specified. |
| 1149 | Opts.OverflowHandler = |
| 1150 | Args.getLastArgValue(OPT_ftrapv_handler); |
| 1151 | } |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 1152 | else if (Args.hasArg(OPT_fwrapv)) |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1153 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1154 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1155 | if (Args.hasArg(OPT_trigraphs)) |
| 1156 | Opts.Trigraphs = 1; |
| 1157 | |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 1158 | Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, |
| 1159 | OPT_fno_dollars_in_identifiers, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1160 | Opts.DollarIdents); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1161 | Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); |
Douglas Gregor | 0bb935c | 2011-10-24 15:27:23 +0000 | [diff] [blame] | 1162 | Opts.MicrosoftExt |
| 1163 | = Args.hasArg(OPT_fms_extensions) || Args.hasArg(OPT_fms_compatibility); |
Francois Pichet | ae55608 | 2011-09-17 04:32:15 +0000 | [diff] [blame] | 1164 | Opts.MicrosoftMode = Args.hasArg(OPT_fms_compatibility); |
Chad Rosier | 4fb10d1 | 2012-12-05 23:35:10 +0000 | [diff] [blame] | 1165 | Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt; |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1166 | Opts.MSCVersion = Args.getLastArgIntValue(OPT_fmsc_version, 0, Diags); |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 1167 | Opts.Borland = Args.hasArg(OPT_fborland_extensions); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1168 | Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 1169 | Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings, |
| 1170 | Opts.ConstStrings); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1171 | if (Args.hasArg(OPT_fno_lax_vector_conversions)) |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 1172 | Opts.LaxVectorConversions = 0; |
| 1173 | if (Args.hasArg(OPT_fno_threadsafe_statics)) |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 1174 | Opts.ThreadsafeStatics = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1175 | Opts.Exceptions = Args.hasArg(OPT_fexceptions); |
Anders Carlsson | e9b801f | 2011-02-22 01:52:06 +0000 | [diff] [blame] | 1176 | Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 1177 | Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions); |
| 1178 | Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); |
Daniel Dunbar | 2ed4228 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 1179 | Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 1180 | |
Mike Stump | de05057 | 2009-12-02 18:57:08 +0000 | [diff] [blame] | 1181 | Opts.RTTI = !Args.hasArg(OPT_fno_rtti); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1182 | Opts.Blocks = Args.hasArg(OPT_fblocks); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 1183 | Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); |
Douglas Gregor | 752c74d | 2012-01-03 17:07:34 +0000 | [diff] [blame] | 1184 | Opts.Modules = Args.hasArg(OPT_fmodules); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1185 | Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char); |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 1186 | Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1187 | Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 1188 | Opts.ShortEnums = Args.hasArg(OPT_fshort_enums); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1189 | Opts.Freestanding = Args.hasArg(OPT_ffreestanding); |
| 1190 | Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 1191 | Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1192 | Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 1193 | Opts.AccessControl = !Args.hasArg(OPT_fno_access_control); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1194 | Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); |
Dan Gohman | c31176d | 2010-01-08 02:20:44 +0000 | [diff] [blame] | 1195 | Opts.MathErrno = Args.hasArg(OPT_fmath_errno); |
Douglas Gregor | 8f4783c | 2012-07-02 19:56:23 +0000 | [diff] [blame] | 1196 | Opts.InstantiationDepth = Args.getLastArgIntValue(OPT_ftemplate_depth, 512, |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 1197 | Diags); |
| 1198 | Opts.ConstexprCallDepth = Args.getLastArgIntValue(OPT_fconstexpr_depth, 512, |
| 1199 | Diags); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1200 | Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1201 | Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy_EQ, |
Argyrios Kyrtzidis | 3532fdd | 2010-11-17 23:11:54 +0000 | [diff] [blame] | 1202 | 0, Diags); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 1203 | Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1204 | Opts.ObjCConstantStringClass = |
| 1205 | Args.getLastArgValue(OPT_fconstant_string_class); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 1206 | Opts.ObjCDefaultSynthProperties = |
| 1207 | Args.hasArg(OPT_fobjc_default_synthesize_properties); |
Fariborz Jahanian | 3d145f6 | 2012-11-15 19:02:45 +0000 | [diff] [blame] | 1208 | Opts.EncodeExtendedBlockSig = |
| 1209 | Args.hasArg(OPT_fencode_extended_block_signature); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1210 | Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1211 | Opts.PackStruct = Args.getLastArgIntValue(OPT_fpack_struct_EQ, 0, Diags); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1212 | Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags); |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1213 | Opts.PIELevel = Args.getLastArgIntValue(OPT_pie_level, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1214 | Opts.Static = Args.hasArg(OPT_static_define); |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 1215 | Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple); |
| 1216 | Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple |
| 1217 | || Args.hasArg(OPT_fdump_record_layouts); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 1218 | Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 1219 | Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking); |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 1220 | Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); |
Peter Collingbourne | 0982136 | 2010-12-04 01:50:56 +0000 | [diff] [blame] | 1221 | Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 1222 | Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1223 | Opts.MRTD = Args.hasArg(OPT_mrtd); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1224 | Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 1225 | Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map); |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 1226 | Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype); |
John McCall | 48218c6 | 2011-07-13 17:56:40 +0000 | [diff] [blame] | 1227 | Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support); |
Sean Callanan | 50a9a12 | 2012-02-04 01:29:37 +0000 | [diff] [blame] | 1228 | Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1229 | Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal); |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 1230 | Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack); |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 1231 | Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1232 | |
Douglas Gregor | 50a70cd | 2013-01-15 06:45:29 +0000 | [diff] [blame] | 1233 | // Check if -fopenmp is specified. |
| 1234 | Opts.OpenMP = Args.hasArg(OPT_fopenmp); |
| 1235 | |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 1236 | // Record whether the __DEPRECATED define was requested. |
| 1237 | Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro, |
| 1238 | OPT_fno_deprecated_macro, |
| 1239 | Opts.Deprecated); |
| 1240 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1241 | // FIXME: Eliminate this dependency. |
Dylan Noblesmith | f23e8d2 | 2012-08-08 16:09:15 +0000 | [diff] [blame] | 1242 | unsigned Opt = getOptimizationLevel(Args, IK, Diags), |
| 1243 | OptSize = getOptimizationLevelSize(Args, IK, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1244 | Opts.Optimize = Opt != 0; |
Dylan Noblesmith | f23e8d2 | 2012-08-08 16:09:15 +0000 | [diff] [blame] | 1245 | Opts.OptimizeSize = OptSize != 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1246 | |
| 1247 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 1248 | // optimization level and -fno-inline, not actually whether the backend has |
| 1249 | // inlining enabled. |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 1250 | Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1251 | |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1252 | Opts.FastMath = Args.hasArg(OPT_ffast_math); |
Bob Wilson | 455e72e | 2012-07-19 03:52:53 +0000 | [diff] [blame] | 1253 | Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1254 | |
Ted Kremenek | 127ff2e | 2012-09-13 06:41:18 +0000 | [diff] [blame] | 1255 | Opts.RetainCommentsFromSystemHeaders = |
| 1256 | Args.hasArg(OPT_fretain_comments_from_system_headers); |
| 1257 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1258 | unsigned SSP = Args.getLastArgIntValue(OPT_stack_protector, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1259 | switch (SSP) { |
| 1260 | default: |
| 1261 | Diags.Report(diag::err_drv_invalid_value) |
| 1262 | << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; |
| 1263 | break; |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1264 | case 0: Opts.setStackProtector(LangOptions::SSPOff); break; |
| 1265 | case 1: Opts.setStackProtector(LangOptions::SSPOn); break; |
| 1266 | case 2: Opts.setStackProtector(LangOptions::SSPReq); break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1267 | } |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1268 | |
| 1269 | // Parse -fsanitize= arguments. |
| 1270 | std::vector<std::string> Sanitizers = Args.getAllArgValues(OPT_fsanitize_EQ); |
| 1271 | for (unsigned I = 0, N = Sanitizers.size(); I != N; ++I) { |
| 1272 | // Since the Opts.Sanitize* values are bitfields, it's a little tricky to |
| 1273 | // efficiently map string values to them. Perform the mapping indirectly: |
| 1274 | // convert strings to enumerated values, then switch over the enum to set |
| 1275 | // the right bitfield value. |
| 1276 | enum Sanitizer { |
| 1277 | #define SANITIZER(NAME, ID) \ |
| 1278 | ID, |
| 1279 | #include "clang/Basic/Sanitizers.def" |
| 1280 | Unknown |
| 1281 | }; |
| 1282 | switch (llvm::StringSwitch<unsigned>(Sanitizers[I]) |
| 1283 | #define SANITIZER(NAME, ID) \ |
| 1284 | .Case(NAME, ID) |
| 1285 | #include "clang/Basic/Sanitizers.def" |
| 1286 | .Default(Unknown)) { |
| 1287 | #define SANITIZER(NAME, ID) \ |
| 1288 | case ID: \ |
Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1289 | Opts.Sanitize.ID = true; \ |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1290 | break; |
| 1291 | #include "clang/Basic/Sanitizers.def" |
| 1292 | |
| 1293 | case Unknown: |
| 1294 | Diags.Report(diag::err_drv_invalid_value) |
| 1295 | << "-fsanitize=" << Sanitizers[I]; |
| 1296 | break; |
| 1297 | } |
| 1298 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1301 | static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1302 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1303 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1304 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1305 | Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch); |
| 1306 | Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1307 | if (const Arg *A = Args.getLastArg(OPT_token_cache)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1308 | Opts.TokenCache = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1309 | else |
| 1310 | Opts.TokenCache = Opts.ImplicitPTHInclude; |
| 1311 | Opts.UsePredefines = !Args.hasArg(OPT_undef); |
Douglas Gregor | 94dc8f6 | 2010-03-19 16:15:56 +0000 | [diff] [blame] | 1312 | Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1313 | Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1314 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 1315 | Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1316 | for (arg_iterator it = Args.filtered_begin(OPT_error_on_deserialized_pch_decl), |
| 1317 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1318 | const Arg *A = *it; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1319 | Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue()); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1320 | } |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1321 | |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1322 | if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1323 | StringRef Value(A->getValue()); |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1324 | size_t Comma = Value.find(','); |
| 1325 | unsigned Bytes = 0; |
| 1326 | unsigned EndOfLine = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1327 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1328 | if (Comma == StringRef::npos || |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1329 | Value.substr(0, Comma).getAsInteger(10, Bytes) || |
| 1330 | Value.substr(Comma + 1).getAsInteger(10, EndOfLine)) |
| 1331 | Diags.Report(diag::err_drv_preamble_format); |
| 1332 | else { |
| 1333 | Opts.PrecompiledPreambleBytes.first = Bytes; |
| 1334 | Opts.PrecompiledPreambleBytes.second = (EndOfLine != 0); |
| 1335 | } |
| 1336 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1337 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1338 | // Add macros from the command line. |
| 1339 | for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U), |
| 1340 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1341 | if ((*it)->getOption().matches(OPT_D)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1342 | Opts.addMacroDef((*it)->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1343 | else |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1344 | Opts.addMacroUndef((*it)->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1347 | Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1348 | |
| 1349 | // Add the ordered list of -includes. |
| 1350 | for (arg_iterator it = Args.filtered_begin(OPT_include, OPT_include_pch, |
| 1351 | OPT_include_pth), |
| 1352 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1353 | const Arg *A = *it; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1354 | Opts.Includes.push_back(A->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1355 | } |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1356 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 1357 | for (arg_iterator it = Args.filtered_begin(OPT_chain_include), |
| 1358 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1359 | const Arg *A = *it; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1360 | Opts.ChainedIncludes.push_back(A->getValue()); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1363 | // Include 'altivec.h' if -faltivec option present |
| 1364 | if (Args.hasArg(OPT_faltivec)) |
| 1365 | Opts.Includes.push_back("altivec.h"); |
| 1366 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1367 | for (arg_iterator it = Args.filtered_begin(OPT_remap_file), |
| 1368 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1369 | const Arg *A = *it; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1370 | std::pair<StringRef,StringRef> Split = |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1371 | StringRef(A->getValue()).split(';'); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1372 | |
| 1373 | if (Split.second.empty()) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1374 | Diags.Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1375 | continue; |
| 1376 | } |
| 1377 | |
| 1378 | Opts.addRemappedFile(Split.first, Split.second); |
| 1379 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1380 | |
| 1381 | if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1382 | StringRef Name = A->getValue(); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1383 | unsigned Library = llvm::StringSwitch<unsigned>(Name) |
| 1384 | .Case("libc++", ARCXX_libcxx) |
| 1385 | .Case("libstdc++", ARCXX_libstdcxx) |
| 1386 | .Case("none", ARCXX_nolib) |
| 1387 | .Default(~0U); |
| 1388 | if (Library == ~0U) |
| 1389 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 1390 | else |
| 1391 | Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library; |
| 1392 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, |
| 1396 | ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1397 | using namespace options; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1398 | Opts.ShowCPP = !Args.hasArg(OPT_dM); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1399 | Opts.ShowComments = Args.hasArg(OPT_C); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 1400 | Opts.ShowLineMarkers = !Args.hasArg(OPT_P); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1401 | Opts.ShowMacroComments = Args.hasArg(OPT_CC); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 1402 | Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD); |
David Blaikie | f1492f9 | 2012-06-14 17:36:09 +0000 | [diff] [blame] | 1403 | Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1407 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1408 | Opts.ABI = Args.getLastArgValue(OPT_target_abi); |
Charles Davis | 98b7c5c | 2010-06-11 01:06:47 +0000 | [diff] [blame] | 1409 | Opts.CXXABI = Args.getLastArgValue(OPT_cxx_abi); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1410 | Opts.CPU = Args.getLastArgValue(OPT_target_cpu); |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 1411 | Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature); |
Daniel Dunbar | 39065a5 | 2010-08-11 23:07:42 +0000 | [diff] [blame] | 1412 | Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version); |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 1413 | Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1414 | |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 1415 | // Use the default target triple if unspecified. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1416 | if (Opts.Triple.empty()) |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 1417 | Opts.Triple = llvm::sys::getDefaultTargetTriple(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | // |
| 1421 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1422 | bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1423 | const char *const *ArgBegin, |
| 1424 | const char *const *ArgEnd, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1425 | DiagnosticsEngine &Diags) { |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1426 | bool Success = true; |
| 1427 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1428 | // Parse the arguments. |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1429 | OwningPtr<OptTable> Opts(createDriverOptTable()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1430 | unsigned MissingArgIndex, MissingArgCount; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 1431 | OwningPtr<InputArgList> Args( |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1432 | Opts->ParseArgs(ArgBegin, ArgEnd,MissingArgIndex, MissingArgCount)); |
| 1433 | |
| 1434 | // Check for missing argument error. |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1435 | if (MissingArgCount) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1436 | Diags.Report(diag::err_drv_missing_argument) |
| 1437 | << Args->getArgString(MissingArgIndex) << MissingArgCount; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1438 | Success = false; |
| 1439 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1440 | |
| 1441 | // Issue errors on unknown arguments. |
| 1442 | for (arg_iterator it = Args->filtered_begin(OPT_UNKNOWN), |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1443 | ie = Args->filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1444 | Diags.Report(diag::err_drv_unknown_argument) << (*it)->getAsString(*Args); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1445 | Success = false; |
| 1446 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1447 | |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1448 | // Issue errors on arguments that are not valid for CC1. |
| 1449 | for (ArgList::iterator I = Args->begin(), E = Args->end(); |
| 1450 | I != E; ++I) { |
Michael J. Spencer | 91e06da | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 1451 | if (!(*I)->getOption().hasFlag(options::CC1Option)) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1452 | Diags.Report(diag::err_drv_unknown_argument) << (*I)->getAsString(*Args); |
| 1453 | Success = false; |
| 1454 | } |
| 1455 | } |
| 1456 | |
Ted Kremenek | 45796b1 | 2012-08-31 04:36:05 +0000 | [diff] [blame] | 1457 | Success = ParseAnalyzerArgs(*Res.getAnalyzerOpts(), *Args, Diags) && Success; |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 1458 | Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1459 | ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args); |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 1460 | Success = ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, &Diags) |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1461 | && Success; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1462 | ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1463 | // FIXME: We shouldn't have to pass the DashX option around here |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1464 | InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1465 | Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags) |
| 1466 | && Success; |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 1467 | ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 1468 | if (DashX != IK_AST && DashX != IK_LLVM_IR) { |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 1469 | ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 1470 | if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC) |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 1471 | Res.getLangOpts()->ObjCExceptions = 1; |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 1472 | } |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1473 | // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of |
| 1474 | // 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] | 1475 | // ParsePreprocessorArgs and remove the FileManager |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1476 | // parameters from the function and the "FileManager.h" #include. |
Chris Lattner | 7ad97ff | 2010-11-23 07:51:02 +0000 | [diff] [blame] | 1477 | FileManager FileMgr(Res.getFileSystemOpts()); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1478 | ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1479 | ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args); |
| 1480 | ParseTargetArgs(Res.getTargetOpts(), *Args); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1481 | |
| 1482 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1483 | } |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1484 | |
| 1485 | namespace { |
| 1486 | |
| 1487 | class ModuleSignature { |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1488 | SmallVector<uint64_t, 16> Data; |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1489 | unsigned CurBit; |
| 1490 | uint64_t CurValue; |
| 1491 | |
| 1492 | public: |
| 1493 | ModuleSignature() : CurBit(0), CurValue(0) { } |
| 1494 | |
| 1495 | void add(uint64_t Value, unsigned Bits); |
| 1496 | void add(StringRef Value); |
| 1497 | void flush(); |
| 1498 | |
| 1499 | llvm::APInt getAsInteger() const; |
| 1500 | }; |
| 1501 | } |
| 1502 | |
| 1503 | void ModuleSignature::add(uint64_t Value, unsigned int NumBits) { |
| 1504 | CurValue |= Value << CurBit; |
| 1505 | if (CurBit + NumBits < 64) { |
| 1506 | CurBit += NumBits; |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | // Add the current word. |
| 1511 | Data.push_back(CurValue); |
| 1512 | |
| 1513 | if (CurBit) |
| 1514 | CurValue = Value >> (64-CurBit); |
| 1515 | else |
| 1516 | CurValue = 0; |
| 1517 | CurBit = (CurBit+NumBits) & 63; |
| 1518 | } |
| 1519 | |
| 1520 | void ModuleSignature::flush() { |
| 1521 | if (CurBit == 0) |
| 1522 | return; |
| 1523 | |
| 1524 | Data.push_back(CurValue); |
| 1525 | CurBit = 0; |
| 1526 | CurValue = 0; |
| 1527 | } |
| 1528 | |
| 1529 | void ModuleSignature::add(StringRef Value) { |
| 1530 | for (StringRef::iterator I = Value.begin(), IEnd = Value.end(); I != IEnd;++I) |
| 1531 | add(*I, 8); |
| 1532 | } |
| 1533 | |
| 1534 | llvm::APInt ModuleSignature::getAsInteger() const { |
| 1535 | return llvm::APInt(Data.size() * 64, Data); |
| 1536 | } |
| 1537 | |
| 1538 | std::string CompilerInvocation::getModuleHash() const { |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1539 | using llvm::hash_code; |
| 1540 | using llvm::hash_value; |
| 1541 | using llvm::hash_combine; |
| 1542 | |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1543 | // Start the signature with the compiler version. |
Douglas Gregor | 3043175 | 2012-11-05 23:30:26 +0000 | [diff] [blame] | 1544 | // FIXME: We'd rather use something more cryptographically sound than |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1545 | // CityHash, but this will do for now. |
| 1546 | hash_code code = hash_value(getClangFullRepositoryVersion()); |
| 1547 | |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1548 | // Extend the signature with the language options |
| 1549 | #define LANGOPT(Name, Bits, Default, Description) \ |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1550 | code = hash_combine(code, LangOpts->Name); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1551 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1552 | code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name())); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1553 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 1554 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 1555 | #include "clang/Basic/LangOptions.def" |
| 1556 | |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1557 | // Extend the signature with the target options. |
| 1558 | code = hash_combine(code, TargetOpts->Triple, TargetOpts->CPU, |
| 1559 | TargetOpts->ABI, TargetOpts->CXXABI, |
| 1560 | TargetOpts->LinkerVersion); |
| 1561 | for (unsigned i = 0, n = TargetOpts->FeaturesAsWritten.size(); i != n; ++i) |
| 1562 | code = hash_combine(code, TargetOpts->FeaturesAsWritten[i]); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1563 | |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 1564 | // Extend the signature with preprocessor options. |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1565 | const PreprocessorOptions &ppOpts = getPreprocessorOpts(); |
| 1566 | code = hash_combine(code, ppOpts.UsePredefines, ppOpts.DetailedRecord); |
| 1567 | |
Douglas Gregor | 05edf66 | 2011-10-17 14:55:37 +0000 | [diff] [blame] | 1568 | std::vector<StringRef> MacroDefs; |
| 1569 | for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator |
| 1570 | I = getPreprocessorOpts().Macros.begin(), |
| 1571 | IEnd = getPreprocessorOpts().Macros.end(); |
| 1572 | I != IEnd; ++I) { |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1573 | code = hash_combine(code, I->first, I->second); |
Douglas Gregor | 05edf66 | 2011-10-17 14:55:37 +0000 | [diff] [blame] | 1574 | } |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1575 | |
| 1576 | // Extend the signature with the sysroot. |
| 1577 | const HeaderSearchOptions &hsOpts = getHeaderSearchOpts(); |
| 1578 | code = hash_combine(code, hsOpts.Sysroot, hsOpts.UseBuiltinIncludes, |
| 1579 | hsOpts.UseStandardSystemIncludes, |
| 1580 | hsOpts.UseStandardCXXIncludes, |
| 1581 | hsOpts.UseLibcxx); |
| 1582 | |
| 1583 | return llvm::APInt(64, code).toString(36, /*Signed=*/false); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1584 | } |