Skip to content

Commit 1298bde

Browse files
authored
Merge pull request #1025 from swiftwasm/maxd/master-merge
Fix build issue after merging master
2 parents 7ed2e2e + 06f0d2f commit 1298bde

File tree

120 files changed

+16085
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+16085
-712
lines changed

docs/libFuzzerIntegration.md

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1-
libFuzzer Integration
2-
---------------------
3-
4-
Swift compiler comes with a built-in `libFuzzer` integration.
5-
In order to use it on a file `myfile.swift`, we define an entry point fuzzing function
6-
with a `@_cdecl("LLVMFuzzerTestOneInput")` annotation:
1+
# libFuzzer Integration
72

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

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

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

2021
```bash
2122
% swiftc -sanitize=fuzzer -parse-as-library myfile.swift
2223
```
2324

24-
`libFuzzer` can be also combined with other sanitizers:
25+
`libFuzzer` can be combined with other sanitizers:
2526

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

30-
Finally, we launch the fuzzing process:
31+
Finally, launch the fuzzing process:
3132

3233
```bash
33-
% ./a.out
34+
% ./myfile
3435
```
3536

36-
Refer to the official `libFuzzer` documentation at http://llvm.org/docs/LibFuzzer.html
37-
for the description of flags the resulting binary has.
37+
Refer to the official `libFuzzer` documentation at
38+
<https://llvm.org/docs/LibFuzzer.html#options>
39+
for a description of the fuzzer's command line options.

include/swift/AST/DiagnosticsSema.def

+3
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ ERROR(no_candidates_match_result_type,none,
250250
"no '%0' candidates produce the expected contextual result type %1",
251251
(StringRef, Type))
252252

253+
ERROR(cannot_infer_closure_parameter_type,none,
254+
"unable to infer type of a closure parameter %0 in the current context",
255+
(StringRef))
253256
ERROR(cannot_infer_closure_type,none,
254257
"unable to infer closure type in the current context", ())
255258
ERROR(cannot_infer_closure_result_type,none,

include/swift/AST/ModuleDependencies.h

+18-5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class SwiftModuleDependenciesStorage : public ModuleDependenciesStorageBase {
6868
/// The Swift interface file, if it can be used to generate the module file.
6969
const Optional<std::string> swiftInterfaceFile;
7070

71+
/// The Swift frontend invocation arguments to build the Swift module from the
72+
/// interface.
73+
const std::vector<std::string> buildCommandLine;
74+
75+
/// The hash value that will be used for the generated module
76+
const std::string contextHash;
77+
7178
/// Bridging header file, if there is one.
7279
Optional<std::string> bridgingHeaderFile;
7380

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

8390
SwiftModuleDependenciesStorage(
8491
const std::string &compiledModulePath,
85-
const Optional<std::string> &swiftInterfaceFile
92+
const Optional<std::string> &swiftInterfaceFile,
93+
ArrayRef<StringRef> buildCommandLine,
94+
StringRef contextHash
8695
) : ModuleDependenciesStorageBase(/*isSwiftModule=*/true, compiledModulePath),
87-
swiftInterfaceFile(swiftInterfaceFile) { }
96+
swiftInterfaceFile(swiftInterfaceFile),
97+
buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()),
98+
contextHash(contextHash) { }
8899

89100
ModuleDependenciesStorageBase *clone() const override {
90101
return new SwiftModuleDependenciesStorage(*this);
@@ -162,18 +173,20 @@ class ModuleDependencies {
162173
/// built from a Swift interface file (\c .swiftinterface).
163174
static ModuleDependencies forSwiftInterface(
164175
const std::string &compiledModulePath,
165-
const std::string &swiftInterfaceFile) {
176+
const std::string &swiftInterfaceFile,
177+
ArrayRef<StringRef> buildCommands,
178+
StringRef contextHash) {
166179
return ModuleDependencies(
167180
std::make_unique<SwiftModuleDependenciesStorage>(
168-
compiledModulePath, swiftInterfaceFile));
181+
compiledModulePath, swiftInterfaceFile, buildCommands, contextHash));
169182
}
170183

171184
/// Describe the module dependencies for a serialized or parsed Swift module.
172185
static ModuleDependencies forSwiftModule(
173186
const std::string &compiledModulePath) {
174187
return ModuleDependencies(
175188
std::make_unique<SwiftModuleDependenciesStorage>(
176-
compiledModulePath, None));
189+
compiledModulePath, None, ArrayRef<StringRef>(), StringRef()));
177190
}
178191

179192
/// Describe the module dependencies for a Clang module that can be

include/swift/AST/ModuleLoader.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class DependencyTracker {
8989
struct SubCompilerInstanceInfo {
9090
StringRef CompilerVersion;
9191
CompilerInstance* Instance;
92+
StringRef Hash;
93+
ArrayRef<StringRef> BuildArguments;
9294
};
9395

9496
/// Abstract interface to run an action in a sub ASTContext.
@@ -97,7 +99,7 @@ struct InterfaceSubContextDelegate {
9799
StringRef interfacePath,
98100
StringRef outputPath,
99101
SourceLoc diagLoc,
100-
llvm::function_ref<bool(ASTContext&)> action) = 0;
102+
llvm::function_ref<bool(ASTContext&,ArrayRef<StringRef>, StringRef)> action) = 0;
101103
virtual bool runInSubCompilerInstance(StringRef moduleName,
102104
StringRef interfacePath,
103105
StringRef outputPath,

include/swift/Basic/STLExtras.h

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct function_traits<R (T::*)(Args...) const> {
7171

7272
} // end namespace swift
7373

74+
#if !defined(swiftCore_EXPORTS)
7475
namespace llvm {
7576

7677
/// @{
@@ -109,6 +110,7 @@ inline void interleave(const Container &c, UnaryFunctor each_fn,
109110
/// @}
110111

111112
} // end namespace llvm
113+
#endif
112114

113115
namespace swift {
114116

include/swift/Demangling/Demangler.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,7 @@ class Demangler : public NodeFactory {
565565
NodePointer demangleValueWitness();
566566

567567
NodePointer demangleTypeMangling();
568-
NodePointer demangleSymbolicReference(unsigned char rawKind,
569-
const void *at);
568+
NodePointer demangleSymbolicReference(unsigned char rawKind);
570569

571570
bool demangleBoundGenerics(Vector<NodePointer> &TypeListList,
572571
NodePointer &RetroactiveConformances);

include/swift/Frontend/ModuleInterfaceLoader.h

+21-19
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
208208
private:
209209
SourceManager &SM;
210210
DiagnosticEngine &Diags;
211+
llvm::BumpPtrAllocator Allocator;
212+
llvm::StringSaver ArgSaver;
213+
std::vector<StringRef> GenericArgs;
211214
CompilerInvocation subInvocation;
215+
std::vector<SupplementaryOutputPaths> ModuleOutputPaths;
212216

213217
template<typename ...ArgTypes>
214218
InFlightDiagnostic diagnose(StringRef interfacePath,
@@ -222,45 +226,43 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
222226
}
223227
return Diags.diagnose(loc, ID, std::move(Args)...);
224228
}
225-
226-
bool extractSwiftInterfaceVersionAndArgs(llvm::StringSaver &SubArgSaver,
227-
SmallVectorImpl<const char *> &SubArgs,
229+
void inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
230+
const LangOptions &LangOpts);
231+
bool extractSwiftInterfaceVersionAndArgs(SmallVectorImpl<const char *> &SubArgs,
228232
std::string &CompilerVersion,
229233
StringRef interfacePath,
230234
SourceLoc diagnosticLoc);
231-
SubCompilerInstanceInfo createInstance(StringRef moduleName,
232-
StringRef interfacePath,
233-
StringRef outputPath,
234-
SourceLoc diagLoc);
235235
public:
236236
InterfaceSubContextDelegateImpl(SourceManager &SM,
237237
DiagnosticEngine &Diags,
238238
const SearchPathOptions &searchPathOpts,
239239
const LangOptions &langOpts,
240-
ClangModuleLoader *clangImporter = nullptr,
241-
StringRef moduleCachePath = StringRef(),
242-
StringRef prebuiltCachePath = StringRef(),
243-
bool serializeDependencyHashes = false,
244-
bool trackSystemDependencies = false,
245-
bool remarkOnRebuildFromInterface = false,
246-
bool disableInterfaceFileLock = false);
240+
ClangModuleLoader *clangImporter,
241+
bool buildModuleCacheDirIfAbsent,
242+
StringRef moduleCachePath,
243+
StringRef prebuiltCachePath,
244+
bool serializeDependencyHashes,
245+
bool trackSystemDependencies,
246+
bool remarkOnRebuildFromInterface,
247+
bool disableInterfaceFileLock);
247248
bool runInSubContext(StringRef moduleName,
248249
StringRef interfacePath,
249250
StringRef outputPath,
250251
SourceLoc diagLoc,
251-
llvm::function_ref<bool(ASTContext&)> action) override;
252+
llvm::function_ref<bool(ASTContext&, ArrayRef<StringRef>, StringRef)> action) override;
252253
bool runInSubCompilerInstance(StringRef moduleName,
253254
StringRef interfacePath,
254255
StringRef outputPath,
255256
SourceLoc diagLoc,
256-
llvm::function_ref<bool(SubCompilerInstanceInfo&)> action) override;
257+
llvm::function_ref<bool(SubCompilerInstanceInfo&)> action) override;
257258

258259
~InterfaceSubContextDelegateImpl() = default;
259260

260261
/// includes a hash of relevant key data.
261-
void computeCachedOutputPath(StringRef moduleName,
262-
StringRef UseInterfacePath,
263-
llvm::SmallString<256> &OutPath);
262+
StringRef computeCachedOutputPath(StringRef moduleName,
263+
StringRef UseInterfacePath,
264+
llvm::SmallString<256> &OutPath,
265+
StringRef &CacheHash);
264266
std::string getCacheHash(StringRef useInterfacePath);
265267
};
266268
}

include/swift/Runtime/Concurrent.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class ConcurrentMapBase<EntryTy, false, Allocator> : protected Allocator {
203203

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

lib/AST/GenericSignatureBuilder.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,13 @@ static void concretizeNestedTypeFromConcreteParent(
25422542
GenericSignatureBuilder &builder) {
25432543
auto parentEquiv = parent->getEquivalenceClassIfPresent();
25442544
assert(parentEquiv && "can't have a concrete type without an equiv class");
2545+
2546+
bool isSuperclassConstrained = false;
25452547
auto concreteParent = parentEquiv->concreteType;
2548+
if (!concreteParent) {
2549+
isSuperclassConstrained = true;
2550+
concreteParent = parentEquiv->superclass;
2551+
}
25462552
assert(concreteParent &&
25472553
"attempting to resolve concrete nested type of non-concrete PA");
25482554

@@ -2564,8 +2570,14 @@ static void concretizeNestedTypeFromConcreteParent(
25642570
"No conformance requirement");
25652571
const RequirementSource *parentConcreteSource = nullptr;
25662572
for (const auto &constraint : parentEquiv->conformsTo.find(proto)->second) {
2567-
if (constraint.source->kind == RequirementSource::Concrete) {
2568-
parentConcreteSource = constraint.source;
2573+
if (!isSuperclassConstrained) {
2574+
if (constraint.source->kind == RequirementSource::Concrete) {
2575+
parentConcreteSource = constraint.source;
2576+
}
2577+
} else {
2578+
if (constraint.source->kind == RequirementSource::Superclass) {
2579+
parentConcreteSource = constraint.source;
2580+
}
25692581
}
25702582
}
25712583

@@ -4299,6 +4311,15 @@ bool GenericSignatureBuilder::updateSuperclass(
42994311
for (const auto &conforms : equivClass->conformsTo) {
43004312
(void)resolveSuperConformance(type, conforms.first);
43014313
}
4314+
4315+
// Eagerly resolve any existing nested types to their concrete forms (others
4316+
// will be "concretized" as they are constructed, in getNestedType).
4317+
for (auto equivT : equivClass->members) {
4318+
for (auto nested : equivT->getNestedTypes()) {
4319+
concretizeNestedTypeFromConcreteParent(equivT, nested.second.front(),
4320+
*this);
4321+
}
4322+
}
43024323
};
43034324

43044325
// If we haven't yet recorded a superclass constraint for this equivalence
@@ -7188,6 +7209,12 @@ void GenericSignatureBuilder::dump(llvm::raw_ostream &out) {
71887209
pa->dump(out, &Context.SourceMgr, 2);
71897210
}
71907211
out << "\n";
7212+
7213+
out << "Equivalence classes:\n";
7214+
for (auto &equiv : Impl->EquivalenceClasses) {
7215+
equiv.dump(out, this);
7216+
}
7217+
out << "\n";
71917218
}
71927219

71937220
void GenericSignatureBuilder::addGenericSignature(GenericSignature sig) {

lib/AST/Type.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -3521,24 +3521,28 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
35213521

35223522
// Retrieve the type witness.
35233523
auto witness =
3524-
conformance.getConcrete()->getTypeWitness(assocType, options);
3525-
if (!witness || witness->hasError())
3524+
conformance.getConcrete()->getTypeWitnessAndDecl(assocType, options);
3525+
3526+
auto witnessTy = witness.getWitnessType();
3527+
if (!witnessTy || witnessTy->hasError())
35263528
return failed();
35273529

35283530
// This is a hacky feature allowing code completion to migrate to
35293531
// using Type::subst() without changing output.
35303532
if (options & SubstFlags::DesugarMemberTypes) {
3531-
if (auto *aliasType =
3532-
dyn_cast<TypeAliasType>(witness.getPointer())) {
3533-
if (!aliasType->is<ErrorType>())
3534-
witness = aliasType->getSinglyDesugaredType();
3535-
}
3533+
if (auto *aliasType = dyn_cast<TypeAliasType>(witnessTy.getPointer()))
3534+
witnessTy = aliasType->getSinglyDesugaredType();
3535+
3536+
// Another hack. If the type witness is a opaque result type. They can
3537+
// only be referred using the name of the associated type.
3538+
if (witnessTy->is<OpaqueTypeArchetypeType>())
3539+
witnessTy = witness.getWitnessDecl()->getDeclaredInterfaceType();
35363540
}
35373541

3538-
if (witness->is<ErrorType>())
3542+
if (witnessTy->is<ErrorType>())
35393543
return failed();
35403544

3541-
return witness;
3545+
return witnessTy;
35423546
}
35433547

35443548
return failed();

lib/Demangling/Demangler.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,14 @@ NodePointer Demangler::demangleTypeMangling() {
677677
return TypeMangling;
678678
}
679679

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

688690
// Map the encoded kind to a specific kind and directness.
@@ -734,7 +736,7 @@ NodePointer Demangler::demangleOperator() {
734736
goto recur;
735737
case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
736738
case 9: case 0xA: case 0xB: case 0xC:
737-
return demangleSymbolicReference((unsigned char)c, Text.data() + Pos);
739+
return demangleSymbolicReference((unsigned char)c);
738740
case 'A': return demangleMultiSubstitutions();
739741
case 'B': return demangleBuiltinType();
740742
case 'C': return demangleAnyGenericType(Node::Kind::Class);

lib/Frontend/ModuleInterfaceBuilder.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
163163
llvm::RestorePrettyStackState(savedInnerPrettyStackState);
164164
};
165165

166-
SubError = subASTDelegate.runInSubCompilerInstance(moduleName, interfacePath,
167-
OutPath, diagnosticLoc,
166+
SubError = subASTDelegate.runInSubCompilerInstance(moduleName,
167+
interfacePath,
168+
OutPath,
169+
diagnosticLoc,
168170
[&](SubCompilerInstanceInfo &info) {
169171
auto &SubInstance = *info.Instance;
170172
auto subInvocation = SubInstance.getInvocation();

0 commit comments

Comments
 (0)