Skip to content

Commit de06c52

Browse files
authored
[lldb] Rework PCM validation disable for Swift (#10974)
The `Preprocessor`'s options have changed to be `const` in llvm@277ab85. Since lldb can no longer mutate the options before constructing a clang importer, this change is to setup the options ahead of time.
1 parent 49be885 commit de06c52

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

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

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,33 @@ static void applyOverrideOptions(std::vector<std::string> &args,
17971797
args = new_args;
17981798
}
17991799

1800+
/// Set PCM validation. This needs to happen before ClangImporter is created but
1801+
/// after m_has_explicit_modules has been initialized.
1802+
void SwiftASTContext::ConfigureModuleValidation(
1803+
std::vector<std::string> &extra_args) {
1804+
// Read the setting.
1805+
AutoBool validate_pcm_setting = AutoBool::Auto;
1806+
TargetSP target_sp = GetTargetWP().lock();
1807+
if (target_sp)
1808+
validate_pcm_setting = target_sp->GetSwiftPCMValidation();
1809+
1810+
// If validation is explicitly enabled, honor it.
1811+
bool validate_pcm = validate_pcm_setting == AutoBool::True;
1812+
if (validate_pcm_setting == AutoBool::Auto) {
1813+
// Disable validation for explicit modules.
1814+
validate_pcm = m_has_explicit_modules ? false : true;
1815+
// Enable validation in asserts builds.
1816+
#ifndef NDEBUG
1817+
validate_pcm = true;
1818+
#endif
1819+
}
1820+
1821+
if (!validate_pcm) {
1822+
extra_args.push_back("-fno-modules-check-relocated");
1823+
LOG_PRINTF(GetLog(LLDBLog::Types), "PCM validation is disabled");
1824+
}
1825+
}
1826+
18001827
void SwiftASTContext::AddExtraClangArgs(
18011828
const std::vector<std::string> &ExtraArgs,
18021829
const std::vector<std::pair<std::string, bool>> module_search_paths,
@@ -1809,6 +1836,7 @@ void SwiftASTContext::AddExtraClangArgs(
18091836
llvm::any_of(importer_options.ExtraArgs, [](const std::string &arg) {
18101837
return StringRef(arg).starts_with("-fmodule-file=");
18111838
});
1839+
ConfigureModuleValidation(importer_options.ExtraArgs);
18121840
});
18131841

18141842
if (ExtraArgs.empty())
@@ -1944,6 +1972,7 @@ void SwiftASTContext::AddExtraClangCC1Args(
19441972
// If cc1 arguments are parsed and generated correctly, set explicitly-built
19451973
// module since only explicit module build can use direct cc1 mode.
19461974
m_has_explicit_modules = true;
1975+
ConfigureModuleValidation(dest);
19471976
return;
19481977
}
19491978

@@ -9265,39 +9294,6 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
92659294
if (cu_imports.size() == 0)
92669295
return true;
92679296

9268-
// Set PCM validation. This is not a great place to do this, but it
9269-
// needs to happen after ClangImporter was created and
9270-
// m_has_explicit_modules has been initialized.
9271-
{
9272-
// Read the setting.
9273-
AutoBool validate_pcm_setting = AutoBool::Auto;
9274-
TargetSP target_sp = GetTargetWP().lock();
9275-
if (target_sp)
9276-
validate_pcm_setting = target_sp->GetSwiftPCMValidation();
9277-
9278-
// If the setting is explicit, honor it.
9279-
bool validate_pcm = validate_pcm_setting != AutoBool::False;
9280-
if (validate_pcm_setting == AutoBool::Auto) {
9281-
// Disable validation for explicit modules.
9282-
validate_pcm = m_has_explicit_modules ? false : true;
9283-
// Enable validation in asserts builds.
9284-
#ifndef NDEBUG
9285-
validate_pcm = true;
9286-
#endif
9287-
}
9288-
9289-
const auto &pp_opts =
9290-
m_clangimporter->getClangPreprocessor().getPreprocessorOpts();
9291-
// rdar://155232969
9292-
// pp_opts.DisablePCHOrModuleValidation =
9293-
// validate_pcm ? clang::DisableValidationForModuleKind::None
9294-
// : clang::DisableValidationForModuleKind::All;
9295-
// pp_opts.ModulesCheckRelocated = validate_pcm;
9296-
9297-
if (!validate_pcm)
9298-
LOG_PRINTF(GetLog(LLDBLog::Types), "PCM validation cannot be disabled");
9299-
}
9300-
93019297
LOG_PRINTF(GetLog(LLDBLog::Types), "Importing dependencies of current CU");
93029298

93039299
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
@@ -275,6 +275,8 @@ class SwiftASTContext : public TypeSystemSwift {
275275

276276
bool AddModuleSearchPath(llvm::StringRef path);
277277

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

0 commit comments

Comments
 (0)