Skip to content

Commit 395d504

Browse files
authored
Merge pull request #8 from swiftwasm/swift/release/5.3
[pull] swiftwasm-release/5.3 from swift/release/5.3
2 parents 366e25f + dcc89a2 commit 395d504

File tree

25 files changed

+752
-338
lines changed

25 files changed

+752
-338
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ bool DlAddrSymbolizer::SymbolizeData(uptr addr, DataInfo *datainfo) {
5353

5454
#define K_ATOS_ENV_VAR "__check_mach_ports_lookup"
5555

56+
// This cannot live in `AtosSymbolizerProcess` because instances of that object
57+
// are allocated by the internal allocator which under ASan is poisoned with
58+
// kAsanInternalHeapMagic.
59+
static char kAtosMachPortEnvEntry[] = K_ATOS_ENV_VAR "=000000000000000";
60+
5661
class AtosSymbolizerProcess : public SymbolizerProcess {
5762
public:
5863
explicit AtosSymbolizerProcess(const char *path)
@@ -69,7 +74,7 @@ class AtosSymbolizerProcess : public SymbolizerProcess {
6974
// We use `putenv()` rather than `setenv()` so that we can later directly
7075
// write into the storage without LibC getting involved to change what the
7176
// variable is set to
72-
int result = putenv(mach_port_env_var_entry_);
77+
int result = putenv(kAtosMachPortEnvEntry);
7378
CHECK_EQ(result, 0);
7479
}
7580
}
@@ -95,12 +100,13 @@ class AtosSymbolizerProcess : public SymbolizerProcess {
95100
// for our task port. We can't call `setenv()` here because it might call
96101
// malloc/realloc. To avoid that we instead update the
97102
// `mach_port_env_var_entry_` variable with our current PID.
98-
uptr count = internal_snprintf(mach_port_env_var_entry_,
99-
sizeof(mach_port_env_var_entry_),
103+
uptr count = internal_snprintf(kAtosMachPortEnvEntry,
104+
sizeof(kAtosMachPortEnvEntry),
100105
K_ATOS_ENV_VAR "=%s", pid_str_);
101106
CHECK_GE(count, sizeof(K_ATOS_ENV_VAR) + internal_strlen(pid_str_));
102107
// Document our assumption but without calling `getenv()` in normal
103108
// builds.
109+
DCHECK(getenv(K_ATOS_ENV_VAR));
104110
DCHECK_EQ(internal_strcmp(getenv(K_ATOS_ENV_VAR), pid_str_), 0);
105111
}
106112

@@ -127,9 +133,10 @@ class AtosSymbolizerProcess : public SymbolizerProcess {
127133
}
128134

129135
char pid_str_[16];
130-
// Space for `\0` in `kAtosEnvVar_` is reused for `=`.
131-
char mach_port_env_var_entry_[sizeof(K_ATOS_ENV_VAR) + sizeof(pid_str_)] =
132-
K_ATOS_ENV_VAR "=0";
136+
// Space for `\0` in `K_ATOS_ENV_VAR` is reused for `=`.
137+
static_assert(sizeof(kAtosMachPortEnvEntry) ==
138+
(sizeof(K_ATOS_ENV_VAR) + sizeof(pid_str_)),
139+
"sizes should match");
133140
};
134141

135142
#undef K_ATOS_ENV_VAR

compiler-rt/lib/ubsan/ubsan_init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static void CommonStandaloneInit() {
4141
AndroidLogInit();
4242
InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
4343
CommonInit();
44+
Symbolizer::LateInitialize();
4445
}
4546

4647
void __ubsan::InitAsStandalone() {

lldb/include/lldb/Symbol/SwiftASTContext.h

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum class IRGenDebugInfoLevel : unsigned;
3939
class CanType;
4040
class DependencyTracker;
4141
class DWARFImporterDelegate;
42+
struct ImplicitImportInfo;
4243
class IRGenOptions;
4344
class NominalTypeDecl;
4445
class SearchPathOptions;
@@ -595,7 +596,13 @@ class SwiftASTContext : public TypeSystemSwift {
595596
/// \return the ExtraArgs of the ClangImporterOptions.
596597
const std::vector<std::string> &GetClangArguments();
597598

598-
swift::ModuleDecl *CreateModule(const SourceModule &module, Status &error);
599+
/// Attempt to create a Swift module, returning \c nullptr and setting
600+
/// \p error if unsuccessful.
601+
///
602+
/// \param importInfo Information about which modules should be implicitly
603+
/// imported by each file of the module.
604+
swift::ModuleDecl *CreateModule(const SourceModule &module, Status &error,
605+
swift::ImplicitImportInfo importInfo);
599606

600607
// This function should only be called when all search paths
601608
// for all items in a swift::ASTContext have been setup to
@@ -1064,16 +1071,30 @@ class SwiftASTContext : public TypeSystemSwift {
10641071

10651072
void SetCachedType(ConstString mangled, const lldb::TypeSP &type_sp) override;
10661073

1067-
static bool PerformUserImport(SwiftASTContext &swift_ast_context,
1068-
SymbolContext &sc,
1069-
ExecutionContextScope &exe_scope,
1070-
lldb::StackFrameWP &stack_frame_wp,
1071-
swift::SourceFile &source_file, Status &error);
1072-
1073-
static bool PerformAutoImport(SwiftASTContext &swift_ast_context,
1074-
SymbolContext &sc,
1075-
lldb::StackFrameWP &stack_frame_wp,
1076-
swift::SourceFile *source_file, Status &error);
1074+
/// Retrieves the modules that need to be implicitly imported in a given
1075+
/// execution scope. This includes the modules imported by both the compile
1076+
/// unit as well as any imports from previous expression evaluations.
1077+
static bool
1078+
GetImplicitImports(SwiftASTContext &swift_ast_context, SymbolContext &sc,
1079+
ExecutionContextScope &exe_scope,
1080+
lldb::StackFrameWP &stack_frame_wp,
1081+
llvm::SmallVectorImpl<swift::ModuleDecl *> &modules,
1082+
Status &error);
1083+
1084+
/// Cache the user's imports from a SourceFile in a given execution scope such
1085+
/// that they are carried over into future expression evaluations.
1086+
static bool CacheUserImports(SwiftASTContext &swift_ast_context,
1087+
SymbolContext &sc,
1088+
ExecutionContextScope &exe_scope,
1089+
lldb::StackFrameWP &stack_frame_wp,
1090+
swift::SourceFile &source_file, Status &error);
1091+
1092+
/// Retrieve the modules imported by the compilation unit.
1093+
static bool
1094+
GetCompileUnitImports(SwiftASTContext &swift_ast_context, SymbolContext &sc,
1095+
lldb::StackFrameWP &stack_frame_wp,
1096+
llvm::SmallVectorImpl<swift::ModuleDecl *> &modules,
1097+
Status &error);
10771098

10781099
protected:
10791100
/// This map uses the string value of ConstStrings as the key, and the

lldb/include/lldb/Utility/Reproducer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class FileProvider : public Provider<FileProvider> {
9898
return m_collector;
9999
}
100100

101+
void recordInterestingDirectory(const llvm::Twine &dir);
102+
101103
void Keep() override {
102104
auto mapping = GetRoot().CopyByAppendingPathComponent(Info::file);
103105
// Temporary files that are removed during execution can cause copy errors.

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,35 +1197,40 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
11971197
snprintf(expr_name_buf, sizeof(expr_name_buf), "__lldb_expr_%u",
11981198
options.GetExpressionNumber());
11991199

1200+
// Gather the modules that need to be implicitly imported.
1201+
// The Swift stdlib needs to be imported before the SwiftLanguageRuntime can
1202+
// be used.
1203+
Status implicit_import_error;
1204+
llvm::SmallVector<swift::ModuleDecl *, 16> additional_imports;
1205+
if (!SwiftASTContext::GetImplicitImports(*swift_ast_context, sc, exe_scope,
1206+
stack_frame_wp, additional_imports,
1207+
implicit_import_error)) {
1208+
return make_error<ModuleImportError>(llvm::Twine("in implicit-import:\n") +
1209+
implicit_import_error.AsCString());
1210+
}
1211+
1212+
swift::ImplicitImportInfo importInfo;
1213+
importInfo.StdlibKind = swift::ImplicitStdlibKind::Stdlib;
1214+
for (auto *module : additional_imports)
1215+
importInfo.AdditionalModules.emplace_back(module, /*exported*/ false);
1216+
12001217
auto module_id = ast_context->getIdentifier(expr_name_buf);
1201-
auto &module = *swift::ModuleDecl::create(module_id, *ast_context);
1202-
const auto implicit_import_kind =
1203-
swift::SourceFile::ImplicitModuleImportKind::Stdlib;
1218+
auto &module = *swift::ModuleDecl::create(module_id, *ast_context,
1219+
importInfo);
12041220

12051221
swift::SourceFileKind source_file_kind = swift::SourceFileKind::Library;
1206-
12071222
if (playground || repl) {
12081223
source_file_kind = swift::SourceFileKind::Main;
12091224
}
12101225

12111226
// Create the source file. Note, we disable delayed parsing for the
12121227
// swift expression parser.
12131228
swift::SourceFile *source_file = new (*ast_context) swift::SourceFile(
1214-
module, source_file_kind, buffer_id, implicit_import_kind,
1215-
/*Keep tokens*/ false, /*KeepSyntaxTree*/ false,
1229+
module, source_file_kind, buffer_id, /*Keep tokens*/ false,
1230+
/*KeepSyntaxTree*/ false,
12161231
swift::SourceFile::ParsingFlags::DisableDelayedBodies);
12171232
module.addFile(*source_file);
12181233

1219-
1220-
// The Swift stdlib needs to be imported before the
1221-
// SwiftLanguageRuntime can be used.
1222-
Status auto_import_error;
1223-
if (!SwiftASTContext::PerformAutoImport(*swift_ast_context, sc,
1224-
stack_frame_wp, source_file,
1225-
auto_import_error))
1226-
return make_error<ModuleImportError>(llvm::Twine("in auto-import:\n") +
1227-
auto_import_error.AsCString());
1228-
12291234
// Swift Modules that rely on shared libraries (not frameworks)
12301235
// don't record the link information in the swiftmodule file, so we
12311236
// can't really make them work without outside information.
@@ -1276,6 +1281,13 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
12761281
// inserting them in.
12771282
swift_ast_context->AddDebuggerClient(external_lookup);
12781283

1284+
if (swift_ast_context->HasErrors())
1285+
return make_error<SwiftASTContextError>();
1286+
1287+
// Resolve the file's imports, including the implicit ones returned from
1288+
// GetImplicitImports.
1289+
swift::performImportResolution(*source_file);
1290+
12791291
if (swift_ast_context->HasErrors())
12801292
return make_error<SwiftASTContextError>();
12811293

@@ -1327,21 +1339,16 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
13271339
stack_frame_sp.reset();
13281340
}
13291341

1330-
swift::performImportResolution(*source_file);
1331-
1332-
if (swift_ast_context->HasErrors())
1333-
return make_error<SwiftASTContextError>();
1334-
1335-
// Do the auto-importing after Name Binding, that's when the Imports
1336-
// for the source file are figured out.
1342+
// Cache the source file's imports such that they're accessible to future
1343+
// expression evaluations.
13371344
{
13381345
std::lock_guard<std::recursive_mutex> global_context_locker(
13391346
IRExecutionUnit::GetLLVMGlobalContextMutex());
13401347

13411348
Status auto_import_error;
1342-
if (!SwiftASTContext::PerformUserImport(*swift_ast_context, sc, exe_scope,
1343-
stack_frame_wp, *source_file,
1344-
auto_import_error)) {
1349+
if (!SwiftASTContext::CacheUserImports(*swift_ast_context, sc, exe_scope,
1350+
stack_frame_wp, *source_file,
1351+
auto_import_error)) {
13451352
return make_error<ModuleImportError>(llvm::Twine("in user-import:\n") +
13461353
auto_import_error.AsCString());
13471354
}

lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,18 +566,16 @@ void SwiftREPL::CompleteCode(const std::string &current_code,
566566
repl_module =
567567
swift_ast->GetModule(completion_module_info, error);
568568
if (repl_module == nullptr) {
569-
repl_module = swift_ast->CreateModule(completion_module_info, error);
570-
const swift::SourceFile::ImplicitModuleImportKind implicit_import_kind =
571-
swift::SourceFile::ImplicitModuleImportKind::Stdlib;
569+
swift::ImplicitImportInfo importInfo;
570+
importInfo.StdlibKind = swift::ImplicitStdlibKind::Stdlib;
571+
repl_module = swift_ast->CreateModule(completion_module_info, error,
572+
importInfo);
572573
llvm::Optional<unsigned> bufferID;
573574
swift::SourceFile *repl_source_file = new (*ast)
574575
swift::SourceFile(*repl_module, swift::SourceFileKind::REPL, bufferID,
575-
implicit_import_kind, /*Keep tokens*/false);
576-
577-
// Given this file is empty and only exists to import the standard
578-
// library, we can go ahead and just mark it as having been type checked.
579-
repl_source_file->ASTStage = swift::SourceFile::TypeChecked;
576+
/*Keep tokens*/false);
580577
repl_module->addFile(*repl_source_file);
578+
swift::performImportResolution(*repl_source_file);
581579
m_completion_module_initialized = true;
582580
}
583581
if (repl_module) {

0 commit comments

Comments
 (0)