@@ -1791,6 +1791,33 @@ static void applyOverrideOptions(std::vector<std::string> &args,
1791
1791
args = new_args;
1792
1792
}
1793
1793
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
+
1794
1821
void SwiftASTContext::AddExtraClangArgs (
1795
1822
const std::vector<std::string> &ExtraArgs,
1796
1823
const std::vector<std::pair<std::string, bool >> module_search_paths,
@@ -1803,6 +1830,7 @@ void SwiftASTContext::AddExtraClangArgs(
1803
1830
llvm::any_of (importer_options.ExtraArgs , [](const std::string &arg) {
1804
1831
return StringRef (arg).starts_with (" -fmodule-file=" );
1805
1832
});
1833
+ ConfigureModuleValidation (importer_options.ExtraArgs );
1806
1834
});
1807
1835
1808
1836
if (ExtraArgs.empty ())
@@ -1938,6 +1966,7 @@ void SwiftASTContext::AddExtraClangCC1Args(
1938
1966
// If cc1 arguments are parsed and generated correctly, set explicitly-built
1939
1967
// module since only explicit module build can use direct cc1 mode.
1940
1968
m_has_explicit_modules = true ;
1969
+ ConfigureModuleValidation (dest);
1941
1970
return ;
1942
1971
}
1943
1972
@@ -9231,38 +9260,6 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
9231
9260
if (cu_imports.size () == 0 )
9232
9261
return true ;
9233
9262
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
-
9266
9263
LOG_PRINTF (GetLog (LLDBLog::Types), " Importing dependencies of current CU" );
9267
9264
9268
9265
std::string category = " Importing Swift module dependencies for " ;
0 commit comments