Skip to content

[Frontend] Turn symbols-missing-from-TBD validation on by default in debug builds on Apple platforms. #16838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ ERROR(symbol_in_ir_not_in_tbd,none,
"symbol '%0' (%1) is in generated IR file, but not in TBD file",
(StringRef, StringRef))

ERROR(tbd_validation_failure,none,
"please file a radar or open a bug on bugs.swift.org with this code, and "
"add -Xfrontend -validate-tbd-against-ir=none to squash the errors", ())

ERROR(redundant_prefix_compilation_flag,none,
"invalid argument '-D%0'; did you provide a redundant '-D' in your build settings?",
(StringRef))
Expand Down
3 changes: 2 additions & 1 deletion include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,14 @@ class FrontendOptions {

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

/// Compare the symbols in the IR against the TBD file we would generate.
TBDValidationMode ValidateTBDAgainstIR = TBDValidationMode::None;
TBDValidationMode ValidateTBDAgainstIR = TBDValidationMode::Default;

/// The install_name to use in the TBD file.
std::string TBDInstallName;
Expand Down
13 changes: 12 additions & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,20 @@ static bool validateTBDIfNeeded(CompilerInvocation &Invocation,
return false;

const auto &frontendOpts = Invocation.getFrontendOptions();
const auto mode = frontendOpts.ValidateTBDAgainstIR;
auto mode = frontendOpts.ValidateTBDAgainstIR;
// Ensure all cases are covered by using a switch here.
switch (mode) {
case FrontendOptions::TBDValidationMode::Default:
#ifndef NDEBUG
// When a debug compiler is targeting an apple platform, we do some
// validation by default.
if (Invocation.getLangOptions().Target.getVendor() == llvm::Triple::Apple) {
mode = FrontendOptions::TBDValidationMode::MissingFromTBD;
break;
}
#endif
// Otherwise, the default is to do nothing.
LLVM_FALLTHROUGH;
case FrontendOptions::TBDValidationMode::None:
return false;
case FrontendOptions::TBDValidationMode::All:
Expand Down
4 changes: 4 additions & 0 deletions lib/FrontendTool/TBD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ static bool validateSymbolSet(DiagnosticEngine &diags,
}
}

if (error) {
diags.diagnose(SourceLoc(), diag::tbd_validation_failure);
}

return error;
}

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