Skip to content

Commit 78471c5

Browse files
author
git apple-llvm automerger
committed
Merge commit '31f0cdc6d5ff' from swift/release/6.0 into stable/20230725
2 parents 51ed540 + 31f0cdc commit 78471c5

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

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

92289262
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)