Skip to content

Commit 6221b05

Browse files
Merge pull request #1399 from apple/swift/tensorflow-merge
Merge 2020-06-30 into swift/tensorflow
2 parents 4a7eb5f + eb53200 commit 6221b05

File tree

22 files changed

+195
-78
lines changed

22 files changed

+195
-78
lines changed

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,46 @@ function(darwin_test_archs os valid_archs)
166166
CACHE STRING "List of valid architectures for platform ${os}." FORCE)
167167
endfunction()
168168

169-
# This function checks the host cpusubtype to see if it is post-haswell. Haswell
170-
# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
169+
# This function checks the host cputype/cpusubtype to filter supported
170+
# architecture for the host OS. This is used to determine which tests are
171+
# available for the host.
171172
function(darwin_filter_host_archs input output)
172173
list_intersect(tmp_var DARWIN_osx_ARCHS ${input})
173174
execute_process(
174-
COMMAND sysctl hw.cpusubtype
175-
OUTPUT_VARIABLE SUBTYPE)
176-
177-
string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
178-
SUBTYPE_MATCHED "${SUBTYPE}")
179-
set(HASWELL_SUPPORTED Off)
180-
if(SUBTYPE_MATCHED)
181-
if(${CMAKE_MATCH_1} GREATER 7)
182-
set(HASWELL_SUPPORTED On)
175+
COMMAND sysctl hw.cputype
176+
OUTPUT_VARIABLE CPUTYPE)
177+
string(REGEX MATCH "hw.cputype: ([0-9]*)"
178+
CPUTYPE_MATCHED "${CPUTYPE}")
179+
set(ARM_HOST Off)
180+
if(CPUTYPE_MATCHED)
181+
# ARM cputype is (0x01000000 | 12) and X86(_64) is always 7.
182+
if(${CMAKE_MATCH_1} GREATER 11)
183+
set(ARM_HOST On)
183184
endif()
184185
endif()
185-
if(NOT HASWELL_SUPPORTED)
186-
list(REMOVE_ITEM tmp_var x86_64h)
186+
187+
if(ARM_HOST)
188+
list(REMOVE_ITEM tmp_var i386)
189+
else()
190+
list(REMOVE_ITEM tmp_var arm64)
191+
list(REMOVE_ITEM tmp_var arm64e)
192+
execute_process(
193+
COMMAND sysctl hw.cpusubtype
194+
OUTPUT_VARIABLE SUBTYPE)
195+
string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
196+
SUBTYPE_MATCHED "${SUBTYPE}")
197+
198+
set(HASWELL_SUPPORTED Off)
199+
if(SUBTYPE_MATCHED)
200+
if(${CMAKE_MATCH_1} GREATER 7)
201+
set(HASWELL_SUPPORTED On)
202+
endif()
203+
endif()
204+
if(NOT HASWELL_SUPPORTED)
205+
list(REMOVE_ITEM tmp_var x86_64h)
206+
endif()
187207
endif()
208+
188209
set(${output} ${tmp_var} PARENT_SCOPE)
189210
endfunction()
190211

compiler-rt/cmake/builtin-config-ix.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,34 @@ if(APPLE)
6060
find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
6161
find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)
6262

63+
# Get supported architecture from SDKSettings.
64+
function(sdk_has_arch_support sdk_path os arch has_support)
65+
execute_process(COMMAND
66+
/usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
67+
OUTPUT_VARIABLE SDK_SUPPORTED_ARCHS
68+
RESULT_VARIABLE PLIST_ERROR)
69+
if (PLIST_ERROR EQUAL 0 AND
70+
SDK_SUPPORTED_ARCHS MATCHES " ${arch}\n")
71+
message(STATUS "Found ${arch} support in ${sdk_path}/SDKSettings.plist")
72+
set("${has_support}" On PARENT_SCOPE)
73+
else()
74+
message(STATUS "No ${arch} support in ${sdk_path}/SDKSettings.plist")
75+
set("${has_support}" Off PARENT_SCOPE)
76+
endif()
77+
endfunction()
78+
6379
set(DARWIN_EMBEDDED_PLATFORMS)
6480
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
6581
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
6682
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
6783
set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
84+
# Add support for arm64 macOS if available in SDK.
85+
foreach(arch ${ARM64})
86+
sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
87+
if (MACOS_ARM_SUPPORT)
88+
list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
89+
endif()
90+
endforeach(arch)
6891

6992
if(COMPILER_RT_ENABLE_IOS)
7093
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
#define SANITIZER_INTERCEPT_STATFS \
342342
(SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
343343
#define SANITIZER_INTERCEPT_STATFS64 \
344-
((SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID)
344+
(((SI_MAC && !TARGET_CPU_ARM64) && !SI_IOS) || SI_LINUX_NOT_ANDROID)
345345
#define SANITIZER_INTERCEPT_STATVFS \
346346
(SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID)
347347
#define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ typedef struct user_fpregs elf_fpregset_t;
170170
namespace __sanitizer {
171171
unsigned struct_utsname_sz = sizeof(struct utsname);
172172
unsigned struct_stat_sz = sizeof(struct stat);
173-
#if !SANITIZER_IOS
173+
#if !SANITIZER_IOS && !(SANITIZER_MAC && TARGET_CPU_ARM64)
174174
unsigned struct_stat64_sz = sizeof(struct stat64);
175175
#endif // !SANITIZER_IOS
176176
unsigned struct_rusage_sz = sizeof(struct rusage);
@@ -196,7 +196,7 @@ namespace __sanitizer {
196196
unsigned struct_regex_sz = sizeof(regex_t);
197197
unsigned struct_regmatch_sz = sizeof(regmatch_t);
198198

199-
#if SANITIZER_MAC && !SANITIZER_IOS
199+
#if (SANITIZER_MAC && !TARGET_CPU_ARM64) && !SANITIZER_IOS
200200
unsigned struct_statfs64_sz = sizeof(struct statfs64);
201201
#endif // SANITIZER_MAC && !SANITIZER_IOS
202202

lldb/include/lldb/Symbol/SwiftASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ class SwiftASTContext : public TypeSystemSwift {
13321332
bool m_initialized_clang_importer_options = false;
13331333
bool m_reported_fatal_error = false;
13341334

1335-
// Whether this is a scratch or a module AST context.
1335+
/// Whether this is a scratch or a module AST context.
13361336
bool m_is_scratch_context = false;
13371337

13381338
Status m_fatal_errors;

lldb/source/Plugins/Language/Swift/SwiftOptional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ lldb::ValueObjectSP lldb_private::formatters::swift::
221221
if (IsEmpty())
222222
return nullptr;
223223
auto child = m_some->GetChildAtIndex(idx, true);
224-
if (m_some->IsSyntheticChildrenGenerated())
224+
if (child && m_some->IsSyntheticChildrenGenerated())
225225
child->SetSyntheticChildrenGenerated(true);
226226
return child;
227227
}

lldb/source/Symbol/SwiftASTContext.cpp

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,9 @@ SwiftASTContext::SwiftASTContext(std::string description, llvm::Triple triple,
909909
// Set the dependency tracker.
910910
if (auto g = repro::Reproducer::Instance().GetGenerator()) {
911911
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
912-
m_dependency_tracker =
913-
std::make_unique<swift::DependencyTracker>(true, fp.GetFileCollector());
912+
m_dependency_tracker = std::make_unique<swift::DependencyTracker>(
913+
swift::IntermoduleDepTrackingMode::IncludeSystem,
914+
fp.GetFileCollector());
914915
}
915916
// rdar://53971116
916917
m_compiler_invocation_ap->disableASTScopeLookup();
@@ -1556,13 +1557,21 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
15561557
return dsym;
15571558
}
15581559

1560+
/// Detect whether a Swift module was "imported" by DWARFImporter.
1561+
/// All this *really* means is that it couldn't be loaded through any
1562+
/// other mechanism.
1563+
static bool IsDWARFImported(swift::ModuleDecl &module) {
1564+
return std::any_of(module.getFiles().begin(), module.getFiles().end(),
1565+
[](swift::FileUnit *file_unit) {
1566+
return (file_unit->getKind() ==
1567+
swift::FileUnitKind::DWARFModule);
1568+
});
1569+
}
1570+
15591571
lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
15601572
Module &module,
15611573
Target *target,
15621574
bool fallback) {
1563-
std::vector<std::string> module_search_paths;
1564-
std::vector<std::pair<std::string, bool>> framework_search_paths;
1565-
15661575
if (!SwiftASTContextSupportsLanguage(language))
15671576
return lldb::TypeSystemSP();
15681577

@@ -1576,16 +1585,33 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
15761585
module.GetDescription(ss, eDescriptionLevelBrief);
15771586
ss << '"' << ')';
15781587
}
1588+
std::vector<std::string> module_search_paths;
1589+
std::vector<std::pair<std::string, bool>> framework_search_paths;
1590+
1591+
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(Module)");
1592+
1593+
auto logError = [&](const char *message) {
1594+
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Failed to create module context - %s",
1595+
message);
1596+
};
15791597

15801598
ArchSpec arch = module.GetArchitecture();
1599+
if (!arch.IsValid()) {
1600+
logError("invalid module architecture");
1601+
return TypeSystemSP();
1602+
}
15811603

15821604
ObjectFile *objfile = module.GetObjectFile();
1583-
if (!objfile)
1584-
return {};
1605+
if (!objfile) {
1606+
logError("no object file for module");
1607+
return TypeSystemSP();
1608+
}
15851609

15861610
ArchSpec object_arch = objfile->GetArchitecture();
1587-
if (!object_arch.IsValid())
1588-
return {};
1611+
if (!object_arch.IsValid()) {
1612+
logError("invalid objfile architecture");
1613+
return TypeSystemSP();
1614+
}
15891615

15901616
lldb::CompUnitSP main_compile_unit_sp = module.GetCompileUnitAtIndex(0);
15911617

@@ -1641,9 +1667,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
16411667
swift_ast_sp->GetLanguageOptions().EnableAccessControl = false;
16421668
swift_ast_sp->GetLanguageOptions().EnableTargetOSChecking = false;
16431669

1644-
if (!arch.IsValid())
1645-
return TypeSystemSP();
1646-
16471670
swift_ast_sp->SetTriple(triple, &module);
16481671

16491672
bool set_triple = false;
@@ -1654,7 +1677,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
16541677
std::string target_triple;
16551678

16561679
if (sym_file) {
1657-
bool got_serialized_options;
1680+
bool got_serialized_options = false;
16581681
llvm::SmallString<0> error;
16591682
llvm::raw_svector_ostream errs(error);
16601683
if (DeserializeAllCompilerFlags(*swift_ast_sp, module, m_description, errs,
@@ -1681,7 +1704,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
16811704
//
16821705
// This step is skipped for modules that don't have any Swift
16831706
// debug info. (We assume that a module without a .swift_ast
1684-
// section has not debuggable Swift code). This skips looking
1707+
// section has no debuggable Swift code). This skips looking
16851708
// through all the shared cache dylibs when they don't have debug
16861709
// info.
16871710
if (found_swift_modules) {
@@ -1784,6 +1807,20 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
17841807
swift_ast_sp->LogConfiguration();
17851808
}
17861809
}
1810+
1811+
if (swift_ast_sp->HasFatalErrors()) {
1812+
logError(swift_ast_sp->GetFatalErrors().AsCString());
1813+
return {};
1814+
}
1815+
1816+
const bool can_create = true;
1817+
swift::ModuleDecl *stdlib =
1818+
swift_ast_sp->m_ast_context_ap->getStdlibModule(can_create);
1819+
if (!stdlib || IsDWARFImported(*stdlib)) {
1820+
logError("couldn't load the Swift stdlib");
1821+
return {};
1822+
}
1823+
17871824
return swift_ast_sp;
17881825
}
17891826

@@ -1840,17 +1877,6 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
18401877
return ModuleSP();
18411878
}
18421879

1843-
/// Detect whether a Swift module was "imported" by DWARFImporter.
1844-
/// All this *really* means is that it couldn't be loaded through any
1845-
/// other mechanism.
1846-
static bool IsDWARFImported(swift::ModuleDecl &module) {
1847-
return std::any_of(module.getFiles().begin(), module.getFiles().end(),
1848-
[](swift::FileUnit *file_unit) {
1849-
return (file_unit->getKind() ==
1850-
swift::FileUnitKind::DWARFModule);
1851-
});
1852-
}
1853-
18541880
lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
18551881
Target &target,
18561882
const char *extra_options) {
@@ -2894,9 +2920,6 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
28942920
class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
28952921
SwiftASTContext &m_swift_ast_ctx;
28962922
using ModuleAndName = std::pair<const char *, const char *>;
2897-
/// Caches successful lookups for the scratch context.
2898-
llvm::DenseMap<ModuleAndName, llvm::SmallVector<clang::QualType, 1>>
2899-
m_decl_cache;
29002923
std::string m_description;
29012924

29022925
/// Used to filter out types with mismatching kinds.
@@ -3106,27 +3129,32 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
31063129
auto *swift_ast_ctx = static_cast<SwiftASTContext *>(&*ts);
31073130
auto *dwarf_imp = static_cast<SwiftDWARFImporterDelegate *>(
31083131
swift_ast_ctx->GetDWARFImporterDelegate());
3109-
if (!dwarf_imp)
3132+
if (!dwarf_imp || dwarf_imp == this)
31103133
continue;
3111-
auto it = dwarf_imp->m_decl_cache.find(
3112-
{module_cs.GetCString(), name_cs.GetCString()});
3113-
if (it == dwarf_imp->m_decl_cache.end())
3134+
3135+
llvm::SmallVector<clang::Decl *, 2> module_results;
3136+
dwarf_imp->lookupValue(name, kind, inModule, module_results);
3137+
if (!module_results.size())
31143138
continue;
31153139

31163140
auto *from_clang_importer = swift_ast_ctx->GetClangImporter();
31173141
if (!from_clang_importer)
31183142
continue;
31193143
auto &from_ctx = from_clang_importer->getClangASTContext();
31203144
auto &to_ctx = clang_importer->getClangASTContext();
3121-
for (clang::QualType qual_type : it->second)
3145+
for (clang::Decl *decl : module_results) {
3146+
clang::QualType qual_type;
3147+
if (auto *interface = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
3148+
qual_type = {interface->getTypeForDecl(), 0};
3149+
if (auto *type = llvm::dyn_cast<clang::TypeDecl>(decl))
3150+
qual_type = {type->getTypeForDecl(), 0};
31223151
importType(qual_type, from_ctx, to_ctx, kind, results);
3152+
}
3153+
// Cut the search short after we found the first result.
3154+
if (results.size())
3155+
break;
31233156
}
3124-
LOG_PRINTF(LIBLLDB_LOG_TYPES, "%d types found in cache.", results.size());
3125-
3126-
// TODO: Otherwise, the correct thing to do is to invoke
3127-
// search() on all modules. In practice, however, this is
3128-
// prohibitively expensive, so we need to do something
3129-
// more targeted.
3157+
LOG_PRINTF(LIBLLDB_LOG_TYPES, "%d types collected.", results.size());
31303158
return;
31313159
}
31323160

@@ -3154,11 +3182,6 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
31543182
clang::QualType qual_type = ClangUtil::GetQualType(compiler_type);
31553183
importType(qual_type, from_ctx, to_ctx, kind, results);
31563184

3157-
// If this is a module context, cache the result for the scratch context.
3158-
if (m_swift_ast_ctx.GetModule())
3159-
m_decl_cache[{module_cs.GetCString(), name_cs.GetCString()}].push_back(
3160-
qual_type);
3161-
31623185
return true;
31633186
});
31643187

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct FromDylib {
2+
int i;
3+
};
4+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import CFoo
2+
3+
public struct WrappingFromDylib {
4+
let s : FromDylib = FromDylib(i: 23)
5+
}
6+
7+
private let anchor = WrappingFromDylib()
8+
9+
public func foo() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
3+
LD_EXTRAS = -L$(BUILDDIR) -lFoo
4+
5+
all: libFoo.dylib $(EXE)
6+
7+
include Makefile.rules
8+
9+
libFoo.dylib: Foo.swift
10+
$(MAKE) MAKE_DSYM=NO VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk all

0 commit comments

Comments
 (0)