Skip to content

Commit 0c4fe6c

Browse files
authored
Merge pull request #16838 from huonw/validate-tbd-by-default
[Frontend] Turn symbols-missing-from-TBD validation on by default in debug builds on Apple platforms.
2 parents ad7cbb3 + caa3dd4 commit 0c4fe6c

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ ERROR(symbol_in_ir_not_in_tbd,none,
220220
"symbol '%0' (%1) is in generated IR file, but not in TBD file",
221221
(StringRef, StringRef))
222222

223+
ERROR(tbd_validation_failure,none,
224+
"please file a radar or open a bug on bugs.swift.org with this code, and "
225+
"add -Xfrontend -validate-tbd-against-ir=none to squash the errors", ())
226+
223227
ERROR(redundant_prefix_compilation_flag,none,
224228
"invalid argument '-D%0'; did you provide a redundant '-D' in your build settings?",
225229
(StringRef))

include/swift/Frontend/FrontendOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,14 @@ class FrontendOptions {
244244

245245
/// The different modes for validating TBD against the LLVM IR.
246246
enum class TBDValidationMode {
247+
Default, ///< Do the default validation for the current platform.
247248
None, ///< Do no validation.
248249
MissingFromTBD, ///< Only check for symbols that are in IR but not TBD.
249250
All, ///< Check for symbols that are in IR but not TBD and TBD but not IR.
250251
};
251252

252253
/// Compare the symbols in the IR against the TBD file we would generate.
253-
TBDValidationMode ValidateTBDAgainstIR = TBDValidationMode::None;
254+
TBDValidationMode ValidateTBDAgainstIR = TBDValidationMode::Default;
254255

255256
/// The install_name to use in the TBD file.
256257
std::string TBDInstallName;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,9 +1166,20 @@ static bool validateTBDIfNeeded(CompilerInvocation &Invocation,
11661166
return false;
11671167

11681168
const auto &frontendOpts = Invocation.getFrontendOptions();
1169-
const auto mode = frontendOpts.ValidateTBDAgainstIR;
1169+
auto mode = frontendOpts.ValidateTBDAgainstIR;
11701170
// Ensure all cases are covered by using a switch here.
11711171
switch (mode) {
1172+
case FrontendOptions::TBDValidationMode::Default:
1173+
#ifndef NDEBUG
1174+
// When a debug compiler is targeting an apple platform, we do some
1175+
// validation by default.
1176+
if (Invocation.getLangOptions().Target.getVendor() == llvm::Triple::Apple) {
1177+
mode = FrontendOptions::TBDValidationMode::MissingFromTBD;
1178+
break;
1179+
}
1180+
#endif
1181+
// Otherwise, the default is to do nothing.
1182+
LLVM_FALLTHROUGH;
11721183
case FrontendOptions::TBDValidationMode::None:
11731184
return false;
11741185
case FrontendOptions::TBDValidationMode::All:

lib/FrontendTool/TBD.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ static bool validateSymbolSet(DiagnosticEngine &diags,
113113
}
114114
}
115115

116+
if (error) {
117+
diags.diagnose(SourceLoc(), diag::tbd_validation_failure);
118+
}
119+
116120
return error;
117121
}
118122

stdlib/public/SwiftOnoneSupport/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ add_swift_library(swiftSwiftOnoneSupport ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_
22
# This file should be listed the first. Module name is inferred from the
33
# filename.
44
SwiftOnoneSupport.swift
5-
SWIFT_COMPILE_FLAGS "-parse-stdlib" "-Xllvm" "-sil-inline-generics=false" "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
5+
# We have to disable validation of TBD files, because this module is
6+
# _explicitly_ special-cased to result in extra symbols generated by the
7+
# optimizer, meaning TBDGen can't (and shouldn't: it has to run
8+
# pre-optimization for performance) list them.
9+
SWIFT_COMPILE_FLAGS "-parse-stdlib" "-Xllvm" "-sil-inline-generics=false" "-Xfrontend" "-validate-tbd-against-ir=none" "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
610
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
711
INSTALL_IN_COMPONENT stdlib)

0 commit comments

Comments
 (0)