@@ -1797,6 +1797,33 @@ static void applyOverrideOptions(std::vector<std::string> &args,
1797
1797
args = new_args;
1798
1798
}
1799
1799
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
+
1800
1827
void SwiftASTContext::AddExtraClangArgs (
1801
1828
const std::vector<std::string> &ExtraArgs,
1802
1829
const std::vector<std::pair<std::string, bool >> module_search_paths,
@@ -1809,6 +1836,7 @@ void SwiftASTContext::AddExtraClangArgs(
1809
1836
llvm::any_of (importer_options.ExtraArgs , [](const std::string &arg) {
1810
1837
return StringRef (arg).starts_with (" -fmodule-file=" );
1811
1838
});
1839
+ ConfigureModuleValidation (importer_options.ExtraArgs );
1812
1840
});
1813
1841
1814
1842
if (ExtraArgs.empty ())
@@ -1944,6 +1972,7 @@ void SwiftASTContext::AddExtraClangCC1Args(
1944
1972
// If cc1 arguments are parsed and generated correctly, set explicitly-built
1945
1973
// module since only explicit module build can use direct cc1 mode.
1946
1974
m_has_explicit_modules = true ;
1975
+ ConfigureModuleValidation (dest);
1947
1976
return ;
1948
1977
}
1949
1978
@@ -9265,39 +9294,6 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
9265
9294
if (cu_imports.size () == 0 )
9266
9295
return true ;
9267
9296
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
-
9301
9297
LOG_PRINTF (GetLog (LLDBLog::Types), " Importing dependencies of current CU" );
9302
9298
9303
9299
std::string category = " Importing Swift module dependencies for " ;
0 commit comments