Skip to content

Commit babe4b2

Browse files
committed
Turn off PCM validation by default.
These diagnostics are useful when debugging LLDB and project configurations, but in a live debug session they mostly get in the way. Especially when using explicit modules mismatches in warning options caused by implicitly triggered imports are not really actionable fo users outside of clearing their module cache and trying again. rdar://130284825
1 parent e43883d commit babe4b2

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"
@@ -9210,6 +9212,38 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
92109212
if (cu_imports.size() == 0)
92119213
return true;
92129214

9215+
// Set PCM validation. This is not a great place to do this, but it
9216+
// needs to happen after ClangImporter was created and
9217+
// m_has_explicit_modules has been initialized.
9218+
{
9219+
// Read the setting.
9220+
AutoBool validate_pcm_setting = AutoBool::Auto;
9221+
TargetSP target_sp = GetTargetWP().lock();
9222+
if (target_sp)
9223+
validate_pcm_setting = target_sp->GetSwiftPCMValidation();
9224+
9225+
// If the setting is explicit, honor it.
9226+
bool validate_pcm = validate_pcm_setting != AutoBool::False;
9227+
if (validate_pcm_setting == AutoBool::Auto) {
9228+
// Disable validation for explicit modules.
9229+
validate_pcm = m_has_explicit_modules ? false : true;
9230+
// Enable validation in asserts builds.
9231+
#ifndef NDEBUG
9232+
validate_pcm = true;
9233+
#endif
9234+
}
9235+
9236+
auto &pp_opts = m_clangimporter->getClangPreprocessor()
9237+
.getPreprocessorOpts();
9238+
pp_opts.DisablePCHOrModuleValidation =
9239+
validate_pcm ? clang::DisableValidationForModuleKind::None
9240+
: clang::DisableValidationForModuleKind::All;
9241+
pp_opts.ModulesCheckRelocated = validate_pcm;
9242+
9243+
LOG_PRINTF(GetLog(LLDBLog::Types), "PCM validation is %s",
9244+
validate_pcm ? "disabled" : "enabled");
9245+
}
9246+
92139247
LOG_PRINTF(GetLog(LLDBLog::Types), "Importing dependencies of current CU");
92149248

92159249
// Turn off implicit clang modules while importing CU dependencies.

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)