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" |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 11 | #include "clang/Basic/FileManager.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 12 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 13 | #include "clang/Driver/DriverDiagnostic.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Options.h" |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Util.h" |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 16 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/LangStandard.h" |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/Lex/HeaderSearchOptions.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 20 | #include "clang/Serialization/ASTReader.h" |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/Hashing.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallVector.h" |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 23 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringSwitch.h" |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/Triple.h" |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 27 | #include "llvm/Option/Arg.h" |
| 28 | #include "llvm/Option/ArgList.h" |
| 29 | #include "llvm/Option/OptTable.h" |
| 30 | #include "llvm/Option/Option.h" |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 31 | #include "llvm/Support/CodeGen.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 32 | #include "llvm/Support/ErrorHandling.h" |
Rafael Espindola | ac1db6b | 2013-06-26 05:03:40 +0000 | [diff] [blame] | 33 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Host.h" |
| 35 | #include "llvm/Support/Path.h" |
Nico Rieck | 2956ef4 | 2013-09-11 00:38:02 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Process.h" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 37 | #include <atomic> |
| 38 | #include <memory> |
Douglas Gregor | d8f681e | 2013-05-10 21:54:08 +0000 | [diff] [blame] | 39 | #include <sys/stat.h> |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 40 | #include <system_error> |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 41 | using namespace clang; |
| 42 | |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 43 | //===----------------------------------------------------------------------===// |
| 44 | // Initialization. |
| 45 | //===----------------------------------------------------------------------===// |
| 46 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 47 | CompilerInvocationBase::CompilerInvocationBase() |
Douglas Gregor | 02c23eb | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 48 | : LangOpts(new LangOptions()), TargetOpts(new TargetOptions()), |
Douglas Gregor | c042edd | 2012-10-24 16:19:39 +0000 | [diff] [blame] | 49 | DiagnosticOpts(new DiagnosticOptions()), |
Douglas Gregor | 14e71f0 | 2012-10-24 17:01:35 +0000 | [diff] [blame] | 50 | HeaderSearchOpts(new HeaderSearchOptions()), |
| 51 | PreprocessorOpts(new PreprocessorOptions()) {} |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 52 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 53 | CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X) |
Dylan Noblesmith | c93dc78 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 54 | : RefCountedBase<CompilerInvocation>(), |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 55 | LangOpts(new LangOptions(*X.getLangOpts())), |
Douglas Gregor | 02c23eb | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 56 | TargetOpts(new TargetOptions(X.getTargetOpts())), |
Douglas Gregor | c042edd | 2012-10-24 16:19:39 +0000 | [diff] [blame] | 57 | DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())), |
Douglas Gregor | 14e71f0 | 2012-10-24 17:01:35 +0000 | [diff] [blame] | 58 | HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())), |
| 59 | PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {} |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 60 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 61 | CompilerInvocationBase::~CompilerInvocationBase() {} |
| 62 | |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 63 | //===----------------------------------------------------------------------===// |
Richard Smith | 7c3f8b3 | 2012-11-01 03:48:49 +0000 | [diff] [blame] | 64 | // Deserialization (from args) |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 65 | //===----------------------------------------------------------------------===// |
| 66 | |
| 67 | using namespace clang::driver; |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 68 | using namespace clang::driver::options; |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 69 | using namespace llvm::opt; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 70 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 71 | // |
| 72 | |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 73 | static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 74 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 61e0786 | 2010-12-04 01:50:45 +0000 | [diff] [blame] | 75 | unsigned DefaultOpt = 0; |
| 76 | if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable)) |
| 77 | DefaultOpt = 2; |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 78 | |
| 79 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
| 80 | if (A->getOption().matches(options::OPT_O0)) |
| 81 | return 0; |
| 82 | |
Chad Rosier | d4fc9de | 2013-04-10 21:26:02 +0000 | [diff] [blame] | 83 | if (A->getOption().matches(options::OPT_Ofast)) |
| 84 | return 3; |
| 85 | |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 86 | assert (A->getOption().matches(options::OPT_O)); |
| 87 | |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 88 | StringRef S(A->getValue()); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 89 | if (S == "s" || S == "z" || S.empty()) |
| 90 | return 2; |
| 91 | |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 92 | return getLastArgIntValue(Args, OPT_O, DefaultOpt, Diags); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return DefaultOpt; |
| 96 | } |
| 97 | |
Chad Rosier | 0542236 | 2013-04-10 21:30:03 +0000 | [diff] [blame] | 98 | static unsigned getOptimizationLevelSize(ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 99 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
| 100 | if (A->getOption().matches(options::OPT_O)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 101 | switch (A->getValue()[0]) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 102 | default: |
| 103 | return 0; |
| 104 | case 's': |
| 105 | return 1; |
| 106 | case 'z': |
| 107 | return 2; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static void addWarningArgs(ArgList &Args, std::vector<std::string> &Warnings) { |
| 115 | for (arg_iterator I = Args.filtered_begin(OPT_W_Group), |
| 116 | E = Args.filtered_end(); I != E; ++I) { |
| 117 | Arg *A = *I; |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 118 | // 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] | 119 | // to the warning list. Else, add its value (for the OPT_W case). |
| 120 | if (A->getOption().getKind() == Option::FlagClass) { |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 121 | Warnings.push_back(A->getOption().getName().substr(1)); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 122 | } else { |
| 123 | for (unsigned Idx = 0, End = A->getNumValues(); |
| 124 | Idx < End; ++Idx) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 125 | StringRef V = A->getValue(Idx); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 126 | // "-Wl," and such are not warning options. |
| 127 | // FIXME: Should be handled by putting these in separate flags. |
| 128 | if (V.startswith("l,") || V.startswith("a,") || V.startswith("p,")) |
| 129 | continue; |
| 130 | |
| 131 | Warnings.push_back(V); |
| 132 | } |
| 133 | } |
| 134 | } |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 137 | static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 138 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 139 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 140 | bool Success = true; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 141 | if (Arg *A = Args.getLastArg(OPT_analyzer_store)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 142 | StringRef Name = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 143 | AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name) |
| 144 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \ |
| 145 | .Case(CMDFLAG, NAME##Model) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 146 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 147 | .Default(NumStores); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 148 | if (Value == NumStores) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 149 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 150 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 151 | Success = false; |
| 152 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 153 | Opts.AnalysisStoreOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 154 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 158 | StringRef Name = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 159 | AnalysisConstraints Value = llvm::StringSwitch<AnalysisConstraints>(Name) |
| 160 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \ |
| 161 | .Case(CMDFLAG, NAME##Model) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 162 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 163 | .Default(NumConstraints); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 164 | if (Value == NumConstraints) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 165 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 166 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 167 | Success = false; |
| 168 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 169 | Opts.AnalysisConstraintsOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 170 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | if (Arg *A = Args.getLastArg(OPT_analyzer_output)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 174 | StringRef Name = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 175 | AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name) |
Jordan Rose | 5fba5a7 | 2013-08-16 01:06:30 +0000 | [diff] [blame] | 176 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) \ |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 177 | .Case(CMDFLAG, PD_##NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 178 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 179 | .Default(NUM_ANALYSIS_DIAG_CLIENTS); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 180 | if (Value == NUM_ANALYSIS_DIAG_CLIENTS) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 181 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 182 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 183 | Success = false; |
| 184 | } else { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 185 | Opts.AnalysisDiagOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 186 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 189 | if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 190 | StringRef Name = A->getValue(); |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 191 | AnalysisPurgeMode Value = llvm::StringSwitch<AnalysisPurgeMode>(Name) |
| 192 | #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \ |
| 193 | .Case(CMDFLAG, NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 194 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 195 | .Default(NumPurgeModes); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 196 | if (Value == NumPurgeModes) { |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 197 | Diags.Report(diag::err_drv_invalid_value) |
| 198 | << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 199 | Success = false; |
| 200 | } else { |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 201 | Opts.AnalysisPurgeOpt = Value; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 202 | } |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 205 | if (Arg *A = Args.getLastArg(OPT_analyzer_inlining_mode)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 206 | StringRef Name = A->getValue(); |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 207 | AnalysisInliningMode Value = llvm::StringSwitch<AnalysisInliningMode>(Name) |
| 208 | #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) \ |
| 209 | .Case(CMDFLAG, NAME) |
Ted Kremenek | 987695a | 2012-08-31 04:35:58 +0000 | [diff] [blame] | 210 | #include "clang/StaticAnalyzer/Core/Analyses.def" |
Anna Zaks | 6625335 | 2012-03-08 23:16:35 +0000 | [diff] [blame] | 211 | .Default(NumInliningModes); |
| 212 | if (Value == NumInliningModes) { |
| 213 | Diags.Report(diag::err_drv_invalid_value) |
| 214 | << A->getAsString(Args) << Name; |
| 215 | Success = false; |
| 216 | } else { |
| 217 | Opts.InliningMode = Value; |
| 218 | } |
| 219 | } |
| 220 | |
Argyrios Kyrtzidis | 116f364 | 2011-02-25 00:09:51 +0000 | [diff] [blame] | 221 | Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help); |
Ted Kremenek | 3b8a040 | 2012-08-30 19:26:53 +0000 | [diff] [blame] | 222 | Opts.visualizeExplodedGraphWithGraphViz = |
| 223 | Args.hasArg(OPT_analyzer_viz_egraph_graphviz); |
| 224 | Opts.visualizeExplodedGraphWithUbiGraph = |
| 225 | Args.hasArg(OPT_analyzer_viz_egraph_ubigraph); |
Anna Zaks | b47dbcb | 2012-03-28 19:59:16 +0000 | [diff] [blame] | 226 | Opts.NoRetryExhausted = Args.hasArg(OPT_analyzer_disable_retry_exhausted); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 227 | Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers); |
| 228 | Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress); |
Ted Kremenek | fc57651 | 2009-12-07 22:06:12 +0000 | [diff] [blame] | 229 | Opts.AnalyzeNestedBlocks = |
| 230 | Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks); |
Ted Kremenek | 0caa2d4 | 2012-08-30 19:26:48 +0000 | [diff] [blame] | 231 | Opts.eagerlyAssumeBinOpBifurcation = Args.hasArg(OPT_analyzer_eagerly_assume); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 232 | Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function); |
Ted Kremenek | 9b823e8 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 233 | Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 234 | Opts.TrimGraph = Args.hasArg(OPT_trim_egraph); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 235 | Opts.maxBlockVisitOnPath = |
| 236 | getLastArgIntValue(Args, OPT_analyzer_max_loop, 4, Diags); |
Anna Zaks | 81fb169 | 2012-02-27 21:33:16 +0000 | [diff] [blame] | 237 | Opts.PrintStats = Args.hasArg(OPT_analyzer_stats); |
Anna Zaks | 8235f9c | 2012-03-02 19:05:03 +0000 | [diff] [blame] | 238 | Opts.InlineMaxStackDepth = |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 239 | getLastArgIntValue(Args, OPT_analyzer_inline_max_stack_depth, |
| 240 | Opts.InlineMaxStackDepth, Diags); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 241 | |
| 242 | Opts.CheckersControlList.clear(); |
| 243 | for (arg_iterator it = Args.filtered_begin(OPT_analyzer_checker, |
| 244 | OPT_analyzer_disable_checker), |
| 245 | ie = Args.filtered_end(); it != ie; ++it) { |
| 246 | const Arg *A = *it; |
| 247 | A->claim(); |
| 248 | bool enable = (A->getOption().getID() == OPT_analyzer_checker); |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 249 | // We can have a list of comma separated checker names, e.g: |
| 250 | // '-analyzer-checker=cocoa,unix' |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 251 | StringRef checkerList = A->getValue(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 252 | SmallVector<StringRef, 4> checkers; |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 253 | checkerList.split(checkers, ","); |
| 254 | for (unsigned i = 0, e = checkers.size(); i != e; ++i) |
| 255 | Opts.CheckersControlList.push_back(std::make_pair(checkers[i], enable)); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 256 | } |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 257 | |
| 258 | // Go through the analyzer configuration options. |
| 259 | for (arg_iterator it = Args.filtered_begin(OPT_analyzer_config), |
| 260 | ie = Args.filtered_end(); it != ie; ++it) { |
| 261 | const Arg *A = *it; |
| 262 | A->claim(); |
| 263 | // We can have a list of comma separated config names, e.g: |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 264 | // '-analyzer-config key1=val1,key2=val2' |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 265 | StringRef configList = A->getValue(); |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 266 | SmallVector<StringRef, 4> configVals; |
| 267 | configList.split(configVals, ","); |
| 268 | for (unsigned i = 0, e = configVals.size(); i != e; ++i) { |
| 269 | StringRef key, val; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 270 | std::tie(key, val) = configVals[i].split("="); |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 271 | if (val.empty()) { |
| 272 | Diags.Report(SourceLocation(), |
| 273 | diag::err_analyzer_config_no_value) << configVals[i]; |
| 274 | Success = false; |
| 275 | break; |
| 276 | } |
Ted Kremenek | 318cc3c | 2012-08-30 05:49:16 +0000 | [diff] [blame] | 277 | if (val.find('=') != StringRef::npos) { |
Ted Kremenek | 7b73e08 | 2012-08-29 05:55:00 +0000 | [diff] [blame] | 278 | Diags.Report(SourceLocation(), |
| 279 | diag::err_analyzer_config_multiple_values) |
| 280 | << configVals[i]; |
| 281 | Success = false; |
| 282 | break; |
| 283 | } |
| 284 | Opts.Config[key] = val; |
| 285 | } |
| 286 | } |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 287 | |
| 288 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 291 | static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) { |
| 292 | Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error); |
Fariborz Jahanian | bbdfad5 | 2012-01-26 20:57:58 +0000 | [diff] [blame] | 293 | Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal); |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 294 | return true; |
| 295 | } |
| 296 | |
Dmitri Gribenko | 6ebf091 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 297 | static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) { |
| 298 | Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands); |
Dmitri Gribenko | 6fd7d30 | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 299 | Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments); |
Dmitri Gribenko | 6ebf091 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 302 | static StringRef getCodeModel(ArgList &Args, DiagnosticsEngine &Diags) { |
| 303 | if (Arg *A = Args.getLastArg(OPT_mcode_model)) { |
| 304 | StringRef Value = A->getValue(); |
| 305 | if (Value == "small" || Value == "kernel" || Value == "medium" || |
| 306 | Value == "large") |
| 307 | return Value; |
| 308 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Value; |
| 309 | } |
| 310 | return "default"; |
| 311 | } |
| 312 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 313 | /// \brief Create a new Regex instance out of the string value in \p RpassArg. |
| 314 | /// It returns a pointer to the newly generated Regex instance. |
| 315 | static std::shared_ptr<llvm::Regex> |
| 316 | GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args, |
| 317 | Arg *RpassArg) { |
| 318 | StringRef Val = RpassArg->getValue(); |
| 319 | std::string RegexError; |
| 320 | std::shared_ptr<llvm::Regex> Pattern = std::make_shared<llvm::Regex>(Val); |
| 321 | if (!Pattern->isValid(RegexError)) { |
| 322 | Diags.Report(diag::err_drv_optimization_remark_pattern) |
| 323 | << RegexError << RpassArg->getAsString(Args); |
| 324 | Pattern.reset(); |
| 325 | } |
| 326 | return Pattern; |
| 327 | } |
| 328 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 329 | static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 330 | DiagnosticsEngine &Diags, |
| 331 | const TargetOptions &TargetOpts) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 332 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 333 | bool Success = true; |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 334 | |
Sylvestre Ledru | 762e567 | 2013-11-18 13:23:07 +0000 | [diff] [blame] | 335 | Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags); |
| 336 | // TODO: This could be done in Driver |
| 337 | unsigned MaxOptLevel = 3; |
| 338 | if (Opts.OptimizationLevel > MaxOptLevel) { |
| 339 | // If the optimization level is not supported, fall back on the default optimization |
| 340 | Diags.Report(diag::warn_drv_optimization_value) |
| 341 | << Args.getLastArg(OPT_O)->getAsString(Args) << "-O" << MaxOptLevel; |
| 342 | Opts.OptimizationLevel = MaxOptLevel; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | // We must always run at least the always inlining pass. |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 346 | Opts.setInlining( |
| 347 | (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining |
| 348 | : CodeGenOptions::OnlyAlwaysInlining); |
Chad Rosier | 634a4b1 | 2012-03-06 21:17:19 +0000 | [diff] [blame] | 349 | // -fno-inline-functions overrides OptimizationLevel > 1. |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 350 | Opts.NoInline = Args.hasArg(OPT_fno_inline); |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 351 | Opts.setInlining(Args.hasArg(OPT_fno_inline_functions) ? |
| 352 | CodeGenOptions::OnlyAlwaysInlining : Opts.getInlining()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 353 | |
Alexey Samsonov | fd00eec | 2012-05-04 07:39:27 +0000 | [diff] [blame] | 354 | if (Args.hasArg(OPT_gline_tables_only)) { |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 355 | Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly); |
Manman Ren | fc0f91c | 2013-06-19 01:46:49 +0000 | [diff] [blame] | 356 | } else if (Args.hasArg(OPT_g_Flag) || Args.hasArg(OPT_gdwarf_2) || |
| 357 | Args.hasArg(OPT_gdwarf_3) || Args.hasArg(OPT_gdwarf_4)) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 358 | bool Default = false; |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 359 | // Until dtrace (via CTF) and LLDB can deal with distributed debug info, |
| 360 | // Darwin and FreeBSD default to standalone/full debug info. |
| 361 | if (llvm::Triple(TargetOpts.Triple).isOSDarwin() || |
| 362 | llvm::Triple(TargetOpts.Triple).isOSFreeBSD()) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 363 | Default = true; |
| 364 | |
| 365 | if (Args.hasFlag(OPT_fstandalone_debug, OPT_fno_standalone_debug, Default)) |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 366 | Opts.setDebugInfo(CodeGenOptions::FullDebugInfo); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 367 | else |
| 368 | Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo); |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 369 | } |
Eric Christopher | da3301e | 2012-10-18 21:52:18 +0000 | [diff] [blame] | 370 | Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info); |
Eric Christopher | ff971d7 | 2013-02-22 23:50:16 +0000 | [diff] [blame] | 371 | Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); |
Manman Ren | fc0f91c | 2013-06-19 01:46:49 +0000 | [diff] [blame] | 372 | if (Args.hasArg(OPT_gdwarf_2)) |
| 373 | Opts.DwarfVersion = 2; |
| 374 | else if (Args.hasArg(OPT_gdwarf_3)) |
| 375 | Opts.DwarfVersion = 3; |
| 376 | else if (Args.hasArg(OPT_gdwarf_4)) |
| 377 | Opts.DwarfVersion = 4; |
| 378 | else if (Opts.getDebugInfo() != CodeGenOptions::NoDebugInfo) |
Eric Christopher | 617f4c5 | 2013-09-03 16:10:12 +0000 | [diff] [blame] | 379 | // Default Dwarf version is 4 if we are generating debug information. |
| 380 | Opts.DwarfVersion = 4; |
Alexey Samsonov | 3a70cd6 | 2012-04-27 07:24:20 +0000 | [diff] [blame] | 381 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 382 | Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); |
| 383 | Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 384 | Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); |
Daniel Dunbar | e26bdb9 | 2011-06-21 18:54:46 +0000 | [diff] [blame] | 385 | Opts.UseRegisterSizedBitfieldAccess = Args.hasArg( |
| 386 | OPT_fuse_register_sized_bitfield_access); |
Chad Rosier | b82e117 | 2013-04-24 18:09:54 +0000 | [diff] [blame] | 387 | Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing); |
Manman Ren | 96d6c45 | 2013-10-11 20:48:38 +0000 | [diff] [blame] | 388 | Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 389 | Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 390 | Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants); |
| 391 | Opts.NoCommon = Args.hasArg(OPT_fno_common); |
| 392 | Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float); |
Chad Rosier | 0542236 | 2013-04-10 21:30:03 +0000 | [diff] [blame] | 393 | Opts.OptimizeSize = getOptimizationLevelSize(Args); |
Daniel Dunbar | 6b0cf67 | 2010-06-07 23:19:17 +0000 | [diff] [blame] | 394 | Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) || |
| 395 | Args.hasArg(OPT_ffreestanding)); |
Chandler Carruth | b26404a | 2013-08-08 08:34:35 +0000 | [diff] [blame] | 396 | Opts.UnrollLoops = |
| 397 | Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops, |
| 398 | (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize)); |
Hal Finkel | ce5b5f1 | 2013-11-17 16:03:29 +0000 | [diff] [blame] | 399 | Opts.RerollLoops = Args.hasArg(OPT_freroll_loops); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 400 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 401 | Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as); |
Daniel Dunbar | f491013 | 2013-04-16 18:21:19 +0000 | [diff] [blame] | 402 | Opts.Autolink = !Args.hasArg(OPT_fno_autolink); |
Diego Novillo | b85a9ec | 2013-11-13 12:22:39 +0000 | [diff] [blame] | 403 | Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 404 | Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate); |
| 405 | Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 406 | Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 407 | Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); |
Peter Collingbourne | d51e43a | 2011-10-06 18:29:46 +0000 | [diff] [blame] | 408 | Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device); |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 409 | Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit); |
| 410 | Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 411 | Opts.CodeModel = getCodeModel(Args, Diags); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 412 | Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 413 | Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim); |
Nick Lewycky | 73b8d4b | 2013-06-21 21:15:32 +0000 | [diff] [blame] | 414 | Opts.DisableFree = Args.hasArg(OPT_disable_free); |
Nick Lewycky | 1db772b | 2012-01-23 08:29:12 +0000 | [diff] [blame] | 415 | Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 416 | Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); |
Peter Collingbourne | 4400cb8 | 2010-12-04 01:51:33 +0000 | [diff] [blame] | 417 | Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 418 | Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); |
Daniel Dunbar | 001f628 | 2011-12-09 23:41:18 +0000 | [diff] [blame] | 419 | Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) || |
| 420 | Args.hasArg(OPT_cl_finite_math_only)|| |
| 421 | Args.hasArg(OPT_cl_fast_relaxed_math)); |
| 422 | Opts.NoNaNsFPMath = (Args.hasArg(OPT_menable_no_nans) || |
| 423 | Args.hasArg(OPT_cl_finite_math_only)|| |
| 424 | Args.hasArg(OPT_cl_fast_relaxed_math)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 425 | Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 426 | Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 427 | Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags); |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 428 | Opts.NoGlobalMerge = Args.hasArg(OPT_mno_global_merge); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 429 | Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); |
Eric Christopher | 3105627 | 2013-04-04 06:29:47 +0000 | [diff] [blame] | 430 | Opts.EnableSegmentedStacks = Args.hasArg(OPT_split_stacks); |
Daniel Dunbar | 4ecc9b7 | 2010-05-27 05:39:39 +0000 | [diff] [blame] | 431 | Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 432 | Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 433 | Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 434 | Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 435 | Opts.SoftFloat = Args.hasArg(OPT_msoft_float); |
Chandler Carruth | 82fe6ae | 2012-03-27 23:58:37 +0000 | [diff] [blame] | 436 | Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 437 | Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) || |
| 438 | Args.hasArg(OPT_cl_unsafe_math_optimizations) || |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 439 | Args.hasArg(OPT_cl_fast_relaxed_math); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 440 | Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 441 | Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); |
Bob Wilson | 71fd6cc | 2012-02-03 06:27:22 +0000 | [diff] [blame] | 442 | Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ); |
Rafael Espindola | 8af669f | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 443 | Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 444 | |
Nick Lewycky | ff05979 | 2013-10-11 03:35:10 +0000 | [diff] [blame] | 445 | Opts.FunctionSections = Args.hasFlag(OPT_ffunction_sections, |
| 446 | OPT_fno_function_sections, false); |
| 447 | Opts.DataSections = Args.hasFlag(OPT_fdata_sections, |
| 448 | OPT_fno_data_sections, false); |
Chris Lattner | bbea716 | 2010-04-13 00:38:24 +0000 | [diff] [blame] | 449 | |
Nick Lewycky | fdf137b | 2013-06-25 01:49:44 +0000 | [diff] [blame] | 450 | Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive); |
| 451 | Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops); |
| 452 | Opts.VectorizeSLP = Args.hasArg(OPT_vectorize_slp); |
| 453 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 454 | Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); |
John McCall | 824e19e | 2010-02-12 23:47:27 +0000 | [diff] [blame] | 455 | Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier); |
Will Dietz | 2d382d1 | 2012-12-30 20:53:28 +0000 | [diff] [blame] | 456 | Opts.SanitizeRecover = !Args.hasArg(OPT_fno_sanitize_recover); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 457 | |
Nick Lewycky | f2b5e07 | 2013-03-20 01:38:16 +0000 | [diff] [blame] | 458 | Opts.DisableGCov = Args.hasArg(OPT_test_coverage); |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 459 | Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); |
| 460 | Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); |
Nick Lewycky | 0f815f1 | 2013-03-07 08:28:53 +0000 | [diff] [blame] | 461 | if (Opts.EmitGcovArcs || Opts.EmitGcovNotes) { |
Nick Lewycky | 3dc0541 | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 462 | Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); |
Nick Lewycky | 0f815f1 | 2013-03-07 08:28:53 +0000 | [diff] [blame] | 463 | Opts.CoverageExtraChecksum = Args.hasArg(OPT_coverage_cfg_checksum); |
Nick Lewycky | 83c546a | 2013-03-20 02:14:38 +0000 | [diff] [blame] | 464 | Opts.CoverageNoFunctionNamesInData = |
| 465 | Args.hasArg(OPT_coverage_no_function_names_in_data); |
Nick Lewycky | 0f815f1 | 2013-03-07 08:28:53 +0000 | [diff] [blame] | 466 | if (Args.hasArg(OPT_coverage_version_EQ)) { |
| 467 | StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ); |
| 468 | if (CoverageVersion.size() != 4) { |
| 469 | Diags.Report(diag::err_drv_invalid_value) |
| 470 | << Args.getLastArg(OPT_coverage_version_EQ)->getAsString(Args) |
| 471 | << CoverageVersion; |
| 472 | } else { |
Nick Lewycky | c3ae583 | 2013-03-14 05:14:01 +0000 | [diff] [blame] | 473 | memcpy(Opts.CoverageVersion, CoverageVersion.data(), 4); |
Nick Lewycky | 0f815f1 | 2013-03-07 08:28:53 +0000 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); |
| 479 | Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); |
| 480 | Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 481 | Opts.CompressDebugSections = Args.hasArg(OPT_compress_debug_sections); |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 482 | Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); |
Peter Collingbourne | 22a7dfe | 2011-10-30 17:30:44 +0000 | [diff] [blame] | 483 | Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file); |
Alexey Samsonov | 91ecfa6 | 2012-12-03 19:12:58 +0000 | [diff] [blame] | 484 | Opts.SanitizerBlacklistFile = Args.getLastArgValue(OPT_fsanitize_blacklist); |
Alexey Samsonov | 4bdc604 | 2013-01-20 13:12:12 +0000 | [diff] [blame] | 485 | Opts.SanitizeMemoryTrackOrigins = |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 486 | getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, Diags); |
Chad Rosier | 78d85b1 | 2013-01-29 23:31:22 +0000 | [diff] [blame] | 487 | Opts.SanitizeUndefinedTrapOnError = |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 488 | Args.hasArg(OPT_fsanitize_undefined_trap_on_error); |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 489 | Opts.SSPBufferSize = |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 490 | getLastArgIntValue(Args, OPT_stack_protector_buffer_size, 8, Diags); |
Nick Lewycky | 4e785c9 | 2011-12-06 03:33:03 +0000 | [diff] [blame] | 491 | Opts.StackRealignment = Args.hasArg(OPT_mstackrealign); |
Joerg Sonnenberger | e9d11db | 2011-12-05 23:05:23 +0000 | [diff] [blame] | 492 | if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 493 | StringRef Val = A->getValue(); |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 494 | unsigned StackAlignment = Opts.StackAlignment; |
| 495 | Val.getAsInteger(10, StackAlignment); |
| 496 | Opts.StackAlignment = StackAlignment; |
Joerg Sonnenberger | e9d11db | 2011-12-05 23:05:23 +0000 | [diff] [blame] | 497 | } |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 498 | |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 499 | if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 500 | StringRef Name = A->getValue(); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 501 | unsigned Method = llvm::StringSwitch<unsigned>(Name) |
| 502 | .Case("legacy", CodeGenOptions::Legacy) |
| 503 | .Case("non-legacy", CodeGenOptions::NonLegacy) |
| 504 | .Case("mixed", CodeGenOptions::Mixed) |
| 505 | .Default(~0U); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 506 | if (Method == ~0U) { |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 507 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 508 | Success = false; |
| 509 | } else { |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 510 | Opts.setObjCDispatchMethod( |
| 511 | static_cast<CodeGenOptions::ObjCDispatchMethodKind>(Method)); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 512 | } |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 513 | } |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 514 | |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 515 | if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 516 | StringRef Name = A->getValue(); |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 517 | unsigned Model = llvm::StringSwitch<unsigned>(Name) |
| 518 | .Case("global-dynamic", CodeGenOptions::GeneralDynamicTLSModel) |
| 519 | .Case("local-dynamic", CodeGenOptions::LocalDynamicTLSModel) |
| 520 | .Case("initial-exec", CodeGenOptions::InitialExecTLSModel) |
| 521 | .Case("local-exec", CodeGenOptions::LocalExecTLSModel) |
| 522 | .Default(~0U); |
| 523 | if (Model == ~0U) { |
| 524 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 525 | Success = false; |
| 526 | } else { |
Douglas Gregor | 4cdad31 | 2012-10-23 20:05:01 +0000 | [diff] [blame] | 527 | Opts.setDefaultTLSModel(static_cast<CodeGenOptions::TLSModel>(Model)); |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Lang Hames | 931c083 | 2012-11-15 07:51:26 +0000 | [diff] [blame] | 531 | if (Arg *A = Args.getLastArg(OPT_ffp_contract)) { |
| 532 | StringRef Val = A->getValue(); |
| 533 | if (Val == "fast") |
| 534 | Opts.setFPContractMode(CodeGenOptions::FPC_Fast); |
| 535 | else if (Val == "on") |
| 536 | Opts.setFPContractMode(CodeGenOptions::FPC_On); |
| 537 | else if (Val == "off") |
| 538 | Opts.setFPContractMode(CodeGenOptions::FPC_Off); |
| 539 | else |
| 540 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; |
| 541 | } |
| 542 | |
John McCall | b8b5297 | 2013-06-18 02:46:29 +0000 | [diff] [blame] | 543 | if (Arg *A = Args.getLastArg(OPT_fpcc_struct_return, OPT_freg_struct_return)) { |
| 544 | if (A->getOption().matches(OPT_fpcc_struct_return)) { |
| 545 | Opts.setStructReturnConvention(CodeGenOptions::SRCK_OnStack); |
| 546 | } else { |
| 547 | assert(A->getOption().matches(OPT_freg_struct_return)); |
| 548 | Opts.setStructReturnConvention(CodeGenOptions::SRCK_InRegs); |
| 549 | } |
| 550 | } |
| 551 | |
Hans Wennborg | b357479 | 2013-08-08 00:17:41 +0000 | [diff] [blame] | 552 | Opts.DependentLibraries = Args.getAllArgValues(OPT_dependent_lib); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 553 | bool NeedLocTracking = false; |
Hans Wennborg | b357479 | 2013-08-08 00:17:41 +0000 | [diff] [blame] | 554 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 555 | if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 556 | Opts.OptimizationRemarkPattern = |
| 557 | GenerateOptimizationRemarkRegex(Diags, Args, A); |
| 558 | NeedLocTracking = true; |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 561 | if (Arg *A = Args.getLastArg(OPT_Rpass_missed_EQ)) { |
| 562 | Opts.OptimizationRemarkMissedPattern = |
| 563 | GenerateOptimizationRemarkRegex(Diags, Args, A); |
| 564 | NeedLocTracking = true; |
| 565 | } |
| 566 | |
| 567 | if (Arg *A = Args.getLastArg(OPT_Rpass_analysis_EQ)) { |
| 568 | Opts.OptimizationRemarkAnalysisPattern = |
| 569 | GenerateOptimizationRemarkRegex(Diags, Args, A); |
| 570 | NeedLocTracking = true; |
| 571 | } |
| 572 | |
| 573 | // If the user requested one of the flags in the -Rpass family, make sure |
| 574 | // that the backend tracks source location information. |
| 575 | if (NeedLocTracking && Opts.getDebugInfo() == CodeGenOptions::NoDebugInfo) |
| 576 | Opts.setDebugInfo(CodeGenOptions::LocTrackingOnly); |
| 577 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 578 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, |
| 582 | ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 583 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 584 | Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file); |
| 585 | Opts.Targets = Args.getAllArgValues(OPT_MT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 586 | Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 587 | Opts.IncludeModuleFiles = Args.hasArg(OPT_module_file_deps); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 588 | Opts.UsePhonyTargets = Args.hasArg(OPT_MP); |
Daniel Dunbar | eef63e0 | 2011-02-02 15:41:17 +0000 | [diff] [blame] | 589 | Opts.ShowHeaderIncludes = Args.hasArg(OPT_H); |
Daniel Dunbar | b34d69b | 2011-02-02 21:11:31 +0000 | [diff] [blame] | 590 | Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file); |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 591 | Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG); |
Hans Wennborg | 708002e | 2013-08-09 00:32:23 +0000 | [diff] [blame] | 592 | Opts.PrintShowIncludes = Args.hasArg(OPT_show_includes); |
Douglas Gregor | 773303a | 2012-02-02 23:45:13 +0000 | [diff] [blame] | 593 | Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 594 | Opts.ModuleDependencyOutputDir = |
| 595 | Args.getLastArgValue(OPT_module_dependency_dir); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 598 | bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, |
| 599 | DiagnosticsEngine *Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 600 | using namespace options; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 601 | bool Success = true; |
| 602 | |
Daniel Dunbar | 08c6695 | 2011-04-07 18:11:14 +0000 | [diff] [blame] | 603 | Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file); |
Ted Kremenek | 7800212 | 2011-10-29 00:12:39 +0000 | [diff] [blame] | 604 | Opts.DiagnosticSerializationFile = |
| 605 | Args.getLastArgValue(OPT_diagnostic_serialized_file); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 606 | Opts.IgnoreWarnings = Args.hasArg(OPT_w); |
| 607 | Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros); |
| 608 | Opts.Pedantic = Args.hasArg(OPT_pedantic); |
| 609 | Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors); |
| 610 | Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics); |
| 611 | Opts.ShowColors = Args.hasArg(OPT_fcolor_diagnostics); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 612 | Opts.ShowColumn = Args.hasFlag(OPT_fshow_column, |
| 613 | OPT_fno_show_column, |
| 614 | /*Default=*/true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 615 | Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); |
| 616 | Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); |
| 617 | Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 618 | |
Nico Rieck | 2956ef4 | 2013-09-11 00:38:02 +0000 | [diff] [blame] | 619 | llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes)); |
| 620 | |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 621 | // Default behavior is to not to show note include stacks. |
| 622 | Opts.ShowNoteIncludeStack = false; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 623 | if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack, |
| 624 | OPT_fno_diagnostics_show_note_include_stack)) |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 625 | if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack)) |
| 626 | Opts.ShowNoteIncludeStack = true; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 627 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 628 | StringRef ShowOverloads = |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 629 | Args.getLastArgValue(OPT_fshow_overloads_EQ, "all"); |
| 630 | if (ShowOverloads == "best") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 631 | Opts.setShowOverloads(Ovl_Best); |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 632 | else if (ShowOverloads == "all") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 633 | Opts.setShowOverloads(Ovl_All); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 634 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 635 | Success = false; |
| 636 | if (Diags) |
| 637 | Diags->Report(diag::err_drv_invalid_value) |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 638 | << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args) |
| 639 | << ShowOverloads; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 640 | } |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 641 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 642 | StringRef ShowCategory = |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 643 | Args.getLastArgValue(OPT_fdiagnostics_show_category, "none"); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 644 | if (ShowCategory == "none") |
| 645 | Opts.ShowCategories = 0; |
| 646 | else if (ShowCategory == "id") |
| 647 | Opts.ShowCategories = 1; |
| 648 | else if (ShowCategory == "name") |
| 649 | Opts.ShowCategories = 2; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 650 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 651 | Success = false; |
| 652 | if (Diags) |
| 653 | Diags->Report(diag::err_drv_invalid_value) |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 654 | << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) |
| 655 | << ShowCategory; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 656 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 657 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 658 | StringRef Format = |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 659 | Args.getLastArgValue(OPT_fdiagnostics_format, "clang"); |
| 660 | if (Format == "clang") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 661 | Opts.setFormat(DiagnosticOptions::Clang); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 662 | else if (Format == "msvc") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 663 | Opts.setFormat(DiagnosticOptions::Msvc); |
Hans Wennborg | 89e3274 | 2013-09-24 00:08:55 +0000 | [diff] [blame] | 664 | else if (Format == "msvc-fallback") { |
| 665 | Opts.setFormat(DiagnosticOptions::Msvc); |
| 666 | Opts.CLFallbackMode = true; |
| 667 | } else if (Format == "vi") |
Douglas Gregor | dc7b641 | 2012-10-23 23:11:23 +0000 | [diff] [blame] | 668 | Opts.setFormat(DiagnosticOptions::Vi); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 669 | else { |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 670 | Success = false; |
| 671 | if (Diags) |
| 672 | Diags->Report(diag::err_drv_invalid_value) |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 673 | << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) |
| 674 | << Format; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 675 | } |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 676 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 677 | Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 678 | Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); |
Richard Smith | 62221b1 | 2012-11-14 23:55:25 +0000 | [diff] [blame] | 679 | Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 680 | Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); |
Richard Trieu | 246b6aa | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 681 | Opts.ElideType = !Args.hasArg(OPT_fno_elide_type); |
| 682 | Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 683 | Opts.ErrorLimit = getLastArgIntValue(Args, OPT_ferror_limit, 0, Diags); |
| 684 | Opts.MacroBacktraceLimit = |
| 685 | getLastArgIntValue(Args, OPT_fmacro_backtrace_limit, |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 686 | DiagnosticOptions::DefaultMacroBacktraceLimit, Diags); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 687 | Opts.TemplateBacktraceLimit = getLastArgIntValue( |
| 688 | Args, OPT_ftemplate_backtrace_limit, |
| 689 | DiagnosticOptions::DefaultTemplateBacktraceLimit, Diags); |
| 690 | Opts.ConstexprBacktraceLimit = getLastArgIntValue( |
| 691 | Args, OPT_fconstexpr_backtrace_limit, |
| 692 | DiagnosticOptions::DefaultConstexprBacktraceLimit, Diags); |
| 693 | Opts.TabStop = getLastArgIntValue(Args, OPT_ftabstop, |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 694 | DiagnosticOptions::DefaultTabStop, Diags); |
| 695 | if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) { |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 696 | Opts.TabStop = DiagnosticOptions::DefaultTabStop; |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 697 | if (Diags) |
| 698 | Diags->Report(diag::warn_ignoring_ftabstop_value) |
| 699 | << Opts.TabStop << DiagnosticOptions::DefaultTabStop; |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 700 | } |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 701 | Opts.MessageLength = getLastArgIntValue(Args, OPT_fmessage_length, 0, Diags); |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 702 | addWarningArgs(Args, Opts.Warnings); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 703 | |
| 704 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 707 | static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) { |
| 708 | Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory); |
| 709 | } |
| 710 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 711 | static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 712 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 713 | using namespace options; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 714 | Opts.ProgramAction = frontend::ParseSyntaxOnly; |
| 715 | if (const Arg *A = Args.getLastArg(OPT_Action_Group)) { |
| 716 | switch (A->getOption().getID()) { |
| 717 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 718 | llvm_unreachable("Invalid option in group!"); |
Alexander Kornienko | 171af64 | 2012-07-31 09:37:40 +0000 | [diff] [blame] | 719 | case OPT_ast_list: |
| 720 | Opts.ProgramAction = frontend::ASTDeclList; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 721 | case OPT_ast_dump: |
| 722 | Opts.ProgramAction = frontend::ASTDump; break; |
| 723 | case OPT_ast_print: |
| 724 | Opts.ProgramAction = frontend::ASTPrint; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 725 | case OPT_ast_view: |
| 726 | Opts.ProgramAction = frontend::ASTView; break; |
| 727 | case OPT_dump_raw_tokens: |
| 728 | Opts.ProgramAction = frontend::DumpRawTokens; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 729 | case OPT_dump_tokens: |
| 730 | Opts.ProgramAction = frontend::DumpTokens; break; |
| 731 | case OPT_S: |
| 732 | Opts.ProgramAction = frontend::EmitAssembly; break; |
| 733 | case OPT_emit_llvm_bc: |
| 734 | Opts.ProgramAction = frontend::EmitBC; break; |
| 735 | case OPT_emit_html: |
| 736 | Opts.ProgramAction = frontend::EmitHTML; break; |
| 737 | case OPT_emit_llvm: |
| 738 | Opts.ProgramAction = frontend::EmitLLVM; break; |
| 739 | case OPT_emit_llvm_only: |
| 740 | Opts.ProgramAction = frontend::EmitLLVMOnly; break; |
Daniel Dunbar | 32148ce | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 741 | case OPT_emit_codegen_only: |
| 742 | Opts.ProgramAction = frontend::EmitCodeGenOnly; break; |
Daniel Dunbar | da1573f | 2010-02-03 01:18:43 +0000 | [diff] [blame] | 743 | case OPT_emit_obj: |
| 744 | Opts.ProgramAction = frontend::EmitObj; break; |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 745 | case OPT_fixit_EQ: |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 746 | Opts.FixItSuffix = A->getValue(); |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 747 | // fall-through! |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 748 | case OPT_fixit: |
| 749 | Opts.ProgramAction = frontend::FixIt; break; |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 750 | case OPT_emit_module: |
| 751 | Opts.ProgramAction = frontend::GenerateModule; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 752 | case OPT_emit_pch: |
| 753 | Opts.ProgramAction = frontend::GeneratePCH; break; |
| 754 | case OPT_emit_pth: |
| 755 | Opts.ProgramAction = frontend::GeneratePTH; break; |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 756 | case OPT_init_only: |
| 757 | Opts.ProgramAction = frontend::InitOnly; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 758 | case OPT_fsyntax_only: |
| 759 | Opts.ProgramAction = frontend::ParseSyntaxOnly; break; |
Douglas Gregor | c544ba0 | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 760 | case OPT_module_file_info: |
| 761 | Opts.ProgramAction = frontend::ModuleFileInfo; break; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 762 | case OPT_verify_pch: |
| 763 | Opts.ProgramAction = frontend::VerifyPCH; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 764 | case OPT_print_decl_contexts: |
| 765 | Opts.ProgramAction = frontend::PrintDeclContext; break; |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 766 | case OPT_print_preamble: |
| 767 | Opts.ProgramAction = frontend::PrintPreamble; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 768 | case OPT_E: |
| 769 | Opts.ProgramAction = frontend::PrintPreprocessedInput; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 770 | case OPT_rewrite_macros: |
| 771 | Opts.ProgramAction = frontend::RewriteMacros; break; |
| 772 | case OPT_rewrite_objc: |
| 773 | Opts.ProgramAction = frontend::RewriteObjC; break; |
| 774 | case OPT_rewrite_test: |
| 775 | Opts.ProgramAction = frontend::RewriteTest; break; |
| 776 | case OPT_analyze: |
| 777 | Opts.ProgramAction = frontend::RunAnalysis; break; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 778 | case OPT_migrate: |
| 779 | Opts.ProgramAction = frontend::MigrateSource; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 780 | case OPT_Eonly: |
| 781 | Opts.ProgramAction = frontend::RunPreprocessorOnly; break; |
| 782 | } |
| 783 | } |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 784 | |
| 785 | if (const Arg* A = Args.getLastArg(OPT_plugin)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 786 | Opts.Plugins.push_back(A->getValue(0)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 787 | Opts.ProgramAction = frontend::PluginAction; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 788 | Opts.ActionName = A->getValue(); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 789 | |
| 790 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 791 | end = Args.filtered_end(); it != end; ++it) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 792 | if ((*it)->getValue(0) == Opts.ActionName) |
| 793 | Opts.PluginArgs.push_back((*it)->getValue(1)); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 794 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 795 | } |
| 796 | |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 797 | Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 798 | Opts.AddPluginArgs.resize(Opts.AddPluginActions.size()); |
| 799 | for (int i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) { |
| 800 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 801 | end = Args.filtered_end(); it != end; ++it) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 802 | if ((*it)->getValue(0) == Opts.AddPluginActions[i]) |
| 803 | Opts.AddPluginArgs[i].push_back((*it)->getValue(1)); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 804 | } |
| 805 | } |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 806 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 807 | if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) { |
| 808 | Opts.CodeCompletionAt = |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 809 | ParsedSourceLocation::FromString(A->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 810 | if (Opts.CodeCompletionAt.FileName.empty()) |
| 811 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 812 | << A->getAsString(Args) << A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 813 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 814 | Opts.DisableFree = Args.hasArg(OPT_disable_free); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 815 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 816 | Opts.OutputFile = Args.getLastArgValue(OPT_o); |
| 817 | Opts.Plugins = Args.getAllArgValues(OPT_load); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 818 | Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 819 | Opts.ShowHelp = Args.hasArg(OPT_help); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 820 | Opts.ShowStats = Args.hasArg(OPT_print_stats); |
| 821 | Opts.ShowTimers = Args.hasArg(OPT_ftime_report); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 822 | Opts.ShowVersion = Args.hasArg(OPT_version); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 823 | Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge); |
| 824 | Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); |
Nick Lewycky | 1450f26 | 2010-08-13 17:31:00 +0000 | [diff] [blame] | 825 | Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can); |
Argyrios Kyrtzidis | 61d679a | 2012-01-26 02:40:48 +0000 | [diff] [blame] | 826 | Opts.FixOnlyWarnings = Args.hasArg(OPT_fix_only_warnings); |
| 827 | Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile); |
| 828 | Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp); |
Alexander Kornienko | e34a052 | 2012-07-26 16:01:23 +0000 | [diff] [blame] | 829 | Opts.ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter); |
Richard Smith | ab297cc | 2013-06-24 01:45:33 +0000 | [diff] [blame] | 830 | Opts.ASTDumpLookups = Args.hasArg(OPT_ast_dump_lookups); |
Douglas Gregor | 20c6f2e | 2013-01-28 18:38:02 +0000 | [diff] [blame] | 831 | Opts.UseGlobalModuleIndex = !Args.hasArg(OPT_fno_modules_global_index); |
Douglas Gregor | f575d6e | 2013-01-25 00:45:27 +0000 | [diff] [blame] | 832 | Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex; |
Douglas Gregor | a6b00fc | 2013-01-23 22:38:11 +0000 | [diff] [blame] | 833 | |
Dmitri Gribenko | d99ef53 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 834 | Opts.CodeCompleteOpts.IncludeMacros |
| 835 | = Args.hasArg(OPT_code_completion_macros); |
| 836 | Opts.CodeCompleteOpts.IncludeCodePatterns |
| 837 | = Args.hasArg(OPT_code_completion_patterns); |
| 838 | Opts.CodeCompleteOpts.IncludeGlobals |
| 839 | = !Args.hasArg(OPT_no_code_completion_globals); |
| 840 | Opts.CodeCompleteOpts.IncludeBriefComments |
| 841 | = Args.hasArg(OPT_code_completion_brief_comments); |
| 842 | |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 843 | Opts.OverrideRecordLayoutsFile |
| 844 | = Args.getLastArgValue(OPT_foverride_record_layout_EQ); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 845 | if (const Arg *A = Args.getLastArg(OPT_arcmt_check, |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 846 | OPT_arcmt_modify, |
| 847 | OPT_arcmt_migrate)) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 848 | switch (A->getOption().getID()) { |
| 849 | default: |
| 850 | llvm_unreachable("missed a case"); |
| 851 | case OPT_arcmt_check: |
| 852 | Opts.ARCMTAction = FrontendOptions::ARCMT_Check; |
| 853 | break; |
| 854 | case OPT_arcmt_modify: |
| 855 | Opts.ARCMTAction = FrontendOptions::ARCMT_Modify; |
| 856 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 857 | case OPT_arcmt_migrate: |
| 858 | Opts.ARCMTAction = FrontendOptions::ARCMT_Migrate; |
| 859 | break; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 860 | } |
| 861 | } |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 862 | Opts.MTMigrateDir = Args.getLastArgValue(OPT_mt_migrate_directory); |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 863 | Opts.ARCMTMigrateReportOut |
| 864 | = Args.getLastArgValue(OPT_arcmt_migrate_report_output); |
| 865 | Opts.ARCMTMigrateEmitARCErrors |
| 866 | = Args.hasArg(OPT_arcmt_migrate_emit_arc_errors); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 867 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 868 | if (Args.hasArg(OPT_objcmt_migrate_literals)) |
| 869 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Literals; |
| 870 | if (Args.hasArg(OPT_objcmt_migrate_subscripting)) |
| 871 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Subscripting; |
Fariborz Jahanian | d412999 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 872 | if (Args.hasArg(OPT_objcmt_migrate_property)) |
| 873 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Property; |
Fariborz Jahanian | 5b98aba | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 874 | if (Args.hasArg(OPT_objcmt_migrate_readonly_property)) |
| 875 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReadonlyProperty; |
Fariborz Jahanian | 081099d | 2013-10-02 21:32:39 +0000 | [diff] [blame] | 876 | if (Args.hasArg(OPT_objcmt_migrate_readwrite_property)) |
| 877 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReadwriteProperty; |
Fariborz Jahanian | a00f873 | 2013-10-02 21:58:13 +0000 | [diff] [blame] | 878 | if (Args.hasArg(OPT_objcmt_migrate_annotation)) |
| 879 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Annotation; |
Fariborz Jahanian | cd569f2 | 2013-11-05 22:28:30 +0000 | [diff] [blame] | 880 | if (Args.hasArg(OPT_objcmt_returns_innerpointer_property)) |
| 881 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReturnsInnerPointerProperty; |
Fariborz Jahanian | a00f873 | 2013-10-02 21:58:13 +0000 | [diff] [blame] | 882 | if (Args.hasArg(OPT_objcmt_migrate_instancetype)) |
| 883 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Instancetype; |
| 884 | if (Args.hasArg(OPT_objcmt_migrate_nsmacros)) |
| 885 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_NsMacros; |
| 886 | if (Args.hasArg(OPT_objcmt_migrate_protocol_conformance)) |
| 887 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ProtocolConformance; |
Fariborz Jahanian | 39ebb02 | 2013-10-09 19:06:08 +0000 | [diff] [blame] | 888 | if (Args.hasArg(OPT_objcmt_atomic_property)) |
| 889 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_AtomicProperty; |
Fariborz Jahanian | 5d2a206 | 2013-11-13 00:08:36 +0000 | [diff] [blame] | 890 | if (Args.hasArg(OPT_objcmt_ns_nonatomic_iosonly)) |
| 891 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_NsAtomicIOSOnlyProperty; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 892 | if (Args.hasArg(OPT_objcmt_migrate_designated_init)) |
| 893 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_DesignatedInitializer; |
Fariborz Jahanian | 081099d | 2013-10-02 21:32:39 +0000 | [diff] [blame] | 894 | if (Args.hasArg(OPT_objcmt_migrate_all)) |
| 895 | Opts.ObjCMTAction |= FrontendOptions::ObjCMT_MigrateDecls; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 896 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 897 | Opts.ObjCMTWhiteListPath = Args.getLastArgValue(OPT_objcmt_whitelist_dir_path); |
Argyrios Kyrtzidis | 2c050f6 | 2013-11-14 16:33:29 +0000 | [diff] [blame] | 898 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 899 | if (Opts.ARCMTAction != FrontendOptions::ARCMT_None && |
| 900 | Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) { |
| 901 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 902 | << "ARC migration" << "ObjC migration"; |
| 903 | } |
| 904 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 905 | InputKind DashX = IK_None; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 906 | if (const Arg *A = Args.getLastArg(OPT_x)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 907 | DashX = llvm::StringSwitch<InputKind>(A->getValue()) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 908 | .Case("c", IK_C) |
| 909 | .Case("cl", IK_OpenCL) |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 910 | .Case("cuda", IK_CUDA) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 911 | .Case("c++", IK_CXX) |
| 912 | .Case("objective-c", IK_ObjC) |
| 913 | .Case("objective-c++", IK_ObjCXX) |
| 914 | .Case("cpp-output", IK_PreprocessedC) |
| 915 | .Case("assembler-with-cpp", IK_Asm) |
| 916 | .Case("c++-cpp-output", IK_PreprocessedCXX) |
| 917 | .Case("objective-c-cpp-output", IK_PreprocessedObjC) |
Chris Lattner | 919f2ca | 2011-04-09 07:09:31 +0000 | [diff] [blame] | 918 | .Case("objc-cpp-output", IK_PreprocessedObjC) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 919 | .Case("objective-c++-cpp-output", IK_PreprocessedObjCXX) |
Nico Weber | 1f7957d | 2011-08-13 19:03:50 +0000 | [diff] [blame] | 920 | .Case("objc++-cpp-output", IK_PreprocessedObjCXX) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 921 | .Case("c-header", IK_C) |
Peter Collingbourne | ae57ead | 2011-10-09 22:03:19 +0000 | [diff] [blame] | 922 | .Case("cl-header", IK_OpenCL) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 923 | .Case("objective-c-header", IK_ObjC) |
| 924 | .Case("c++-header", IK_CXX) |
| 925 | .Case("objective-c++-header", IK_ObjCXX) |
Douglas Gregor | c544ba0 | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 926 | .Cases("ast", "pcm", IK_AST) |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 927 | .Case("ir", IK_LLVM_IR) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 928 | .Default(IK_None); |
| 929 | if (DashX == IK_None) |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 930 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 931 | << A->getAsString(Args) << A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | // '-' is the default input if none is given. |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 935 | std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 936 | Opts.Inputs.clear(); |
| 937 | if (Inputs.empty()) |
| 938 | Inputs.push_back("-"); |
| 939 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 940 | InputKind IK = DashX; |
| 941 | if (IK == IK_None) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 942 | IK = FrontendOptions::getInputKindForExtension( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 943 | StringRef(Inputs[i]).rsplit('.').second); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 944 | // FIXME: Remove this hack. |
| 945 | if (i == 0) |
| 946 | DashX = IK; |
| 947 | } |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 948 | Opts.Inputs.push_back(FrontendInputFile(Inputs[i], IK)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | return DashX; |
| 952 | } |
| 953 | |
Daniel Dunbar | 8b9adfe | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 954 | std::string CompilerInvocation::GetResourcesPath(const char *Argv0, |
| 955 | void *MainAddr) { |
Rafael Espindola | 3473c8d | 2013-06-26 05:40:30 +0000 | [diff] [blame] | 956 | SmallString<128> P(llvm::sys::fs::getMainExecutable(Argv0, MainAddr)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 957 | |
Rafael Espindola | 3473c8d | 2013-06-26 05:40:30 +0000 | [diff] [blame] | 958 | if (!P.empty()) { |
| 959 | llvm::sys::path::remove_filename(P); // Remove /clang from foo/bin/clang |
| 960 | llvm::sys::path::remove_filename(P); // Remove /bin from foo/bin |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 961 | |
| 962 | // Get foo/lib/clang/<version>/include |
Benjamin Kramer | ceb6dc8 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 963 | llvm::sys::path::append(P, "lib", "clang", CLANG_VERSION_STRING); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | return P.str(); |
| 967 | } |
| 968 | |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 969 | static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 970 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 971 | Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 972 | Opts.Verbose = Args.hasArg(OPT_v); |
Francois Pichet | c91562c | 2011-10-10 20:34:10 +0000 | [diff] [blame] | 973 | Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 974 | Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 975 | Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx); |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 976 | if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 977 | Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 978 | Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir); |
Douglas Gregor | 953a61f | 2013-02-07 19:01:24 +0000 | [diff] [blame] | 979 | Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodules_cache_path); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 980 | Opts.ModuleUserBuildPath = Args.getLastArgValue(OPT_fmodules_user_build_path); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 981 | Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash); |
Daniel Jasper | 056ec12 | 2013-08-05 20:26:17 +0000 | [diff] [blame] | 982 | // -fmodules implies -fmodule-maps |
| 983 | Opts.ModuleMaps = Args.hasArg(OPT_fmodule_maps) || Args.hasArg(OPT_fmodules); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 984 | Opts.ModuleCachePruneInterval = |
| 985 | getLastArgIntValue(Args, OPT_fmodules_prune_interval, 7 * 24 * 60 * 60); |
| 986 | Opts.ModuleCachePruneAfter = |
| 987 | getLastArgIntValue(Args, OPT_fmodules_prune_after, 31 * 24 * 60 * 60); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 988 | Opts.ModulesValidateOncePerBuildSession = |
| 989 | Args.hasArg(OPT_fmodules_validate_once_per_build_session); |
| 990 | Opts.BuildSessionTimestamp = |
| 991 | getLastArgUInt64Value(Args, OPT_fbuild_session_timestamp, 0); |
| 992 | Opts.ModulesValidateSystemHeaders = |
| 993 | Args.hasArg(OPT_fmodules_validate_system_headers); |
| 994 | |
Douglas Gregor | 2a06085 | 2013-02-07 00:21:12 +0000 | [diff] [blame] | 995 | for (arg_iterator it = Args.filtered_begin(OPT_fmodules_ignore_macro), |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 996 | ie = Args.filtered_end(); |
| 997 | it != ie; ++it) { |
Douglas Gregor | 005d51b | 2013-02-07 01:18:48 +0000 | [diff] [blame] | 998 | StringRef MacroDef = (*it)->getValue(); |
| 999 | Opts.ModulesIgnoreMacros.insert(MacroDef.split('=').first); |
Douglas Gregor | 2a06085 | 2013-02-07 00:21:12 +0000 | [diff] [blame] | 1000 | } |
Daniel Jasper | 1b8840c | 2013-09-24 09:27:13 +0000 | [diff] [blame] | 1001 | std::vector<std::string> ModuleMapFiles = |
| 1002 | Args.getAllArgValues(OPT_fmodule_map_file); |
| 1003 | Opts.ModuleMapFiles.insert(ModuleMapFiles.begin(), ModuleMapFiles.end()); |
Douglas Gregor | 2a06085 | 2013-02-07 00:21:12 +0000 | [diff] [blame] | 1004 | |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 1005 | // Add -I..., -F..., and -index-header-map options in order. |
| 1006 | bool IsIndexHeaderMap = false; |
| 1007 | for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F, |
| 1008 | OPT_index_header_map), |
| 1009 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1010 | if ((*it)->getOption().matches(OPT_index_header_map)) { |
| 1011 | // -index-header-map applies to the next -I or -F. |
| 1012 | IsIndexHeaderMap = true; |
| 1013 | continue; |
| 1014 | } |
| 1015 | |
| 1016 | frontend::IncludeDirGroup Group |
| 1017 | = IsIndexHeaderMap? frontend::IndexHeaderMap : frontend::Angled; |
| 1018 | |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 1019 | Opts.AddPath((*it)->getValue(), Group, |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame] | 1020 | /*IsFramework=*/ (*it)->getOption().matches(OPT_F), true); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 1021 | IsIndexHeaderMap = false; |
| 1022 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1023 | |
Daniel Dunbar | f3fc21f | 2013-01-25 01:50:34 +0000 | [diff] [blame] | 1024 | // Add -iprefix/-iwithprefix/-iwithprefixbefore options. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1025 | StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1026 | for (arg_iterator it = Args.filtered_begin(OPT_iprefix, OPT_iwithprefix, |
| 1027 | OPT_iwithprefixbefore), |
| 1028 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1029 | const Arg *A = *it; |
| 1030 | if (A->getOption().matches(OPT_iprefix)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1031 | Prefix = A->getValue(); |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1032 | else if (A->getOption().matches(OPT_iwithprefix)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1033 | Opts.AddPath(Prefix.str() + A->getValue(), |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame] | 1034 | frontend::After, false, true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1035 | else |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1036 | Opts.AddPath(Prefix.str() + A->getValue(), |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame] | 1037 | frontend::Angled, false, true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | for (arg_iterator it = Args.filtered_begin(OPT_idirafter), |
| 1041 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame] | 1042 | Opts.AddPath((*it)->getValue(), frontend::After, false, true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1043 | for (arg_iterator it = Args.filtered_begin(OPT_iquote), |
| 1044 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | c33c9f7 | 2013-01-29 23:59:45 +0000 | [diff] [blame] | 1045 | Opts.AddPath((*it)->getValue(), frontend::Quoted, false, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1046 | for (arg_iterator it = Args.filtered_begin(OPT_isystem, |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1047 | OPT_iwithsysroot), ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 1048 | Opts.AddPath((*it)->getValue(), frontend::System, false, |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1049 | !(*it)->getOption().matches(OPT_iwithsysroot)); |
Daniel Dunbar | 024f4be | 2011-10-18 20:40:38 +0000 | [diff] [blame] | 1050 | for (arg_iterator it = Args.filtered_begin(OPT_iframework), |
| 1051 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 1052 | Opts.AddPath((*it)->getValue(), frontend::System, true, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1053 | |
| 1054 | // Add the paths for the various language specific isystem flags. |
| 1055 | for (arg_iterator it = Args.filtered_begin(OPT_c_isystem), |
| 1056 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 1057 | Opts.AddPath((*it)->getValue(), frontend::CSystem, false, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1058 | for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem), |
| 1059 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 1060 | Opts.AddPath((*it)->getValue(), frontend::CXXSystem, false, true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1061 | for (arg_iterator it = Args.filtered_begin(OPT_objc_isystem), |
| 1062 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 1063 | Opts.AddPath((*it)->getValue(), frontend::ObjCSystem, false,true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1064 | for (arg_iterator it = Args.filtered_begin(OPT_objcxx_isystem), |
| 1065 | ie = Args.filtered_end(); it != ie; ++it) |
Daniel Dunbar | eab6652 | 2013-01-25 01:50:47 +0000 | [diff] [blame] | 1066 | Opts.AddPath((*it)->getValue(), frontend::ObjCXXSystem, false, true); |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1067 | |
| 1068 | // Add the internal paths from a driver that detects standard include paths. |
| 1069 | for (arg_iterator I = Args.filtered_begin(OPT_internal_isystem, |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 1070 | OPT_internal_externc_isystem), |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1071 | E = Args.filtered_end(); |
Daniel Dunbar | ef84554 | 2013-01-30 00:19:24 +0000 | [diff] [blame] | 1072 | I != E; ++I) { |
| 1073 | frontend::IncludeDirGroup Group = frontend::System; |
| 1074 | if ((*I)->getOption().matches(OPT_internal_externc_isystem)) |
| 1075 | Group = frontend::ExternCSystem; |
Daniel Dunbar | 59fd635 | 2013-01-30 00:34:26 +0000 | [diff] [blame] | 1076 | Opts.AddPath((*I)->getValue(), Group, false, true); |
Daniel Dunbar | ef84554 | 2013-01-30 00:19:24 +0000 | [diff] [blame] | 1077 | } |
Richard Smith | f122a13 | 2012-06-13 20:27:03 +0000 | [diff] [blame] | 1078 | |
| 1079 | // Add the path prefixes which are implicitly treated as being system headers. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1080 | for (arg_iterator I = Args.filtered_begin(OPT_system_header_prefix, |
| 1081 | OPT_no_system_header_prefix), |
Richard Smith | f122a13 | 2012-06-13 20:27:03 +0000 | [diff] [blame] | 1082 | E = Args.filtered_end(); |
| 1083 | I != E; ++I) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1084 | Opts.AddSystemHeaderPrefix( |
| 1085 | (*I)->getValue(), (*I)->getOption().matches(OPT_system_header_prefix)); |
| 1086 | |
| 1087 | for (arg_iterator I = Args.filtered_begin(OPT_ivfsoverlay), |
| 1088 | E = Args.filtered_end(); I != E; ++I) |
| 1089 | Opts.AddVFSOverlayFile((*I)->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1092 | void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, |
| 1093 | LangStandard::Kind LangStd) { |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1094 | // 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] | 1095 | // to move these to the language standard, and have the driver resolve the |
| 1096 | // input kind + language standard. |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1097 | if (IK == IK_Asm) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1098 | Opts.AsmPreprocessor = 1; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1099 | } else if (IK == IK_ObjC || |
| 1100 | IK == IK_ObjCXX || |
| 1101 | IK == IK_PreprocessedObjC || |
| 1102 | IK == IK_PreprocessedObjCXX) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1103 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 1104 | } |
| 1105 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1106 | if (LangStd == LangStandard::lang_unspecified) { |
| 1107 | // Based on the base language, pick one. |
| 1108 | switch (IK) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1109 | case IK_None: |
| 1110 | case IK_AST: |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 1111 | case IK_LLVM_IR: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1112 | llvm_unreachable("Invalid input kind!"); |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1113 | case IK_OpenCL: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1114 | LangStd = LangStandard::lang_opencl; |
| 1115 | break; |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1116 | case IK_CUDA: |
| 1117 | LangStd = LangStandard::lang_cuda; |
| 1118 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1119 | case IK_Asm: |
| 1120 | case IK_C: |
| 1121 | case IK_PreprocessedC: |
| 1122 | case IK_ObjC: |
| 1123 | case IK_PreprocessedObjC: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1124 | LangStd = LangStandard::lang_gnu99; |
| 1125 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1126 | case IK_CXX: |
| 1127 | case IK_PreprocessedCXX: |
| 1128 | case IK_ObjCXX: |
| 1129 | case IK_PreprocessedObjCXX: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1130 | LangStd = LangStandard::lang_gnucxx98; |
| 1131 | break; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
Nico Weber | bb23628 | 2012-11-11 07:02:14 +0000 | [diff] [blame] | 1136 | Opts.LineComment = Std.hasLineComments(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1137 | Opts.C99 = Std.isC99(); |
Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 1138 | Opts.C11 = Std.isC11(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1139 | Opts.CPlusPlus = Std.isCPlusPlus(); |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1140 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); |
Richard Smith | 5ba49c0 | 2012-10-17 23:07:52 +0000 | [diff] [blame] | 1141 | Opts.CPlusPlus1y = Std.isCPlusPlus1y(); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1142 | Opts.CPlusPlus1z = Std.isCPlusPlus1z(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1143 | Opts.Digraphs = Std.hasDigraphs(); |
| 1144 | Opts.GNUMode = Std.isGNUMode(); |
| 1145 | Opts.GNUInline = !Std.isC99(); |
| 1146 | Opts.HexFloats = Std.hasHexFloats(); |
| 1147 | Opts.ImplicitInt = Std.hasImplicitInt(); |
| 1148 | |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 1149 | // Set OpenCL Version. |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1150 | Opts.OpenCL = LangStd == LangStandard::lang_opencl || IK == IK_OpenCL; |
| 1151 | if (LangStd == LangStandard::lang_opencl) |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 1152 | Opts.OpenCLVersion = 100; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1153 | else if (LangStd == LangStandard::lang_opencl11) |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 1154 | Opts.OpenCLVersion = 110; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1155 | else if (LangStd == LangStandard::lang_opencl12) |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 1156 | Opts.OpenCLVersion = 120; |
Tanya Lattner | f4205e1 | 2012-06-18 22:55:02 +0000 | [diff] [blame] | 1157 | |
| 1158 | // OpenCL has some additional defaults. |
| 1159 | if (Opts.OpenCL) { |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 1160 | Opts.AltiVec = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1161 | Opts.CXXOperatorNames = 1; |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 1162 | Opts.LaxVectorConversions = 0; |
Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1163 | Opts.DefaultFPContract = 1; |
Joey Gouly | 19dbb20 | 2013-01-23 11:56:20 +0000 | [diff] [blame] | 1164 | Opts.NativeHalfType = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1167 | Opts.CUDA = LangStd == LangStandard::lang_cuda || IK == IK_CUDA; |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1168 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1169 | // OpenCL and C++ both have bool, true, false keywords. |
| 1170 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
| 1171 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1172 | // OpenCL has half keyword |
| 1173 | Opts.Half = Opts.OpenCL; |
| 1174 | |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 1175 | // C++ has wchar_t keyword. |
| 1176 | Opts.WChar = Opts.CPlusPlus; |
| 1177 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1178 | Opts.GNUKeywords = Opts.GNUMode; |
| 1179 | Opts.CXXOperatorNames = Opts.CPlusPlus; |
| 1180 | |
| 1181 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 1182 | // is specified, or -std is set to a conforming mode. |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1183 | // Trigraphs are disabled by default in c++1z onwards. |
| 1184 | Opts.Trigraphs = !Opts.GNUMode && !Opts.CPlusPlus1z; |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1185 | |
| 1186 | Opts.DollarIdents = !Opts.AsmPreprocessor; |
Richard Smith | 3cebc73 | 2013-11-05 09:12:18 +0000 | [diff] [blame] | 1187 | |
| 1188 | // C++1y onwards has sized global deallocation functions. |
| 1189 | Opts.SizedDeallocation = Opts.CPlusPlus1y; |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
John McCall | a880b19 | 2013-02-19 01:57:35 +0000 | [diff] [blame] | 1192 | /// Attempt to parse a visibility value out of the given argument. |
| 1193 | static Visibility parseVisibility(Arg *arg, ArgList &args, |
| 1194 | DiagnosticsEngine &diags) { |
| 1195 | StringRef value = arg->getValue(); |
| 1196 | if (value == "default") { |
| 1197 | return DefaultVisibility; |
| 1198 | } else if (value == "hidden") { |
| 1199 | return HiddenVisibility; |
| 1200 | } else if (value == "protected") { |
| 1201 | // FIXME: diagnose if target does not support protected visibility |
| 1202 | return ProtectedVisibility; |
| 1203 | } |
| 1204 | |
| 1205 | diags.Report(diag::err_drv_invalid_value) |
| 1206 | << arg->getAsString(args) << value; |
| 1207 | return DefaultVisibility; |
| 1208 | } |
| 1209 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1210 | static unsigned parseMSCVersion(ArgList &Args, DiagnosticsEngine &Diags) { |
| 1211 | auto Arg = Args.getLastArg(OPT_fmsc_version); |
| 1212 | if (!Arg) |
| 1213 | return 0; |
| 1214 | |
| 1215 | // The MSC versioning scheme involves four versioning components: |
| 1216 | // - Major |
| 1217 | // - Minor |
| 1218 | // - Build |
| 1219 | // - Patch |
| 1220 | // |
| 1221 | // We accept either the old style (_MSC_VER) value, or a _MSC_FULL_VER value. |
| 1222 | // Additionally, the value may be provided in the form of a more readable |
| 1223 | // MM.mm.bbbbb.pp version. |
| 1224 | // |
| 1225 | // Unfortunately, due to the bit-width limitations, we cannot currently encode |
| 1226 | // the value for the patch level. |
| 1227 | |
| 1228 | StringRef Value = Arg->getValue(); |
| 1229 | |
| 1230 | // parse the compatible old form of _MSC_VER or the newer _MSC_FULL_VER |
| 1231 | if (Value.find('.') == StringRef::npos) { |
| 1232 | unsigned Version = 0; |
| 1233 | if (Value.getAsInteger(10, Version)) { |
| 1234 | Diags.Report(diag::err_drv_invalid_value) |
| 1235 | << Arg->getAsString(Args) << Value; |
| 1236 | return 0; |
| 1237 | } |
| 1238 | if (Version < 100) |
| 1239 | Version = Version * 100; // major -> major.minor |
| 1240 | if (Version < 100000) |
| 1241 | Version = Version * 100000; // major.minor -> major.minor.build |
| 1242 | return Version; |
| 1243 | } |
| 1244 | |
| 1245 | // parse the dot-delimited component version |
| 1246 | unsigned VC[4] = {0}; |
| 1247 | SmallVector<StringRef, 4> Components; |
| 1248 | |
| 1249 | Value.split(Components, ".", llvm::array_lengthof(VC)); |
| 1250 | for (unsigned CI = 0, |
| 1251 | CE = std::min(Components.size(), llvm::array_lengthof(VC)); |
| 1252 | CI < CE; ++CI) { |
| 1253 | if (Components[CI].getAsInteger(10, VC[CI])) { |
| 1254 | Diags.Report(diag::err_drv_invalid_value) |
| 1255 | << Arg->getAsString(Args) << Value; |
| 1256 | return 0; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | // FIXME we cannot encode the patch level |
| 1261 | return VC[0] * 10000000 + VC[1] * 100000 + VC[2]; |
| 1262 | } |
| 1263 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1264 | static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1265 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1266 | // FIXME: Cleanup per-file based stuff. |
| 1267 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 1268 | if (const Arg *A = Args.getLastArg(OPT_std_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1269 | LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1270 | #define LANGSTANDARD(id, name, desc, features) \ |
| 1271 | .Case(name, LangStandard::lang_##id) |
| 1272 | #include "clang/Frontend/LangStandards.def" |
| 1273 | .Default(LangStandard::lang_unspecified); |
| 1274 | if (LangStd == LangStandard::lang_unspecified) |
| 1275 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1276 | << A->getAsString(Args) << A->getValue(); |
Chad Rosier | b2dba4b | 2011-05-02 19:24:53 +0000 | [diff] [blame] | 1277 | else { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1278 | // Valid standard, check to make sure language and standard are |
| 1279 | // compatible. |
Chad Rosier | b2dba4b | 2011-05-02 19:24:53 +0000 | [diff] [blame] | 1280 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 1281 | switch (IK) { |
| 1282 | case IK_C: |
| 1283 | case IK_ObjC: |
| 1284 | case IK_PreprocessedC: |
| 1285 | case IK_PreprocessedObjC: |
| 1286 | if (!(Std.isC89() || Std.isC99())) |
| 1287 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1288 | << A->getAsString(Args) << "C/ObjC"; |
| 1289 | break; |
| 1290 | case IK_CXX: |
| 1291 | case IK_ObjCXX: |
| 1292 | case IK_PreprocessedCXX: |
| 1293 | case IK_PreprocessedObjCXX: |
| 1294 | if (!Std.isCPlusPlus()) |
| 1295 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1296 | << A->getAsString(Args) << "C++/ObjC++"; |
| 1297 | break; |
| 1298 | case IK_OpenCL: |
| 1299 | if (!Std.isC99()) |
| 1300 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1301 | << A->getAsString(Args) << "OpenCL"; |
| 1302 | break; |
| 1303 | case IK_CUDA: |
| 1304 | if (!Std.isCPlusPlus()) |
| 1305 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1306 | << A->getAsString(Args) << "CUDA"; |
| 1307 | break; |
| 1308 | default: |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1314 | // -cl-std only applies for OpenCL language standards. |
| 1315 | // Override the -std option in this case. |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1316 | if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1317 | LangStandard::Kind OpenCLLangStd |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1318 | = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1319 | .Case("CL", LangStandard::lang_opencl) |
| 1320 | .Case("CL1.1", LangStandard::lang_opencl11) |
| 1321 | .Case("CL1.2", LangStandard::lang_opencl12) |
| 1322 | .Default(LangStandard::lang_unspecified); |
| 1323 | |
| 1324 | if (OpenCLLangStd == LangStandard::lang_unspecified) { |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1325 | Diags.Report(diag::err_drv_invalid_value) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1326 | << A->getAsString(Args) << A->getValue(); |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1327 | } |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1328 | else |
| 1329 | LangStd = OpenCLLangStd; |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1330 | } |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 1331 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1332 | CompilerInvocation::setLangDefaults(Opts, IK, LangStd); |
| 1333 | |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1334 | // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension |
| 1335 | // keywords. This behavior is provided by GCC's poorly named '-fasm' flag, |
| 1336 | // while a subset (the non-C++ GNU keywords) is provided by GCC's |
| 1337 | // '-fgnu-keywords'. Clang conflates the two for simplicity under the single |
| 1338 | // name, as it doesn't seem a useful distinction. |
| 1339 | Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1340 | Opts.GNUKeywords); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1341 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1342 | if (Args.hasArg(OPT_fno_operator_names)) |
| 1343 | Opts.CXXOperatorNames = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1344 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1345 | if (Opts.ObjC1) { |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1346 | if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1347 | StringRef value = arg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1348 | if (Opts.ObjCRuntime.tryParse(value)) |
| 1349 | Diags.Report(diag::err_drv_unknown_objc_runtime) << value; |
| 1350 | } |
| 1351 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1352 | if (Args.hasArg(OPT_fobjc_gc_only)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1353 | Opts.setGC(LangOptions::GCOnly); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1354 | else if (Args.hasArg(OPT_fobjc_gc)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1355 | Opts.setGC(LangOptions::HybridGC); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1356 | else if (Args.hasArg(OPT_fobjc_arc)) { |
| 1357 | Opts.ObjCAutoRefCount = 1; |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1358 | if (!Opts.ObjCRuntime.allowsARC()) |
| 1359 | Diags.Report(diag::err_arc_unsupported_on_runtime); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1360 | |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1361 | // Only set ObjCARCWeak if ARC is enabled. |
| 1362 | if (Args.hasArg(OPT_fobjc_runtime_has_weak)) |
| 1363 | Opts.ObjCARCWeak = 1; |
| 1364 | else |
| 1365 | Opts.ObjCARCWeak = Opts.ObjCRuntime.allowsWeak(); |
| 1366 | } |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 1367 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1368 | if (Args.hasArg(OPT_fno_objc_infer_related_result_type)) |
| 1369 | Opts.ObjCInferRelatedResultType = 0; |
Fariborz Jahanian | d9553e3 | 2013-11-01 21:58:17 +0000 | [diff] [blame] | 1370 | |
| 1371 | if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime)) |
| 1372 | Opts.ObjCSubscriptingLegacyRuntime = |
| 1373 | (Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
Rafael Espindola | fb3f4aa | 2011-06-02 16:13:27 +0000 | [diff] [blame] | 1376 | if (Args.hasArg(OPT_fgnu89_inline)) |
| 1377 | Opts.GNUInline = 1; |
| 1378 | |
Fariborz Jahanian | 142f9e9 | 2011-02-04 00:01:24 +0000 | [diff] [blame] | 1379 | if (Args.hasArg(OPT_fapple_kext)) { |
| 1380 | if (!Opts.CPlusPlus) |
| 1381 | Diags.Report(diag::warn_c_kext); |
| 1382 | else |
| 1383 | Opts.AppleKext = 1; |
| 1384 | } |
| 1385 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1386 | if (Args.hasArg(OPT_print_ivar_layout)) |
| 1387 | Opts.ObjCGCBitmapPrint = 1; |
Fariborz Jahanian | 33e982b | 2010-04-22 20:26:39 +0000 | [diff] [blame] | 1388 | if (Args.hasArg(OPT_fno_constant_cfstrings)) |
| 1389 | Opts.NoConstantCFStrings = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1390 | |
| 1391 | if (Args.hasArg(OPT_faltivec)) |
| 1392 | Opts.AltiVec = 1; |
| 1393 | |
| 1394 | if (Args.hasArg(OPT_pthread)) |
| 1395 | Opts.POSIXThreads = 1; |
| 1396 | |
John McCall | a880b19 | 2013-02-19 01:57:35 +0000 | [diff] [blame] | 1397 | // The value-visibility mode defaults to "default". |
| 1398 | if (Arg *visOpt = Args.getLastArg(OPT_fvisibility)) { |
| 1399 | Opts.setValueVisibilityMode(parseVisibility(visOpt, Args, Diags)); |
| 1400 | } else { |
| 1401 | Opts.setValueVisibilityMode(DefaultVisibility); |
| 1402 | } |
| 1403 | |
| 1404 | // The type-visibility mode defaults to the value-visibility mode. |
| 1405 | if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) { |
| 1406 | Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags)); |
| 1407 | } else { |
| 1408 | Opts.setTypeVisibilityMode(Opts.getValueVisibilityMode()); |
| 1409 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1410 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 1411 | if (Args.hasArg(OPT_fvisibility_inlines_hidden)) |
| 1412 | Opts.InlineVisibilityHidden = 1; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1413 | |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 1414 | if (Args.hasArg(OPT_ftrapv)) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1415 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 1416 | // Set the handler, if one is specified. |
| 1417 | Opts.OverflowHandler = |
| 1418 | Args.getLastArgValue(OPT_ftrapv_handler); |
| 1419 | } |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 1420 | else if (Args.hasArg(OPT_fwrapv)) |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1421 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1422 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1423 | if (Args.hasArg(OPT_trigraphs)) |
| 1424 | Opts.Trigraphs = 1; |
| 1425 | |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 1426 | Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, |
| 1427 | OPT_fno_dollars_in_identifiers, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1428 | Opts.DollarIdents); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1429 | Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1430 | Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility); |
| 1431 | Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions); |
Chad Rosier | 4fb10d1 | 2012-12-05 23:35:10 +0000 | [diff] [blame] | 1432 | Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1433 | Opts.MSCVersion = parseMSCVersion(Args, Diags); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1434 | Opts.VtorDispMode = getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags); |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 1435 | Opts.Borland = Args.hasArg(OPT_fborland_extensions); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1436 | Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 1437 | Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings, |
| 1438 | Opts.ConstStrings); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1439 | if (Args.hasArg(OPT_fno_lax_vector_conversions)) |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 1440 | Opts.LaxVectorConversions = 0; |
| 1441 | if (Args.hasArg(OPT_fno_threadsafe_statics)) |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 1442 | Opts.ThreadsafeStatics = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1443 | Opts.Exceptions = Args.hasArg(OPT_fexceptions); |
Anders Carlsson | e9b801f | 2011-02-22 01:52:06 +0000 | [diff] [blame] | 1444 | Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 1445 | Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions); |
| 1446 | Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); |
Daniel Dunbar | 2ed4228 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 1447 | Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 1448 | |
Mike Stump | de05057 | 2009-12-02 18:57:08 +0000 | [diff] [blame] | 1449 | Opts.RTTI = !Args.hasArg(OPT_fno_rtti); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1450 | Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1451 | Opts.Blocks = Args.hasArg(OPT_fblocks); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 1452 | Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); |
Douglas Gregor | 752c74d | 2012-01-03 17:07:34 +0000 | [diff] [blame] | 1453 | Opts.Modules = Args.hasArg(OPT_fmodules); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1454 | Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse); |
| 1455 | Opts.ModulesDeclUse = |
| 1456 | Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse; |
| 1457 | Opts.ModulesSearchAll = Opts.Modules && |
| 1458 | !Args.hasArg(OPT_fno_modules_search_all) && |
| 1459 | Args.hasArg(OPT_fmodules_search_all); |
| 1460 | Opts.ModulesErrorRecovery = !Args.hasArg(OPT_fno_modules_error_recovery); |
David Tweed | 8bc5602 | 2013-09-09 09:17:24 +0000 | [diff] [blame] | 1461 | Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char); |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 1462 | Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1463 | Opts.ShortWChar = Args.hasFlag(OPT_fshort_wchar, OPT_fno_short_wchar, false); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 1464 | Opts.ShortEnums = Args.hasArg(OPT_fshort_enums); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1465 | Opts.Freestanding = Args.hasArg(OPT_ffreestanding); |
| 1466 | Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; |
Eli Bendersky | 264d206 | 2013-07-23 00:13:01 +0000 | [diff] [blame] | 1467 | Opts.NoMathBuiltin = Args.hasArg(OPT_fno_math_builtin); |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 1468 | Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); |
Richard Smith | 3cebc73 | 2013-11-05 09:12:18 +0000 | [diff] [blame] | 1469 | Opts.SizedDeallocation |= Args.hasArg(OPT_fsized_deallocation); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1470 | Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 1471 | Opts.AccessControl = !Args.hasArg(OPT_fno_access_control); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1472 | Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); |
David Tweed | 8bc5602 | 2013-09-09 09:17:24 +0000 | [diff] [blame] | 1473 | Opts.MathErrno = !Opts.OpenCL && Args.hasArg(OPT_fmath_errno); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 1474 | Opts.InstantiationDepth = |
| 1475 | getLastArgIntValue(Args, OPT_ftemplate_depth, 256, Diags); |
Richard Smith | 195dd7c | 2013-11-06 19:31:51 +0000 | [diff] [blame] | 1476 | Opts.ArrowDepth = |
| 1477 | getLastArgIntValue(Args, OPT_foperator_arrow_depth, 256, Diags); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 1478 | Opts.ConstexprCallDepth = |
| 1479 | getLastArgIntValue(Args, OPT_fconstexpr_depth, 512, Diags); |
| 1480 | Opts.ConstexprStepLimit = |
| 1481 | getLastArgIntValue(Args, OPT_fconstexpr_steps, 1048576, Diags); |
| 1482 | Opts.BracketDepth = getLastArgIntValue(Args, OPT_fbracket_depth, 256, Diags); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1483 | Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 1484 | Opts.NumLargeByValueCopy = |
| 1485 | getLastArgIntValue(Args, OPT_Wlarge_by_value_copy_EQ, 0, Diags); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 1486 | Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1487 | Opts.ObjCConstantStringClass = |
| 1488 | Args.getLastArgValue(OPT_fconstant_string_class); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 1489 | Opts.ObjCDefaultSynthProperties = |
Rafael Espindola | 14f9889 | 2013-09-27 20:21:48 +0000 | [diff] [blame] | 1490 | !Args.hasArg(OPT_disable_objc_default_synthesize_properties); |
Fariborz Jahanian | 3d145f6 | 2012-11-15 19:02:45 +0000 | [diff] [blame] | 1491 | Opts.EncodeExtendedBlockSig = |
| 1492 | Args.hasArg(OPT_fencode_extended_block_signature); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1493 | Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 1494 | Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags); |
| 1495 | Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); |
| 1496 | Opts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1497 | Opts.Static = Args.hasArg(OPT_static_define); |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 1498 | Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple); |
| 1499 | Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple |
| 1500 | || Args.hasArg(OPT_fdump_record_layouts); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 1501 | Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 1502 | Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking); |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 1503 | Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); |
Peter Collingbourne | 0982136 | 2010-12-04 01:50:56 +0000 | [diff] [blame] | 1504 | Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 1505 | Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1506 | Opts.MRTD = Args.hasArg(OPT_mrtd); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1507 | Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 1508 | Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map); |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 1509 | Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype); |
John McCall | 48218c6 | 2011-07-13 17:56:40 +0000 | [diff] [blame] | 1510 | Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support); |
Sean Callanan | 50a9a12 | 2012-02-04 01:29:37 +0000 | [diff] [blame] | 1511 | Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1512 | Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal); |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 1513 | Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack); |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 1514 | Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1515 | |
David Tweed | 1eef852 | 2013-09-13 12:04:22 +0000 | [diff] [blame] | 1516 | if (Arg *A = Args.getLastArg(OPT_faddress_space_map_mangling_EQ)) { |
| 1517 | switch (llvm::StringSwitch<unsigned>(A->getValue()) |
| 1518 | .Case("target", LangOptions::ASMM_Target) |
| 1519 | .Case("no", LangOptions::ASMM_Off) |
| 1520 | .Case("yes", LangOptions::ASMM_On) |
| 1521 | .Default(255)) { |
| 1522 | default: |
| 1523 | Diags.Report(diag::err_drv_invalid_value) |
| 1524 | << "-faddress-space-map-mangling=" << A->getValue(); |
| 1525 | break; |
| 1526 | case LangOptions::ASMM_Target: |
| 1527 | Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Target); |
| 1528 | break; |
| 1529 | case LangOptions::ASMM_On: |
| 1530 | Opts.setAddressSpaceMapMangling(LangOptions::ASMM_On); |
| 1531 | break; |
| 1532 | case LangOptions::ASMM_Off: |
| 1533 | Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Off); |
| 1534 | break; |
| 1535 | } |
| 1536 | } |
| 1537 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1538 | if (Arg *A = Args.getLastArg(OPT_fms_memptr_rep_EQ)) { |
| 1539 | LangOptions::PragmaMSPointersToMembersKind InheritanceModel = |
| 1540 | llvm::StringSwitch<LangOptions::PragmaMSPointersToMembersKind>( |
| 1541 | A->getValue()) |
| 1542 | .Case("single", |
| 1543 | LangOptions::PPTMK_FullGeneralitySingleInheritance) |
| 1544 | .Case("multiple", |
| 1545 | LangOptions::PPTMK_FullGeneralityMultipleInheritance) |
| 1546 | .Case("virtual", |
| 1547 | LangOptions::PPTMK_FullGeneralityVirtualInheritance) |
| 1548 | .Default(LangOptions::PPTMK_BestCase); |
| 1549 | if (InheritanceModel == LangOptions::PPTMK_BestCase) |
| 1550 | Diags.Report(diag::err_drv_invalid_value) |
| 1551 | << "-fms-memptr-rep=" << A->getValue(); |
| 1552 | |
| 1553 | Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel); |
| 1554 | } |
| 1555 | |
| 1556 | // Check if -fopenmp= is specified. |
| 1557 | if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) { |
| 1558 | Opts.OpenMP = llvm::StringSwitch<bool>(A->getValue()) |
| 1559 | .Case("libiomp5", true) |
| 1560 | .Default(false); |
| 1561 | } |
Douglas Gregor | 50a70cd | 2013-01-15 06:45:29 +0000 | [diff] [blame] | 1562 | |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 1563 | // Record whether the __DEPRECATED define was requested. |
| 1564 | Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro, |
| 1565 | OPT_fno_deprecated_macro, |
| 1566 | Opts.Deprecated); |
| 1567 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1568 | // FIXME: Eliminate this dependency. |
Dylan Noblesmith | f23e8d2 | 2012-08-08 16:09:15 +0000 | [diff] [blame] | 1569 | unsigned Opt = getOptimizationLevel(Args, IK, Diags), |
Chad Rosier | 0542236 | 2013-04-10 21:30:03 +0000 | [diff] [blame] | 1570 | OptSize = getOptimizationLevelSize(Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1571 | Opts.Optimize = Opt != 0; |
Dylan Noblesmith | f23e8d2 | 2012-08-08 16:09:15 +0000 | [diff] [blame] | 1572 | Opts.OptimizeSize = OptSize != 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1573 | |
| 1574 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 1575 | // optimization level and -fno-inline, not actually whether the backend has |
| 1576 | // inlining enabled. |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 1577 | Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1578 | |
Chad Rosier | b82e117 | 2013-04-24 18:09:54 +0000 | [diff] [blame] | 1579 | Opts.FastMath = Args.hasArg(OPT_ffast_math); |
Bob Wilson | 455e72e | 2012-07-19 03:52:53 +0000 | [diff] [blame] | 1580 | Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1581 | |
Ted Kremenek | 127ff2e | 2012-09-13 06:41:18 +0000 | [diff] [blame] | 1582 | Opts.RetainCommentsFromSystemHeaders = |
| 1583 | Args.hasArg(OPT_fretain_comments_from_system_headers); |
| 1584 | |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 1585 | unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1586 | switch (SSP) { |
| 1587 | default: |
| 1588 | Diags.Report(diag::err_drv_invalid_value) |
| 1589 | << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; |
| 1590 | break; |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1591 | case 0: Opts.setStackProtector(LangOptions::SSPOff); break; |
| 1592 | case 1: Opts.setStackProtector(LangOptions::SSPOn); break; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1593 | case 2: Opts.setStackProtector(LangOptions::SSPStrong); break; |
| 1594 | case 3: Opts.setStackProtector(LangOptions::SSPReq); break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1595 | } |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1596 | |
| 1597 | // Parse -fsanitize= arguments. |
| 1598 | std::vector<std::string> Sanitizers = Args.getAllArgValues(OPT_fsanitize_EQ); |
| 1599 | for (unsigned I = 0, N = Sanitizers.size(); I != N; ++I) { |
| 1600 | // Since the Opts.Sanitize* values are bitfields, it's a little tricky to |
| 1601 | // efficiently map string values to them. Perform the mapping indirectly: |
| 1602 | // convert strings to enumerated values, then switch over the enum to set |
| 1603 | // the right bitfield value. |
| 1604 | enum Sanitizer { |
| 1605 | #define SANITIZER(NAME, ID) \ |
| 1606 | ID, |
| 1607 | #include "clang/Basic/Sanitizers.def" |
| 1608 | Unknown |
| 1609 | }; |
| 1610 | switch (llvm::StringSwitch<unsigned>(Sanitizers[I]) |
| 1611 | #define SANITIZER(NAME, ID) \ |
| 1612 | .Case(NAME, ID) |
| 1613 | #include "clang/Basic/Sanitizers.def" |
| 1614 | .Default(Unknown)) { |
| 1615 | #define SANITIZER(NAME, ID) \ |
| 1616 | case ID: \ |
Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1617 | Opts.Sanitize.ID = true; \ |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1618 | break; |
| 1619 | #include "clang/Basic/Sanitizers.def" |
| 1620 | |
| 1621 | case Unknown: |
| 1622 | Diags.Report(diag::err_drv_invalid_value) |
| 1623 | << "-fsanitize=" << Sanitizers[I]; |
| 1624 | break; |
| 1625 | } |
| 1626 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1629 | static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1630 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1631 | DiagnosticsEngine &Diags) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1632 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1633 | Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch); |
| 1634 | Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1635 | if (const Arg *A = Args.getLastArg(OPT_token_cache)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1636 | Opts.TokenCache = A->getValue(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1637 | else |
| 1638 | Opts.TokenCache = Opts.ImplicitPTHInclude; |
| 1639 | Opts.UsePredefines = !Args.hasArg(OPT_undef); |
Douglas Gregor | 94dc8f6 | 2010-03-19 16:15:56 +0000 | [diff] [blame] | 1640 | Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1641 | Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1642 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 1643 | Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1644 | for (arg_iterator it = Args.filtered_begin(OPT_error_on_deserialized_pch_decl), |
| 1645 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1646 | const Arg *A = *it; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1647 | Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue()); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1648 | } |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1650 | if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1651 | StringRef Value(A->getValue()); |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1652 | size_t Comma = Value.find(','); |
| 1653 | unsigned Bytes = 0; |
| 1654 | unsigned EndOfLine = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1655 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1656 | if (Comma == StringRef::npos || |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1657 | Value.substr(0, Comma).getAsInteger(10, Bytes) || |
| 1658 | Value.substr(Comma + 1).getAsInteger(10, EndOfLine)) |
| 1659 | Diags.Report(diag::err_drv_preamble_format); |
| 1660 | else { |
| 1661 | Opts.PrecompiledPreambleBytes.first = Bytes; |
| 1662 | Opts.PrecompiledPreambleBytes.second = (EndOfLine != 0); |
| 1663 | } |
| 1664 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1665 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1666 | // Add macros from the command line. |
| 1667 | for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U), |
| 1668 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1669 | if ((*it)->getOption().matches(OPT_D)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1670 | Opts.addMacroDef((*it)->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1671 | else |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1672 | Opts.addMacroUndef((*it)->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1675 | Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1676 | |
| 1677 | // Add the ordered list of -includes. |
Argyrios Kyrtzidis | 3ad86fd | 2013-02-05 16:36:52 +0000 | [diff] [blame] | 1678 | for (arg_iterator it = Args.filtered_begin(OPT_include), |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1679 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1680 | const Arg *A = *it; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1681 | Opts.Includes.push_back(A->getValue()); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1682 | } |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1683 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 1684 | for (arg_iterator it = Args.filtered_begin(OPT_chain_include), |
| 1685 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1686 | const Arg *A = *it; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1687 | Opts.ChainedIncludes.push_back(A->getValue()); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1690 | // Include 'altivec.h' if -faltivec option present |
| 1691 | if (Args.hasArg(OPT_faltivec)) |
| 1692 | Opts.Includes.push_back("altivec.h"); |
| 1693 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1694 | for (arg_iterator it = Args.filtered_begin(OPT_remap_file), |
| 1695 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1696 | const Arg *A = *it; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1697 | std::pair<StringRef,StringRef> Split = |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1698 | StringRef(A->getValue()).split(';'); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1699 | |
| 1700 | if (Split.second.empty()) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1701 | Diags.Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1702 | continue; |
| 1703 | } |
| 1704 | |
| 1705 | Opts.addRemappedFile(Split.first, Split.second); |
| 1706 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1707 | |
| 1708 | if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1709 | StringRef Name = A->getValue(); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1710 | unsigned Library = llvm::StringSwitch<unsigned>(Name) |
| 1711 | .Case("libc++", ARCXX_libcxx) |
| 1712 | .Case("libstdc++", ARCXX_libstdcxx) |
| 1713 | .Case("none", ARCXX_nolib) |
| 1714 | .Default(~0U); |
| 1715 | if (Library == ~0U) |
| 1716 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 1717 | else |
| 1718 | Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library; |
| 1719 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, |
Jordan Rose | 74c2498 | 2013-01-30 01:52:57 +0000 | [diff] [blame] | 1723 | ArgList &Args, |
| 1724 | frontend::ActionKind Action) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1725 | using namespace options; |
Jordan Rose | 74c2498 | 2013-01-30 01:52:57 +0000 | [diff] [blame] | 1726 | |
| 1727 | switch (Action) { |
| 1728 | case frontend::ASTDeclList: |
| 1729 | case frontend::ASTDump: |
Jordan Rose | 74c2498 | 2013-01-30 01:52:57 +0000 | [diff] [blame] | 1730 | case frontend::ASTPrint: |
| 1731 | case frontend::ASTView: |
| 1732 | case frontend::EmitAssembly: |
| 1733 | case frontend::EmitBC: |
| 1734 | case frontend::EmitHTML: |
| 1735 | case frontend::EmitLLVM: |
| 1736 | case frontend::EmitLLVMOnly: |
| 1737 | case frontend::EmitCodeGenOnly: |
| 1738 | case frontend::EmitObj: |
| 1739 | case frontend::FixIt: |
| 1740 | case frontend::GenerateModule: |
| 1741 | case frontend::GeneratePCH: |
| 1742 | case frontend::GeneratePTH: |
| 1743 | case frontend::ParseSyntaxOnly: |
Douglas Gregor | c544ba0 | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 1744 | case frontend::ModuleFileInfo: |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1745 | case frontend::VerifyPCH: |
Jordan Rose | 74c2498 | 2013-01-30 01:52:57 +0000 | [diff] [blame] | 1746 | case frontend::PluginAction: |
| 1747 | case frontend::PrintDeclContext: |
| 1748 | case frontend::RewriteObjC: |
| 1749 | case frontend::RewriteTest: |
| 1750 | case frontend::RunAnalysis: |
| 1751 | case frontend::MigrateSource: |
| 1752 | Opts.ShowCPP = 0; |
| 1753 | break; |
| 1754 | |
| 1755 | case frontend::DumpRawTokens: |
| 1756 | case frontend::DumpTokens: |
| 1757 | case frontend::InitOnly: |
| 1758 | case frontend::PrintPreamble: |
| 1759 | case frontend::PrintPreprocessedInput: |
| 1760 | case frontend::RewriteMacros: |
| 1761 | case frontend::RunPreprocessorOnly: |
| 1762 | Opts.ShowCPP = !Args.hasArg(OPT_dM); |
| 1763 | break; |
| 1764 | } |
| 1765 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1766 | Opts.ShowComments = Args.hasArg(OPT_C); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 1767 | Opts.ShowLineMarkers = !Args.hasArg(OPT_P); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1768 | Opts.ShowMacroComments = Args.hasArg(OPT_CC); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 1769 | Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD); |
David Blaikie | f1492f9 | 2012-06-14 17:36:09 +0000 | [diff] [blame] | 1770 | Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Weiming Zhao | 360355d | 2013-03-06 02:08:54 +0000 | [diff] [blame] | 1773 | static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { |
James Molloy | bfd7a52 | 2012-05-01 14:57:16 +0000 | [diff] [blame] | 1774 | using namespace options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1775 | Opts.ABI = Args.getLastArgValue(OPT_target_abi); |
| 1776 | Opts.CPU = Args.getLastArgValue(OPT_target_cpu); |
Rafael Espindola | 5389b84 | 2013-08-21 21:59:03 +0000 | [diff] [blame] | 1777 | Opts.FPMath = Args.getLastArgValue(OPT_mfpmath); |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 1778 | Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature); |
Daniel Dunbar | 39065a5 | 2010-08-11 23:07:42 +0000 | [diff] [blame] | 1779 | Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version); |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 1780 | Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1781 | |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 1782 | // Use the default target triple if unspecified. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1783 | if (Opts.Triple.empty()) |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 1784 | Opts.Triple = llvm::sys::getDefaultTargetTriple(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1787 | bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1788 | const char *const *ArgBegin, |
| 1789 | const char *const *ArgEnd, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1790 | DiagnosticsEngine &Diags) { |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1791 | bool Success = true; |
| 1792 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1793 | // Parse the arguments. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1794 | std::unique_ptr<OptTable> Opts(createDriverOptTable()); |
Hans Wennborg | 4ed47cc | 2013-08-02 20:16:22 +0000 | [diff] [blame] | 1795 | const unsigned IncludedFlagsBitmask = options::CC1Option; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1796 | unsigned MissingArgIndex, MissingArgCount; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1797 | std::unique_ptr<InputArgList> Args( |
| 1798 | Opts->ParseArgs(ArgBegin, ArgEnd, MissingArgIndex, MissingArgCount, |
| 1799 | IncludedFlagsBitmask)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1800 | |
| 1801 | // Check for missing argument error. |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1802 | if (MissingArgCount) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1803 | Diags.Report(diag::err_drv_missing_argument) |
| 1804 | << Args->getArgString(MissingArgIndex) << MissingArgCount; |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1805 | Success = false; |
| 1806 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1807 | |
| 1808 | // Issue errors on unknown arguments. |
| 1809 | for (arg_iterator it = Args->filtered_begin(OPT_UNKNOWN), |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1810 | ie = Args->filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1811 | Diags.Report(diag::err_drv_unknown_argument) << (*it)->getAsString(*Args); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1812 | Success = false; |
| 1813 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1814 | |
Ted Kremenek | 45796b1 | 2012-08-31 04:36:05 +0000 | [diff] [blame] | 1815 | Success = ParseAnalyzerArgs(*Res.getAnalyzerOpts(), *Args, Diags) && Success; |
Fariborz Jahanian | b5c6bab | 2012-01-25 00:20:29 +0000 | [diff] [blame] | 1816 | Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1817 | ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args); |
Chad Rosier | 2dec85b | 2012-03-13 20:09:56 +0000 | [diff] [blame] | 1818 | Success = ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, &Diags) |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1819 | && Success; |
Dmitri Gribenko | 6ebf091 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1820 | ParseCommentArgs(Res.getLangOpts()->CommentOpts, *Args); |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1821 | ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1822 | // FIXME: We shouldn't have to pass the DashX option around here |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1823 | InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1824 | ParseTargetArgs(Res.getTargetOpts(), *Args); |
| 1825 | Success = ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags, |
| 1826 | Res.getTargetOpts()) && Success; |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 1827 | ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 1828 | if (DashX != IK_AST && DashX != IK_LLVM_IR) { |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 1829 | ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 1830 | if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC) |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 1831 | Res.getLangOpts()->ObjCExceptions = 1; |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 1832 | } |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1833 | // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of |
| 1834 | // 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] | 1835 | // ParsePreprocessorArgs and remove the FileManager |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1836 | // parameters from the function and the "FileManager.h" #include. |
Chris Lattner | 7ad97ff | 2010-11-23 07:51:02 +0000 | [diff] [blame] | 1837 | FileManager FileMgr(Res.getFileSystemOpts()); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1838 | ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags); |
Jordan Rose | 74c2498 | 2013-01-30 01:52:57 +0000 | [diff] [blame] | 1839 | ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args, |
| 1840 | Res.getFrontendOpts().ProgramAction); |
Dylan Noblesmith | 8fdb6de | 2011-12-23 03:05:38 +0000 | [diff] [blame] | 1841 | return Success; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1842 | } |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1843 | |
| 1844 | namespace { |
| 1845 | |
| 1846 | class ModuleSignature { |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1847 | SmallVector<uint64_t, 16> Data; |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1848 | unsigned CurBit; |
| 1849 | uint64_t CurValue; |
| 1850 | |
| 1851 | public: |
| 1852 | ModuleSignature() : CurBit(0), CurValue(0) { } |
| 1853 | |
| 1854 | void add(uint64_t Value, unsigned Bits); |
| 1855 | void add(StringRef Value); |
| 1856 | void flush(); |
| 1857 | |
| 1858 | llvm::APInt getAsInteger() const; |
| 1859 | }; |
| 1860 | } |
| 1861 | |
| 1862 | void ModuleSignature::add(uint64_t Value, unsigned int NumBits) { |
| 1863 | CurValue |= Value << CurBit; |
| 1864 | if (CurBit + NumBits < 64) { |
| 1865 | CurBit += NumBits; |
| 1866 | return; |
| 1867 | } |
| 1868 | |
| 1869 | // Add the current word. |
| 1870 | Data.push_back(CurValue); |
| 1871 | |
| 1872 | if (CurBit) |
| 1873 | CurValue = Value >> (64-CurBit); |
| 1874 | else |
| 1875 | CurValue = 0; |
| 1876 | CurBit = (CurBit+NumBits) & 63; |
| 1877 | } |
| 1878 | |
| 1879 | void ModuleSignature::flush() { |
| 1880 | if (CurBit == 0) |
| 1881 | return; |
| 1882 | |
| 1883 | Data.push_back(CurValue); |
| 1884 | CurBit = 0; |
| 1885 | CurValue = 0; |
| 1886 | } |
| 1887 | |
| 1888 | void ModuleSignature::add(StringRef Value) { |
| 1889 | for (StringRef::iterator I = Value.begin(), IEnd = Value.end(); I != IEnd;++I) |
| 1890 | add(*I, 8); |
| 1891 | } |
| 1892 | |
| 1893 | llvm::APInt ModuleSignature::getAsInteger() const { |
| 1894 | return llvm::APInt(Data.size() * 64, Data); |
| 1895 | } |
| 1896 | |
| 1897 | std::string CompilerInvocation::getModuleHash() const { |
Douglas Gregor | c544ba0 | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 1898 | // Note: For QoI reasons, the things we use as a hash here should all be |
| 1899 | // dumped via the -module-info flag. |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1900 | using llvm::hash_code; |
| 1901 | using llvm::hash_value; |
| 1902 | using llvm::hash_combine; |
| 1903 | |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1904 | // Start the signature with the compiler version. |
Douglas Gregor | 3043175 | 2012-11-05 23:30:26 +0000 | [diff] [blame] | 1905 | // FIXME: We'd rather use something more cryptographically sound than |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1906 | // CityHash, but this will do for now. |
| 1907 | hash_code code = hash_value(getClangFullRepositoryVersion()); |
| 1908 | |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1909 | // Extend the signature with the language options |
| 1910 | #define LANGOPT(Name, Bits, Default, Description) \ |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1911 | code = hash_combine(code, LangOpts->Name); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1912 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1913 | code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name())); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1914 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 1915 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 1916 | #include "clang/Basic/LangOptions.def" |
| 1917 | |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1918 | // Extend the signature with the target options. |
| 1919 | code = hash_combine(code, TargetOpts->Triple, TargetOpts->CPU, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1920 | TargetOpts->ABI); |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1921 | for (unsigned i = 0, n = TargetOpts->FeaturesAsWritten.size(); i != n; ++i) |
| 1922 | code = hash_combine(code, TargetOpts->FeaturesAsWritten[i]); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1923 | |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 1924 | // Extend the signature with preprocessor options. |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1925 | const PreprocessorOptions &ppOpts = getPreprocessorOpts(); |
Douglas Gregor | 2a06085 | 2013-02-07 00:21:12 +0000 | [diff] [blame] | 1926 | const HeaderSearchOptions &hsOpts = getHeaderSearchOpts(); |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1927 | code = hash_combine(code, ppOpts.UsePredefines, ppOpts.DetailedRecord); |
| 1928 | |
Douglas Gregor | 05edf66 | 2011-10-17 14:55:37 +0000 | [diff] [blame] | 1929 | for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator |
| 1930 | I = getPreprocessorOpts().Macros.begin(), |
| 1931 | IEnd = getPreprocessorOpts().Macros.end(); |
| 1932 | I != IEnd; ++I) { |
Douglas Gregor | 2a06085 | 2013-02-07 00:21:12 +0000 | [diff] [blame] | 1933 | // If we're supposed to ignore this macro for the purposes of modules, |
| 1934 | // don't put it into the hash. |
| 1935 | if (!hsOpts.ModulesIgnoreMacros.empty()) { |
Douglas Gregor | 2a06085 | 2013-02-07 00:21:12 +0000 | [diff] [blame] | 1936 | // Check whether we're ignoring this macro. |
Douglas Gregor | 005d51b | 2013-02-07 01:18:48 +0000 | [diff] [blame] | 1937 | StringRef MacroDef = I->first; |
| 1938 | if (hsOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first)) |
Douglas Gregor | 2a06085 | 2013-02-07 00:21:12 +0000 | [diff] [blame] | 1939 | continue; |
| 1940 | } |
| 1941 | |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1942 | code = hash_combine(code, I->first, I->second); |
Douglas Gregor | 05edf66 | 2011-10-17 14:55:37 +0000 | [diff] [blame] | 1943 | } |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1944 | |
| 1945 | // Extend the signature with the sysroot. |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1946 | code = hash_combine(code, hsOpts.Sysroot, hsOpts.UseBuiltinIncludes, |
| 1947 | hsOpts.UseStandardSystemIncludes, |
| 1948 | hsOpts.UseStandardCXXIncludes, |
| 1949 | hsOpts.UseLibcxx); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1950 | code = hash_combine(code, hsOpts.ResourceDir); |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1951 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1952 | // Extend the signature with the user build path. |
| 1953 | code = hash_combine(code, hsOpts.ModuleUserBuildPath); |
| 1954 | |
Douglas Gregor | d8f681e | 2013-05-10 21:54:08 +0000 | [diff] [blame] | 1955 | // Darwin-specific hack: if we have a sysroot, use the contents and |
| 1956 | // modification time of |
Douglas Gregor | 31230e6 | 2013-04-12 00:18:53 +0000 | [diff] [blame] | 1957 | // $sysroot/System/Library/CoreServices/SystemVersion.plist |
| 1958 | // as part of the module hash. |
| 1959 | if (!hsOpts.Sysroot.empty()) { |
Douglas Gregor | 31230e6 | 2013-04-12 00:18:53 +0000 | [diff] [blame] | 1960 | SmallString<128> systemVersionFile; |
| 1961 | systemVersionFile += hsOpts.Sysroot; |
| 1962 | llvm::sys::path::append(systemVersionFile, "System"); |
| 1963 | llvm::sys::path::append(systemVersionFile, "Library"); |
| 1964 | llvm::sys::path::append(systemVersionFile, "CoreServices"); |
| 1965 | llvm::sys::path::append(systemVersionFile, "SystemVersion.plist"); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1966 | |
| 1967 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer = |
| 1968 | llvm::MemoryBuffer::getFile(systemVersionFile.str()); |
| 1969 | if (buffer) { |
Douglas Gregor | 31230e6 | 2013-04-12 00:18:53 +0000 | [diff] [blame] | 1970 | code = hash_combine(code, buffer.get()->getBuffer()); |
Douglas Gregor | d8f681e | 2013-05-10 21:54:08 +0000 | [diff] [blame] | 1971 | |
| 1972 | struct stat statBuf; |
| 1973 | if (stat(systemVersionFile.c_str(), &statBuf) == 0) |
| 1974 | code = hash_combine(code, statBuf.st_mtime); |
Douglas Gregor | 31230e6 | 2013-04-12 00:18:53 +0000 | [diff] [blame] | 1975 | } |
| 1976 | } |
| 1977 | |
Douglas Gregor | 984e2eb | 2012-11-05 19:45:09 +0000 | [diff] [blame] | 1978 | return llvm::APInt(64, code).toString(36, /*Signed=*/false); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1979 | } |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 1980 | |
| 1981 | namespace clang { |
| 1982 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1983 | template<typename IntTy> |
| 1984 | static IntTy getLastArgIntValueImpl(const ArgList &Args, OptSpecifier Id, |
| 1985 | IntTy Default, |
| 1986 | DiagnosticsEngine *Diags) { |
| 1987 | IntTy Res = Default; |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 1988 | if (Arg *A = Args.getLastArg(Id)) { |
| 1989 | if (StringRef(A->getValue()).getAsInteger(10, Res)) { |
| 1990 | if (Diags) |
| 1991 | Diags->Report(diag::err_drv_invalid_int_value) << A->getAsString(Args) |
| 1992 | << A->getValue(); |
| 1993 | } |
| 1994 | } |
| 1995 | return Res; |
| 1996 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1997 | |
| 1998 | |
| 1999 | // Declared in clang/Frontend/Utils.h. |
| 2000 | int getLastArgIntValue(const ArgList &Args, OptSpecifier Id, int Default, |
| 2001 | DiagnosticsEngine *Diags) { |
| 2002 | return getLastArgIntValueImpl<int>(Args, Id, Default, Diags); |
| 2003 | } |
| 2004 | |
| 2005 | uint64_t getLastArgUInt64Value(const ArgList &Args, OptSpecifier Id, |
| 2006 | uint64_t Default, |
| 2007 | DiagnosticsEngine *Diags) { |
| 2008 | return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags); |
| 2009 | } |
| 2010 | |
| 2011 | void BuryPointer(const void *Ptr) { |
| 2012 | // This function may be called only a small fixed amount of times per each |
| 2013 | // invocation, otherwise we do actually have a leak which we want to report. |
| 2014 | // If this function is called more than kGraveYardMaxSize times, the pointers |
| 2015 | // will not be properly buried and a leak detector will report a leak, which |
| 2016 | // is what we want in such case. |
| 2017 | static const size_t kGraveYardMaxSize = 16; |
| 2018 | LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize]; |
| 2019 | static std::atomic<unsigned> GraveYardSize; |
| 2020 | unsigned Idx = GraveYardSize++; |
| 2021 | if (Idx >= kGraveYardMaxSize) |
| 2022 | return; |
| 2023 | GraveYard[Idx] = Ptr; |
| 2024 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2025 | |
| 2026 | IntrusiveRefCntPtr<vfs::FileSystem> |
| 2027 | createVFSFromCompilerInvocation(const CompilerInvocation &CI, |
| 2028 | DiagnosticsEngine &Diags) { |
| 2029 | if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) |
| 2030 | return vfs::getRealFileSystem(); |
| 2031 | |
| 2032 | IntrusiveRefCntPtr<vfs::OverlayFileSystem> |
| 2033 | Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem())); |
| 2034 | // earlier vfs files are on the bottom |
| 2035 | for (const std::string &File : CI.getHeaderSearchOpts().VFSOverlayFiles) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 2036 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer = |
| 2037 | llvm::MemoryBuffer::getFile(File); |
| 2038 | if (!Buffer) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2039 | Diags.Report(diag::err_missing_vfs_overlay_file) << File; |
| 2040 | return IntrusiveRefCntPtr<vfs::FileSystem>(); |
| 2041 | } |
| 2042 | |
| 2043 | IntrusiveRefCntPtr<vfs::FileSystem> FS = |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 2044 | vfs::getVFSFromYAML(Buffer->release(), /*DiagHandler*/ nullptr); |
| 2045 | if (!FS.get()) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2046 | Diags.Report(diag::err_invalid_vfs_overlay) << File; |
| 2047 | return IntrusiveRefCntPtr<vfs::FileSystem>(); |
| 2048 | } |
| 2049 | Overlay->pushOverlay(FS); |
| 2050 | } |
| 2051 | return Overlay; |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 2052 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2053 | } // end namespace clang |