Skip to content

Commit 31f0cdc

Browse files
Merge pull request swiftlang#9051 from adrian-prantl/130284825
Turn off PCM validation by default.
2 parents 7d06a8f + babe4b2 commit 31f0cdc

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ class TargetProperties : public Properties {
188188

189189
bool GetSwiftAllowExplicitModules() const;
190190

191+
AutoBool GetSwiftPCMValidation() const;
192+
191193
Args GetSwiftPluginServerForPath() const;
192194

193195
bool GetSwiftAutoImportFrameworks() const;

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
#include "clang/Basic/TargetOptions.h"
5858
#include "clang/Driver/Driver.h"
5959
#include "clang/Frontend/CompilerInstance.h"
60+
#include "clang/Lex/Preprocessor.h"
6061

62+
#include "clang/Lex/PreprocessorOptions.h"
6163
#include "llvm/ADT/ArrayRef.h"
6264
#include "llvm/ADT/STLExtras.h"
6365
#include "llvm/ADT/SmallVector.h"
@@ -9224,6 +9226,38 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
92249226
if (cu_imports.size() == 0)
92259227
return true;
92269228

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

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

lldb/source/Target/Target.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,6 +4688,13 @@ static constexpr OptionEnumValueElement g_memory_module_load_level_values[] = {
46884688
},
46894689
};
46904690

4691+
static constexpr OptionEnumValueElement g_swift_pcm_validation_values[] = {
4692+
{llvm::to_underlying(AutoBool::Auto), "auto",
4693+
"Turned on when explicit modules are enabled"},
4694+
{llvm::to_underlying(AutoBool::True), "true", "Enable validation."},
4695+
{llvm::to_underlying(AutoBool::False), "false", "Disable validation."},
4696+
};
4697+
46914698

46924699
#define LLDB_PROPERTIES_target
46934700
#include "TargetProperties.inc"
@@ -4927,6 +4934,19 @@ bool TargetProperties::GetSwiftAllowExplicitModules() const {
49274934
return true;
49284935
}
49294936

4937+
AutoBool TargetProperties::GetSwiftPCMValidation() const {
4938+
const Property *exp_property =
4939+
m_collection_sp->GetPropertyAtIndex(ePropertyExperimental);
4940+
OptionValueProperties *exp_values =
4941+
exp_property->GetValue()->GetAsProperties();
4942+
if (exp_values)
4943+
return exp_values
4944+
->GetPropertyAtIndexAs<AutoBool>(ePropertySwiftPCMValidation)
4945+
.value_or(AutoBool::Auto);
4946+
4947+
return AutoBool::Auto;
4948+
}
4949+
49304950
Args TargetProperties::GetSwiftPluginServerForPath() const {
49314951
const uint32_t idx = ePropertySwiftPluginServerForPath;
49324952

lldb/source/Target/TargetProperties.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ let Definition = "target_experimental" in {
2626
def SwiftAllowExplicitModules: Property<"swift-allow-explicit-modules", "Boolean">,
2727
DefaultTrue,
2828
Desc<"Allows explicit module flags to be passed through to ClangImporter.">;
29+
def SwiftPCMValidation: Property<"swift-pcm-validation", "Enum">,
30+
Global,
31+
DefaultEnumValue<"llvm::to_underlying(AutoBool::Auto)">,
32+
EnumValues<"OptionEnumValues(g_swift_pcm_validation_values)">,
33+
Desc<"Enable validation when loading Clang PCM files (-fvalidate-pch, -fmodules-check-relocated).">;
2934
}
3035

3136
let Definition = "target" in {

lldb/test/API/lang/swift/clangimporter/fmodule_flags/TestSwiftFModuleFlags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ def test(self):
2424
# CHECK-NOT: -fno-implicit-modules
2525
# CHECK-NOT: -fno-implicit-module-maps
2626
# CHECK: -DMARKER2
27+
# CHECK: PCM validation is

0 commit comments

Comments
 (0)