Skip to content

Commit e1b70cd

Browse files
authored
Merge pull request #15813 from jrose-apple/decremental
[Driver] Disallow -autolink-force-load with -incremental
2 parents 1d66f0a + c3d8fc0 commit e1b70cd

File tree

3 files changed

+99
-47
lines changed

3 files changed

+99
-47
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ ERROR(error_input_changed_during_build,none,
126126
ERROR(error_conflicting_options, none,
127127
"conflicting options '%0' and '%1'",
128128
(StringRef, StringRef))
129+
ERROR(error_option_not_supported, none,
130+
"'%0' is not supported with '%1'",
131+
(StringRef, StringRef))
129132

130133
WARNING(warn_ignore_embed_bitcode, none,
131134
"ignoring -embed-bitcode since no object file is being generated", ())

lib/Driver/Driver.cpp

Lines changed: 92 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -119,88 +119,133 @@ ArrayRef<const char *> Driver::getArgsWithoutProgramNameAndDriverMode(
119119
return Args;
120120
}
121121

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)) {
125126
diags.diagnose({}, diag::error_framework_bridging_header);
126127
}
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;
127135

128136
// 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)) {
144145
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;
155148
}
156149
}
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+
}
157163
}
164+
}
158165

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)) {
162170
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
163171
"-warnings-as-errors", "-suppress-warnings");
164172
}
173+
}
165174

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) {
170180
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
171181
"-profile-generate", "-profile-use");
182+
}
172183

173184
// Check if the profdata is missing
174-
if (ProfileUse && !llvm::sys::fs::exists(ProfileUse->getValue()))
185+
if (ProfileUse && !llvm::sys::fs::exists(ProfileUse->getValue())) {
175186
diags.diagnose(SourceLoc(), diag::error_profile_missing,
176-
ProfileUse->getValue());
187+
ProfileUse->getValue());
188+
}
189+
}
177190

191+
static void validateDebugInfoArgs(DiagnosticEngine &diags,
192+
const ArgList &args) {
178193
// 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)) {
185197
diags.diagnose(SourceLoc(),
186198
diag::verify_debug_info_requires_debug_option);
199+
}
187200
}
201+
}
188202

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)) {
190206
StringRef name = A->getValue();
191-
if (name.find('=') != StringRef::npos)
207+
if (name.find('=') != StringRef::npos) {
192208
diags.diagnose(SourceLoc(),
193209
diag::cannot_assign_value_to_conditional_compilation_flag,
194210
name);
195-
else if (name.startswith("-D"))
211+
} else if (name.startswith("-D")) {
196212
diags.diagnose(SourceLoc(), diag::redundant_prefix_compilation_flag,
197213
name);
198-
else if (!Lexer::isIdentifier(name))
214+
} else if (!Lexer::isIdentifier(name)) {
199215
diags.diagnose(SourceLoc(), diag::invalid_conditional_compilation_flag,
200216
name);
217+
}
201218
}
202219
}
203220

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+
204249
std::unique_ptr<ToolChain>
205250
Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) {
206251

test/Driver/options.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@
129129
// RUN: %swiftc_driver -driver-print-jobs -assume-single-threaded %s | %FileCheck -check-prefix=ASSUME_SINGLE_THREADED %s
130130
// ASSUME_SINGLE_THREADED: swift
131131
// ASSUME_SINGLE_THREADED: -frontend {{.*}} -assume-single-threaded
132+
133+
// RUN: not %swiftc_driver -incremental -autolink-force-load %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
134+
// RUN: not %swiftc_driver -autolink-force-load -incremental %s 2>&1 | %FileCheck -check-prefix=AUTOLINK_FORCE_LOAD %s
135+
// AUTOLINK_FORCE_LOAD: error: '-autolink-force-load' is not supported with '-incremental'

0 commit comments

Comments
 (0)