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