Skip to content

Commit ada1a1b

Browse files
committed
[lldb] Rework PCM validation disable for Swift
1 parent 5bea56e commit ada1a1b

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,33 @@ static void applyOverrideOptions(std::vector<std::string> &args,
17911791
args = new_args;
17921792
}
17931793

1794+
/// Set PCM validation. This needs to happen before ClangImporter is created but
1795+
/// after m_has_explicit_modules has been initialized.
1796+
void SwiftASTContext::ConfigureModuleValidation(
1797+
std::vector<std::string> &extra_args) {
1798+
// Read the setting.
1799+
AutoBool validate_pcm_setting = AutoBool::Auto;
1800+
TargetSP target_sp = GetTargetWP().lock();
1801+
if (target_sp)
1802+
validate_pcm_setting = target_sp->GetSwiftPCMValidation();
1803+
1804+
// If validation is explicitly enabled, honor it.
1805+
bool validate_pcm = validate_pcm_setting == AutoBool::True;
1806+
if (validate_pcm_setting == AutoBool::Auto) {
1807+
// Disable validation for explicit modules.
1808+
validate_pcm = m_has_explicit_modules ? false : true;
1809+
// Enable validation in asserts builds.
1810+
#ifndef NDEBUG
1811+
validate_pcm = true;
1812+
#endif
1813+
}
1814+
1815+
if (!validate_pcm) {
1816+
extra_args.push_back("-fno-modules-check-relocated");
1817+
LOG_PRINTF(GetLog(LLDBLog::Types), "PCM validation is disabled");
1818+
}
1819+
}
1820+
17941821
void SwiftASTContext::AddExtraClangArgs(
17951822
const std::vector<std::string> &ExtraArgs,
17961823
const std::vector<std::pair<std::string, bool>> module_search_paths,
@@ -1803,6 +1830,7 @@ void SwiftASTContext::AddExtraClangArgs(
18031830
llvm::any_of(importer_options.ExtraArgs, [](const std::string &arg) {
18041831
return StringRef(arg).starts_with("-fmodule-file=");
18051832
});
1833+
ConfigureModuleValidation(importer_options.ExtraArgs);
18061834
});
18071835

18081836
if (ExtraArgs.empty())
@@ -1938,6 +1966,7 @@ void SwiftASTContext::AddExtraClangCC1Args(
19381966
// If cc1 arguments are parsed and generated correctly, set explicitly-built
19391967
// module since only explicit module build can use direct cc1 mode.
19401968
m_has_explicit_modules = true;
1969+
ConfigureModuleValidation(dest);
19411970
return;
19421971
}
19431972

@@ -9231,38 +9260,6 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
92319260
if (cu_imports.size() == 0)
92329261
return true;
92339262

9234-
// Set PCM validation. This is not a great place to do this, but it
9235-
// needs to happen after ClangImporter was created and
9236-
// m_has_explicit_modules has been initialized.
9237-
{
9238-
// Read the setting.
9239-
AutoBool validate_pcm_setting = AutoBool::Auto;
9240-
TargetSP target_sp = GetTargetWP().lock();
9241-
if (target_sp)
9242-
validate_pcm_setting = target_sp->GetSwiftPCMValidation();
9243-
9244-
// If the setting is explicit, honor it.
9245-
bool validate_pcm = validate_pcm_setting != AutoBool::False;
9246-
if (validate_pcm_setting == AutoBool::Auto) {
9247-
// Disable validation for explicit modules.
9248-
validate_pcm = m_has_explicit_modules ? false : true;
9249-
// Enable validation in asserts builds.
9250-
#ifndef NDEBUG
9251-
validate_pcm = true;
9252-
#endif
9253-
}
9254-
9255-
auto &pp_opts = m_clangimporter->getClangPreprocessor()
9256-
.getPreprocessorOpts();
9257-
pp_opts.DisablePCHOrModuleValidation =
9258-
validate_pcm ? clang::DisableValidationForModuleKind::None
9259-
: clang::DisableValidationForModuleKind::All;
9260-
pp_opts.ModulesCheckRelocated = validate_pcm;
9261-
9262-
LOG_PRINTF(GetLog(LLDBLog::Types), "PCM validation is %s",
9263-
validate_pcm ? "disabled" : "enabled");
9264-
}
9265-
92669263
LOG_PRINTF(GetLog(LLDBLog::Types), "Importing dependencies of current CU");
92679264

92689265
std::string category = "Importing Swift module dependencies for ";

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ class SwiftASTContext : public TypeSystemSwift {
273273

274274
bool AddModuleSearchPath(llvm::StringRef path);
275275

276+
void ConfigureModuleValidation(std::vector<std::string> &extra_args);
277+
276278
/// Add a list of Clang arguments to the ClangImporter options and
277279
/// apply the working directory to any relative paths.
278280
void AddExtraClangArgs(

0 commit comments

Comments
 (0)