Skip to content

Commit b07c3e4

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 (cherry picked from commit babe4b2)
1 parent d0bec9d commit b07c3e4

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"
@@ -9225,6 +9227,38 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
92259227
if (cu_imports.size() == 0)
92269228
return true;
92279229

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

92309264
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
@@ -4625,6 +4625,13 @@ static constexpr OptionEnumValueElement g_memory_module_load_level_values[] = {
46254625
},
46264626
};
46274627

4628+
static constexpr OptionEnumValueElement g_swift_pcm_validation_values[] = {
4629+
{llvm::to_underlying(AutoBool::Auto), "auto",
4630+
"Turned on when explicit modules are enabled"},
4631+
{llvm::to_underlying(AutoBool::True), "true", "Enable validation."},
4632+
{llvm::to_underlying(AutoBool::False), "false", "Disable validation."},
4633+
};
4634+
46284635

46294636
#define LLDB_PROPERTIES_target
46304637
#include "TargetProperties.inc"
@@ -4856,6 +4863,19 @@ bool TargetProperties::GetSwiftAllowExplicitModules() const {
48564863
return true;
48574864
}
48584865

4866+
AutoBool TargetProperties::GetSwiftPCMValidation() const {
4867+
const Property *exp_property =
4868+
m_collection_sp->GetPropertyAtIndex(ePropertyExperimental);
4869+
OptionValueProperties *exp_values =
4870+
exp_property->GetValue()->GetAsProperties();
4871+
if (exp_values)
4872+
return exp_values
4873+
->GetPropertyAtIndexAs<AutoBool>(ePropertySwiftPCMValidation)
4874+
.value_or(AutoBool::Auto);
4875+
4876+
return AutoBool::Auto;
4877+
}
4878+
48594879
Args TargetProperties::GetSwiftPluginServerForPath() const {
48604880
const uint32_t idx = ePropertySwiftPluginServerForPath;
48614881

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)