Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
0e7e4ba
[CodeCompletion] Add an already-fixed crashing test case
rintaro May 14, 2020
d57cbce
Fixes example snippets in Set.swift
valeriyvan May 14, 2020
89a671d
SILGen: Refactor emitOrDelayFunction() to not take a closure
slavapestov May 14, 2020
ee92a11
SILGen: Simplify on-demand function emission
slavapestov May 15, 2020
2965cd2
SILGen: Emit enum element constructors using the 'on-demand' mechanism
slavapestov May 15, 2020
d60d6dd
[gardening] Propagate type info to silence static analyzer nullptr er…
gottesmm May 15, 2020
b5568e0
[CSGen] Allow closure parameters to become holes by default
xedin May 14, 2020
2b8518b
[ConstraintSystem] Add a way to check whether a given type variable r…
xedin May 14, 2020
bf4c513
[CSFix] Add a fix to use when type of closure parameter can't be infe…
xedin May 14, 2020
7e4eb9c
[Diagnostics] Diagnose inability to infer type of a closure parameter
xedin May 14, 2020
f68e8d2
[Diagnostics] Don't diagnose inability to infer closure parameter if …
xedin May 14, 2020
2f91f21
[ConstraintSystem] Don't contract edges with type holes
xedin May 15, 2020
d111f11
[ConstraintSystem] Detect and diagnose inability to infer type of clo…
xedin May 15, 2020
d740824
Allow space after json key name. JSONEncoder has this (used by swift-…
cltnschlosser May 15, 2020
a70e606
Fix an OOB read in the demangler (#31793)
tbkka May 15, 2020
61d4793
Added tests for edge cases in importing and mangling C structs
gribozavr May 15, 2020
01dcc29
Merge pull request #31809 from xedin/rdar-63230293
xedin May 15, 2020
3fa1d1f
runtime: ingest LLVMSupport into the runtime
compnerd May 8, 2020
b72788c
runtime: namespace LLVMSupport fork
compnerd May 11, 2020
bb10270
runtime: prune LLVMSupport
compnerd May 11, 2020
6244af5
runtime: generate the link arguments in CMake
compnerd May 15, 2020
0a41ac9
[NFC] initAssociatedTypeWitness is now unused in non-ptrauth builds
rjmccall May 15, 2020
a16c485
IRGen: "Simple" partial_apply still needs to re-sign the entry point …
jckarter May 14, 2020
7d08a24
ModuleInterface: reconstruct command-line arguments for building Swif…
nkcsgexi May 14, 2020
82728d3
Merge pull request #31808 from gottesmm/pr-b5aedd90dfc12a3be8e463e234…
gottesmm May 15, 2020
8adca54
[gardening] Add missing `sil_stage canonical` to a test.
gottesmm May 15, 2020
1053189
[ownership] Remove -disable-sil-ownership-verifier from a test.
gottesmm May 15, 2020
5d3f173
IRGen: Only replace opaque result types of function result types when
aschwaighofer May 15, 2020
29398b1
[ASTPrinter] Don't print inferred opaque result type witness
rintaro May 15, 2020
e85b658
Merge pull request #31813 from gribozavr/add-tests
gribozavr May 15, 2020
7b70120
Merge pull request #31665 from compnerd/indigestion
compnerd May 15, 2020
9d53c95
Merge pull request #31791 from nkcsgexi/command-arg-for-build-interface
nkcsgexi May 15, 2020
47d1457
Merge pull request #31805 from slavapestov/simplify-on-demand
slavapestov May 15, 2020
f05e063
Merge pull request #31799 from jckarter/simple-partial-apply-arm64e
jckarter May 15, 2020
73d9545
Merge pull request #31817 from compnerd/bashful
drexin May 15, 2020
616a787
Merge pull request #31797 from valeriyvan/FixExampleSnippetsSet.swift
CodaFi May 15, 2020
2245ec2
Merge pull request #31815 from cltnschlosser/swift-driver-json-space
CodaFi May 15, 2020
a99a93d
[silgen] Add interpreter tests for families of throwing initializers …
gottesmm May 15, 2020
677f42d
Merge pull request #31820 from rjmccall/unused-associated-type-elimin…
rjmccall May 15, 2020
ffbfcfa
SILGen: Extend scope for evaluation in memberwise initializers to inc…
jckarter May 15, 2020
1c5a4a8
Merge pull request #31824 from gottesmm/pr-3475f9a686612f497f7c626b14…
swift-ci May 15, 2020
4d000f0
Merge pull request #31821 from rintaro/ide-completion-rdar59817674
rintaro May 15, 2020
a8c47de
Merge pull request #31831 from gottesmm/pr-91bb523a50019c1625bffb3b1f…
swift-ci May 15, 2020
a59a67a
Merge pull request #31787 from rintaro/ide-completion-rdar58470999
rintaro May 16, 2020
cda33a9
Merge pull request #31825 from aschwaighofer/irgen_fix_opaque_result_…
aschwaighofer May 16, 2020
514a042
GSB: Concretize nested types when adding a superclass constraint
slavapestov May 16, 2020
2e0ca0b
Update docs and tests for LLVMFuzzerTestOneInput (#31802)
benrimmington May 16, 2020
91601cf
Merge pull request #31832 from jckarter/memberwise-initializer-scope
jckarter May 16, 2020
80dd7fa
Merge pull request #31835 from slavapestov/gsb-superclass-nested-type
slavapestov May 16, 2020
b080d4d
Merge branch 'master' of github.com:swiftwasm/swift into maxd/master-…
MaxDesiatov May 16, 2020
06f0d2f
Handle static-stdlib-args.lnk same as upstream
MaxDesiatov May 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions docs/libFuzzerIntegration.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
libFuzzer Integration
---------------------

Swift compiler comes with a built-in `libFuzzer` integration.
In order to use it on a file `myfile.swift`, we define an entry point fuzzing function
with a `@_cdecl("LLVMFuzzerTestOneInput")` annotation:
# libFuzzer Integration

Custom builds of the Swift toolchain (including development snapshots)
have a built-in `libFuzzer` integration. In order to use it on a file
`myfile.swift`, define an entry point fuzzing function with a
`@_cdecl("LLVMFuzzerTestOneInput")` annotation:

```swift
@_cdecl("LLVMFuzzerTestOneInput") public func fuzzMe(Data: UnsafePointer<CChar>, Size: CInt) -> CInt{
// Test our code using provided Data.
}
@_cdecl("LLVMFuzzerTestOneInput")
public func test(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
let bytes = UnsafeRawBufferPointer(start: start, count: count)
// TODO: Test the code using the provided bytes.
return 0
}
```

To compile it, we use `-sanitize=fuzzer` flag to link `libFuzzer`
and enable coverage annotation, and `-parse-as-library` flag not to insert
the `main` symbol, such that the fuzzer entry point can be used:
To compile it, use the `-sanitize=fuzzer` flag to link `libFuzzer`
and enable code coverage information; and the `-parse-as-library` flag
to omit the `main` symbol, so that the fuzzer entry point can be used:

```bash
% swiftc -sanitize=fuzzer -parse-as-library myfile.swift
```

`libFuzzer` can be also combined with other sanitizers:
`libFuzzer` can be combined with other sanitizers:

```bash
% swiftc -sanitize=fuzzer,address -parse-as-library myfile.swift
```

Finally, we launch the fuzzing process:
Finally, launch the fuzzing process:

```bash
% ./a.out
% ./myfile
```

Refer to the official `libFuzzer` documentation at http://llvm.org/docs/LibFuzzer.html
for the description of flags the resulting binary has.
Refer to the official `libFuzzer` documentation at
<https://llvm.org/docs/LibFuzzer.html#options>
for a description of the fuzzer's command line options.
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ ERROR(no_candidates_match_result_type,none,
"no '%0' candidates produce the expected contextual result type %1",
(StringRef, Type))

ERROR(cannot_infer_closure_parameter_type,none,
"unable to infer type of a closure parameter %0 in the current context",
(StringRef))
ERROR(cannot_infer_closure_type,none,
"unable to infer closure type in the current context", ())
ERROR(cannot_infer_closure_result_type,none,
Expand Down
23 changes: 18 additions & 5 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class SwiftModuleDependenciesStorage : public ModuleDependenciesStorageBase {
/// The Swift interface file, if it can be used to generate the module file.
const Optional<std::string> swiftInterfaceFile;

/// The Swift frontend invocation arguments to build the Swift module from the
/// interface.
const std::vector<std::string> buildCommandLine;

/// The hash value that will be used for the generated module
const std::string contextHash;

/// Bridging header file, if there is one.
Optional<std::string> bridgingHeaderFile;

Expand All @@ -82,9 +89,13 @@ class SwiftModuleDependenciesStorage : public ModuleDependenciesStorageBase {

SwiftModuleDependenciesStorage(
const std::string &compiledModulePath,
const Optional<std::string> &swiftInterfaceFile
const Optional<std::string> &swiftInterfaceFile,
ArrayRef<StringRef> buildCommandLine,
StringRef contextHash
) : ModuleDependenciesStorageBase(/*isSwiftModule=*/true, compiledModulePath),
swiftInterfaceFile(swiftInterfaceFile) { }
swiftInterfaceFile(swiftInterfaceFile),
buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()),
contextHash(contextHash) { }

ModuleDependenciesStorageBase *clone() const override {
return new SwiftModuleDependenciesStorage(*this);
Expand Down Expand Up @@ -162,18 +173,20 @@ class ModuleDependencies {
/// built from a Swift interface file (\c .swiftinterface).
static ModuleDependencies forSwiftInterface(
const std::string &compiledModulePath,
const std::string &swiftInterfaceFile) {
const std::string &swiftInterfaceFile,
ArrayRef<StringRef> buildCommands,
StringRef contextHash) {
return ModuleDependencies(
std::make_unique<SwiftModuleDependenciesStorage>(
compiledModulePath, swiftInterfaceFile));
compiledModulePath, swiftInterfaceFile, buildCommands, contextHash));
}

/// Describe the module dependencies for a serialized or parsed Swift module.
static ModuleDependencies forSwiftModule(
const std::string &compiledModulePath) {
return ModuleDependencies(
std::make_unique<SwiftModuleDependenciesStorage>(
compiledModulePath, None));
compiledModulePath, None, ArrayRef<StringRef>(), StringRef()));
}

/// Describe the module dependencies for a Clang module that can be
Expand Down
4 changes: 3 additions & 1 deletion include/swift/AST/ModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class DependencyTracker {
struct SubCompilerInstanceInfo {
StringRef CompilerVersion;
CompilerInstance* Instance;
StringRef Hash;
ArrayRef<StringRef> BuildArguments;
};

/// Abstract interface to run an action in a sub ASTContext.
Expand All @@ -97,7 +99,7 @@ struct InterfaceSubContextDelegate {
StringRef interfacePath,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<bool(ASTContext&)> action) = 0;
llvm::function_ref<bool(ASTContext&,ArrayRef<StringRef>, StringRef)> action) = 0;
virtual bool runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
StringRef outputPath,
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Basic/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct function_traits<R (T::*)(Args...) const> {

} // end namespace swift

#if !defined(swiftCore_EXPORTS)
namespace llvm {

/// @{
Expand Down Expand Up @@ -109,6 +110,7 @@ inline void interleave(const Container &c, UnaryFunctor each_fn,
/// @}

} // end namespace llvm
#endif

namespace swift {

Expand Down
3 changes: 1 addition & 2 deletions include/swift/Demangling/Demangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,7 @@ class Demangler : public NodeFactory {
NodePointer demangleValueWitness();

NodePointer demangleTypeMangling();
NodePointer demangleSymbolicReference(unsigned char rawKind,
const void *at);
NodePointer demangleSymbolicReference(unsigned char rawKind);

bool demangleBoundGenerics(Vector<NodePointer> &TypeListList,
NodePointer &RetroactiveConformances);
Expand Down
40 changes: 21 additions & 19 deletions include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
private:
SourceManager &SM;
DiagnosticEngine &Diags;
llvm::BumpPtrAllocator Allocator;
llvm::StringSaver ArgSaver;
std::vector<StringRef> GenericArgs;
CompilerInvocation subInvocation;
std::vector<SupplementaryOutputPaths> ModuleOutputPaths;

template<typename ...ArgTypes>
InFlightDiagnostic diagnose(StringRef interfacePath,
Expand All @@ -222,45 +226,43 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
}
return Diags.diagnose(loc, ID, std::move(Args)...);
}

bool extractSwiftInterfaceVersionAndArgs(llvm::StringSaver &SubArgSaver,
SmallVectorImpl<const char *> &SubArgs,
void inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
const LangOptions &LangOpts);
bool extractSwiftInterfaceVersionAndArgs(SmallVectorImpl<const char *> &SubArgs,
std::string &CompilerVersion,
StringRef interfacePath,
SourceLoc diagnosticLoc);
SubCompilerInstanceInfo createInstance(StringRef moduleName,
StringRef interfacePath,
StringRef outputPath,
SourceLoc diagLoc);
public:
InterfaceSubContextDelegateImpl(SourceManager &SM,
DiagnosticEngine &Diags,
const SearchPathOptions &searchPathOpts,
const LangOptions &langOpts,
ClangModuleLoader *clangImporter = nullptr,
StringRef moduleCachePath = StringRef(),
StringRef prebuiltCachePath = StringRef(),
bool serializeDependencyHashes = false,
bool trackSystemDependencies = false,
bool remarkOnRebuildFromInterface = false,
bool disableInterfaceFileLock = false);
ClangModuleLoader *clangImporter,
bool buildModuleCacheDirIfAbsent,
StringRef moduleCachePath,
StringRef prebuiltCachePath,
bool serializeDependencyHashes,
bool trackSystemDependencies,
bool remarkOnRebuildFromInterface,
bool disableInterfaceFileLock);
bool runInSubContext(StringRef moduleName,
StringRef interfacePath,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<bool(ASTContext&)> action) override;
llvm::function_ref<bool(ASTContext&, ArrayRef<StringRef>, StringRef)> action) override;
bool runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<bool(SubCompilerInstanceInfo&)> action) override;
llvm::function_ref<bool(SubCompilerInstanceInfo&)> action) override;

~InterfaceSubContextDelegateImpl() = default;

/// includes a hash of relevant key data.
void computeCachedOutputPath(StringRef moduleName,
StringRef UseInterfacePath,
llvm::SmallString<256> &OutPath);
StringRef computeCachedOutputPath(StringRef moduleName,
StringRef UseInterfacePath,
llvm::SmallString<256> &OutPath,
StringRef &CacheHash);
std::string getCacheHash(StringRef useInterfacePath);
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Runtime/Concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class ConcurrentMapBase<EntryTy, false, Allocator> : protected Allocator {

// Deallocate the node. The static_cast here is required
// because LLVM's allocator API is insane.
this->Deallocate(static_cast<void*>(node), allocSize);
this->Deallocate(static_cast<void*>(node), allocSize, alignof(Node));
}
};

Expand Down
31 changes: 29 additions & 2 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,13 @@ static void concretizeNestedTypeFromConcreteParent(
GenericSignatureBuilder &builder) {
auto parentEquiv = parent->getEquivalenceClassIfPresent();
assert(parentEquiv && "can't have a concrete type without an equiv class");

bool isSuperclassConstrained = false;
auto concreteParent = parentEquiv->concreteType;
if (!concreteParent) {
isSuperclassConstrained = true;
concreteParent = parentEquiv->superclass;
}
assert(concreteParent &&
"attempting to resolve concrete nested type of non-concrete PA");

Expand All @@ -2564,8 +2570,14 @@ static void concretizeNestedTypeFromConcreteParent(
"No conformance requirement");
const RequirementSource *parentConcreteSource = nullptr;
for (const auto &constraint : parentEquiv->conformsTo.find(proto)->second) {
if (constraint.source->kind == RequirementSource::Concrete) {
parentConcreteSource = constraint.source;
if (!isSuperclassConstrained) {
if (constraint.source->kind == RequirementSource::Concrete) {
parentConcreteSource = constraint.source;
}
} else {
if (constraint.source->kind == RequirementSource::Superclass) {
parentConcreteSource = constraint.source;
}
}
}

Expand Down Expand Up @@ -4299,6 +4311,15 @@ bool GenericSignatureBuilder::updateSuperclass(
for (const auto &conforms : equivClass->conformsTo) {
(void)resolveSuperConformance(type, conforms.first);
}

// Eagerly resolve any existing nested types to their concrete forms (others
// will be "concretized" as they are constructed, in getNestedType).
for (auto equivT : equivClass->members) {
for (auto nested : equivT->getNestedTypes()) {
concretizeNestedTypeFromConcreteParent(equivT, nested.second.front(),
*this);
}
}
};

// If we haven't yet recorded a superclass constraint for this equivalence
Expand Down Expand Up @@ -7188,6 +7209,12 @@ void GenericSignatureBuilder::dump(llvm::raw_ostream &out) {
pa->dump(out, &Context.SourceMgr, 2);
}
out << "\n";

out << "Equivalence classes:\n";
for (auto &equiv : Impl->EquivalenceClasses) {
equiv.dump(out, this);
}
out << "\n";
}

void GenericSignatureBuilder::addGenericSignature(GenericSignature sig) {
Expand Down
22 changes: 13 additions & 9 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3521,24 +3521,28 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,

// Retrieve the type witness.
auto witness =
conformance.getConcrete()->getTypeWitness(assocType, options);
if (!witness || witness->hasError())
conformance.getConcrete()->getTypeWitnessAndDecl(assocType, options);

auto witnessTy = witness.getWitnessType();
if (!witnessTy || witnessTy->hasError())
return failed();

// This is a hacky feature allowing code completion to migrate to
// using Type::subst() without changing output.
if (options & SubstFlags::DesugarMemberTypes) {
if (auto *aliasType =
dyn_cast<TypeAliasType>(witness.getPointer())) {
if (!aliasType->is<ErrorType>())
witness = aliasType->getSinglyDesugaredType();
}
if (auto *aliasType = dyn_cast<TypeAliasType>(witnessTy.getPointer()))
witnessTy = aliasType->getSinglyDesugaredType();

// Another hack. If the type witness is a opaque result type. They can
// only be referred using the name of the associated type.
if (witnessTy->is<OpaqueTypeArchetypeType>())
witnessTy = witness.getWitnessDecl()->getDeclaredInterfaceType();
}

if (witness->is<ErrorType>())
if (witnessTy->is<ErrorType>())
return failed();

return witness;
return witnessTy;
}

return failed();
Expand Down
10 changes: 6 additions & 4 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,14 @@ NodePointer Demangler::demangleTypeMangling() {
return TypeMangling;
}

NodePointer Demangler::demangleSymbolicReference(unsigned char rawKind,
const void *at) {
NodePointer Demangler::demangleSymbolicReference(unsigned char rawKind) {
// The symbolic reference is a 4-byte machine integer encoded in the following
// four bytes.
if (Pos + 4 > Text.size())
return nullptr;
const void *at = Text.data() + Pos;
int32_t value;
memcpy(&value, Text.data() + Pos, 4);
memcpy(&value, at, 4);
Pos += 4;

// Map the encoded kind to a specific kind and directness.
Expand Down Expand Up @@ -734,7 +736,7 @@ NodePointer Demangler::demangleOperator() {
goto recur;
case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
case 9: case 0xA: case 0xB: case 0xC:
return demangleSymbolicReference((unsigned char)c, Text.data() + Pos);
return demangleSymbolicReference((unsigned char)c);
case 'A': return demangleMultiSubstitutions();
case 'B': return demangleBuiltinType();
case 'C': return demangleAnyGenericType(Node::Kind::Class);
Expand Down
6 changes: 4 additions & 2 deletions lib/Frontend/ModuleInterfaceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
llvm::RestorePrettyStackState(savedInnerPrettyStackState);
};

SubError = subASTDelegate.runInSubCompilerInstance(moduleName, interfacePath,
OutPath, diagnosticLoc,
SubError = subASTDelegate.runInSubCompilerInstance(moduleName,
interfacePath,
OutPath,
diagnosticLoc,
[&](SubCompilerInstanceInfo &info) {
auto &SubInstance = *info.Instance;
auto subInvocation = SubInstance.getInvocation();
Expand Down
Loading