@@ -119,88 +119,133 @@ ArrayRef<const char *> Driver::getArgsWithoutProgramNameAndDriverMode(
119
119
return Args;
120
120
}
121
121
122
- static void validateArgs (DiagnosticEngine &diags, const ArgList &Args) {
123
- if (Args.hasArgNoClaim (options::OPT_import_underlying_module) &&
124
- Args.hasArgNoClaim (options::OPT_import_objc_header)) {
122
+ static void validateBridgingHeaderArgs (DiagnosticEngine &diags,
123
+ const ArgList &args) {
124
+ if (args.hasArgNoClaim (options::OPT_import_underlying_module) &&
125
+ args.hasArgNoClaim (options::OPT_import_objc_header)) {
125
126
diags.diagnose ({}, diag::error_framework_bridging_header);
126
127
}
128
+ }
129
+
130
+ static void validateDeploymentTarget (DiagnosticEngine &diags,
131
+ const ArgList &args) {
132
+ const Arg *A = args.getLastArg (options::OPT_target);
133
+ if (!A)
134
+ return ;
127
135
128
136
// Check minimum supported OS versions.
129
- if (const Arg *A = Args.getLastArg (options::OPT_target)) {
130
- llvm::Triple triple (llvm::Triple::normalize (A->getValue ()));
131
- if (triple.isMacOSX ()) {
132
- if (triple.isMacOSXVersionLT (10 , 9 ))
133
- diags.diagnose (SourceLoc (), diag::error_os_minimum_deployment,
134
- " OS X 10.9" );
135
- } else if (triple.isiOS ()) {
136
- if (triple.isTvOS ()) {
137
- if (triple.isOSVersionLT (9 , 0 )) {
138
- diags.diagnose (SourceLoc (), diag::error_os_minimum_deployment,
139
- " tvOS 9.0" );
140
- return ;
141
- }
142
- }
143
- if (triple.isOSVersionLT (7 ))
137
+ llvm::Triple triple (llvm::Triple::normalize (A->getValue ()));
138
+ if (triple.isMacOSX ()) {
139
+ if (triple.isMacOSXVersionLT (10 , 9 ))
140
+ diags.diagnose (SourceLoc (), diag::error_os_minimum_deployment,
141
+ " OS X 10.9" );
142
+ } else if (triple.isiOS ()) {
143
+ if (triple.isTvOS ()) {
144
+ if (triple.isOSVersionLT (9 , 0 )) {
144
145
diags.diagnose (SourceLoc (), diag::error_os_minimum_deployment,
145
- " iOS 7" );
146
- if (triple.isArch32Bit () && !triple.isOSVersionLT (11 )) {
147
- diags.diagnose (SourceLoc (), diag::error_ios_maximum_deployment_32,
148
- triple.getOSMajorVersion ());
149
- }
150
- } else if (triple.isWatchOS ()) {
151
- if (triple.isOSVersionLT (2 , 0 )) {
152
- diags.diagnose (SourceLoc (), diag::error_os_minimum_deployment,
153
- " watchOS 2.0" );
154
- return ;
146
+ " tvOS 9.0" );
147
+ return ;
155
148
}
156
149
}
150
+ if (triple.isOSVersionLT (7 ))
151
+ diags.diagnose (SourceLoc (), diag::error_os_minimum_deployment,
152
+ " iOS 7" );
153
+ if (triple.isArch32Bit () && !triple.isOSVersionLT (11 )) {
154
+ diags.diagnose (SourceLoc (), diag::error_ios_maximum_deployment_32,
155
+ triple.getOSMajorVersion ());
156
+ }
157
+ } else if (triple.isWatchOS ()) {
158
+ if (triple.isOSVersionLT (2 , 0 )) {
159
+ diags.diagnose (SourceLoc (), diag::error_os_minimum_deployment,
160
+ " watchOS 2.0" );
161
+ return ;
162
+ }
157
163
}
164
+ }
158
165
159
- // Check for conflicting warning control flags
160
- if (Args.hasArg (options::OPT_suppress_warnings) &&
161
- Args.hasArg (options::OPT_warnings_as_errors)) {
166
+ static void validateWarningControlArgs (DiagnosticEngine &diags,
167
+ const ArgList &args) {
168
+ if (args.hasArg (options::OPT_suppress_warnings) &&
169
+ args.hasArg (options::OPT_warnings_as_errors)) {
162
170
diags.diagnose (SourceLoc (), diag::error_conflicting_options,
163
171
" -warnings-as-errors" , " -suppress-warnings" );
164
172
}
173
+ }
165
174
166
- // Check for conflicting profiling flags
167
- const Arg *ProfileGenerate = Args.getLastArg (options::OPT_profile_generate);
168
- const Arg *ProfileUse = Args.getLastArg (options::OPT_profile_use);
169
- if (ProfileGenerate && ProfileUse)
175
+ static void validateProfilingArgs (DiagnosticEngine &diags,
176
+ const ArgList &args) {
177
+ const Arg *ProfileGenerate = args.getLastArg (options::OPT_profile_generate);
178
+ const Arg *ProfileUse = args.getLastArg (options::OPT_profile_use);
179
+ if (ProfileGenerate && ProfileUse) {
170
180
diags.diagnose (SourceLoc (), diag::error_conflicting_options,
171
181
" -profile-generate" , " -profile-use" );
182
+ }
172
183
173
184
// Check if the profdata is missing
174
- if (ProfileUse && !llvm::sys::fs::exists (ProfileUse->getValue ()))
185
+ if (ProfileUse && !llvm::sys::fs::exists (ProfileUse->getValue ())) {
175
186
diags.diagnose (SourceLoc (), diag::error_profile_missing,
176
- ProfileUse->getValue ());
187
+ ProfileUse->getValue ());
188
+ }
189
+ }
177
190
191
+ static void validateDebugInfoArgs (DiagnosticEngine &diags,
192
+ const ArgList &args) {
178
193
// Check for missing debug option when verifying debug info.
179
- if (Args.hasArg (options::OPT_verify_debug_info)) {
180
- bool hasDebugOption = true ;
181
- Arg *Arg = Args.getLastArg (swift::options::OPT_g_Group);
182
- if (!Arg || Arg->getOption ().matches (swift::options::OPT_gnone))
183
- hasDebugOption = false ;
184
- if (!hasDebugOption)
194
+ if (args.hasArg (options::OPT_verify_debug_info)) {
195
+ Arg *debugOpt = args.getLastArg (swift::options::OPT_g_Group);
196
+ if (!debugOpt || debugOpt->getOption ().matches (swift::options::OPT_gnone)) {
185
197
diags.diagnose (SourceLoc (),
186
198
diag::verify_debug_info_requires_debug_option);
199
+ }
187
200
}
201
+ }
188
202
189
- for (const Arg *A : Args.filtered (options::OPT_D)) {
203
+ static void validateCompilationConditionArgs (DiagnosticEngine &diags,
204
+ const ArgList &args) {
205
+ for (const Arg *A : args.filtered (options::OPT_D)) {
190
206
StringRef name = A->getValue ();
191
- if (name.find (' =' ) != StringRef::npos)
207
+ if (name.find (' =' ) != StringRef::npos) {
192
208
diags.diagnose (SourceLoc (),
193
209
diag::cannot_assign_value_to_conditional_compilation_flag,
194
210
name);
195
- else if (name.startswith (" -D" ))
211
+ } else if (name.startswith (" -D" )) {
196
212
diags.diagnose (SourceLoc (), diag::redundant_prefix_compilation_flag,
197
213
name);
198
- else if (!Lexer::isIdentifier (name))
214
+ } else if (!Lexer::isIdentifier (name)) {
199
215
diags.diagnose (SourceLoc (), diag::invalid_conditional_compilation_flag,
200
216
name);
217
+ }
201
218
}
202
219
}
203
220
221
+ static void validateAutolinkingArgs (DiagnosticEngine &diags,
222
+ const ArgList &args) {
223
+ auto *forceLoadArg = args.getLastArg (options::OPT_autolink_force_load);
224
+ if (!forceLoadArg)
225
+ return ;
226
+ auto *incrementalArg = args.getLastArg (options::OPT_incremental);
227
+ if (!incrementalArg)
228
+ return ;
229
+
230
+ // Note: -incremental can itself be overridden by other arguments later
231
+ // on, but since -autolink-force-load is a rare and not-really-recommended
232
+ // option it's not worth modeling that complexity here (or moving the
233
+ // check somewhere else).
234
+ diags.diagnose (SourceLoc (), diag::error_option_not_supported,
235
+ forceLoadArg->getSpelling (), incrementalArg->getSpelling ());
236
+ }
237
+
238
+ // / Perform miscellaneous early validation of arguments.
239
+ static void validateArgs (DiagnosticEngine &diags, const ArgList &args) {
240
+ validateBridgingHeaderArgs (diags, args);
241
+ validateDeploymentTarget (diags, args);
242
+ validateWarningControlArgs (diags, args);
243
+ validateProfilingArgs (diags, args);
244
+ validateDebugInfoArgs (diags, args);
245
+ validateCompilationConditionArgs (diags, args);
246
+ validateAutolinkingArgs (diags, args);
247
+ }
248
+
204
249
std::unique_ptr<ToolChain>
205
250
Driver::buildToolChain (const llvm::opt::InputArgList &ArgList) {
206
251
0 commit comments