Skip to content

Commit f6f0d75

Browse files
authored
Merge pull request #81843 from slavapestov/hamish-fuzzer-fixes
Hamish fuzzer fixes
2 parents f979695 + a0e7cce commit f6f0d75

22 files changed

+92
-33
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7892,7 +7892,7 @@ ERROR(expected_macro_expansion_expr,PointsToFirstBadToken,
78927892
ERROR(expected_macro_expansion_decls,PointsToFirstBadToken,
78937893
"expected macro expansion to produce a declaration", ())
78947894
ERROR(macro_undefined,PointsToFirstBadToken,
7895-
"no macro named %0", (Identifier))
7895+
"no macro named %0", (DeclName))
78967896
ERROR(external_macro_not_found,none,
78977897
"external macro implementation type '%0.%1' could not be found for "
78987898
"macro %2; %3", (StringRef, StringRef, DeclName, StringRef))

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class ProtocolConformanceRef {
140140
}
141141

142142
AbstractConformance *getAbstract() const {
143+
ASSERT(isAbstract());
143144
return Union.get<AbstractConformance *>();
144145
}
145146

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ struct ASTContext::Implementation {
520520
llvm::DenseMap<const AbstractFunctionDecl *, SourceRange> OriginalBodySourceRanges;
521521

522522
/// Macro discriminators per context.
523-
llvm::DenseMap<std::pair<const void *, Identifier>, unsigned>
523+
llvm::DenseMap<std::pair<const void *, DeclBaseName>, unsigned>
524524
NextMacroDiscriminator;
525525

526526
/// Local and closure discriminators per context.
@@ -2286,8 +2286,8 @@ unsigned ASTContext::getNextMacroDiscriminator(
22862286
MacroDiscriminatorContext context,
22872287
DeclBaseName baseName
22882288
) {
2289-
std::pair<const void *, Identifier> key(
2290-
context.getOpaqueValue(), baseName.getIdentifier());
2289+
std::pair<const void *, DeclBaseName> key(
2290+
context.getOpaqueValue(), baseName);
22912291
return getImpl().NextMacroDiscriminator[key]++;
22922292
}
22932293

lib/AST/ASTDemangler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ Type ASTBuilder::createExistentialMetatypeType(
767767
Type ASTBuilder::createConstrainedExistentialType(
768768
Type base, ArrayRef<BuiltRequirement> constraints,
769769
ArrayRef<BuiltInverseRequirement> inverseRequirements) {
770-
llvm::SmallDenseMap<Identifier, Type> primaryAssociatedTypes;
771-
llvm::SmallDenseSet<Identifier> claimed;
770+
llvm::SmallDenseMap<AssociatedTypeDecl *, Type> primaryAssociatedTypes;
771+
llvm::SmallDenseSet<AssociatedTypeDecl *> claimed;
772772

773773
for (const auto &req : constraints) {
774774
switch (req.getKind()) {
@@ -782,7 +782,7 @@ Type ASTBuilder::createConstrainedExistentialType(
782782
if (auto *memberTy = req.getFirstType()->getAs<DependentMemberType>()) {
783783
if (memberTy->getBase()->is<GenericTypeParamType>()) {
784784
// This is the only case we understand so far.
785-
primaryAssociatedTypes[memberTy->getName()] = req.getSecondType();
785+
primaryAssociatedTypes[memberTy->getAssocType()] = req.getSecondType();
786786
continue;
787787
}
788788
}
@@ -799,7 +799,7 @@ Type ASTBuilder::createConstrainedExistentialType(
799799

800800
llvm::SmallVector<Type, 4> args;
801801
for (auto *assocTy : proto->getPrimaryAssociatedTypes()) {
802-
auto found = primaryAssociatedTypes.find(assocTy->getName());
802+
auto found = primaryAssociatedTypes.find(assocTy);
803803
if (found == primaryAssociatedTypes.end())
804804
return protoTy;
805805
args.push_back(found->second);

lib/Parse/Lexer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,8 @@ static bool advanceIfValidContinuationOfOperator(char const *&ptr,
660660

661661
/// Returns true if the given string is entirely whitespace (considering only
662662
/// those whitespace code points permitted in raw identifiers).
663-
static bool isEntirelyWhitespace(StringRef string) {
664-
if (string.empty()) return false;
663+
static bool isEscapedIdentifierEntirelyWhitespace(StringRef string) {
664+
if (string.empty()) return true;
665665
char const *p = string.data(), *end = string.end();
666666
if (!advanceIf(p, end, isPermittedRawIdentifierWhitespace))
667667
return false;
@@ -703,7 +703,7 @@ bool Lexer::isValidAsEscapedIdentifier(StringRef string) {
703703
;
704704
if (p != end)
705705
return false;
706-
return !isEntirelyWhitespace(string);
706+
return !isEscapedIdentifierEntirelyWhitespace(string);
707707
}
708708

709709
/// Determines if the given string is a valid operator identifier,
@@ -2315,7 +2315,8 @@ void Lexer::lexEscapedIdentifier() {
23152315
// If we have the terminating "`", it's an escaped/raw identifier, unless it
23162316
// contained only operator characters or was entirely whitespace.
23172317
StringRef IdStr(IdentifierStart, CurPtr - IdentifierStart);
2318-
if (*CurPtr == '`' && !isOperator(IdStr) && !isEntirelyWhitespace(IdStr)) {
2318+
if (*CurPtr == '`' && !isOperator(IdStr) &&
2319+
!isEscapedIdentifierEntirelyWhitespace(IdStr)) {
23192320
++CurPtr;
23202321
formEscapedIdentifierToken(Quote);
23212322
return;

lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
503503
peekToken().isContextualPunctuator("~")) &&
504504
!peekToken().isAtStartOfLine()) {
505505
ParserResult<TypeRepr> ty = parseType();
506+
if (ty.isNull())
507+
return nullptr;
508+
506509
auto *typeExpr = new (Context) TypeExpr(ty.get());
507510
return makeParserResult(typeExpr);
508511
}

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4068,8 +4068,8 @@ namespace {
40684068
}
40694069

40704070
/// Lookup all macros with the given macro name.
4071-
SmallVector<OverloadChoice, 1> lookupMacros(Identifier moduleName,
4072-
Identifier macroName,
4071+
SmallVector<OverloadChoice, 1> lookupMacros(DeclName moduleName,
4072+
DeclName macroName,
40734073
FunctionRefInfo functionRefInfo,
40744074
MacroRoles roles) {
40754075
SmallVector<OverloadChoice, 1> choices;
@@ -4100,8 +4100,8 @@ namespace {
41004100
CS.associateArgumentList(locator, expr->getArgs());
41014101

41024102
// Look up the macros with this name.
4103-
auto moduleIdent = expr->getModuleName().getBaseIdentifier();
4104-
auto macroIdent = expr->getMacroName().getBaseIdentifier();
4103+
auto moduleIdent = expr->getModuleName().getBaseName();
4104+
auto macroIdent = expr->getMacroName().getBaseName();
41054105
FunctionRefInfo functionRefInfo = FunctionRefInfo::singleBaseNameApply();
41064106
auto macros = lookupMacros(moduleIdent, macroIdent, functionRefInfo,
41074107
expr->getMacroRoles());

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7336,8 +7336,11 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
73367336
// would be handled by existental promotion in cases where it's allowed.
73377337
if (isTupleWithUnresolvedPackExpansion(origType1) ||
73387338
isTupleWithUnresolvedPackExpansion(origType2)) {
7339-
if (desugar1->is<TupleType>() != desugar2->is<TupleType>() &&
7340-
(!desugar1->isAny() && !desugar2->isAny())) {
7339+
if (isa<TupleType>(desugar1) != isa<TupleType>(desugar2) &&
7340+
!isa<InOutType>(desugar1) &&
7341+
!isa<InOutType>(desugar2) &&
7342+
!desugar1->isAny() &&
7343+
!desugar2->isAny()) {
73417344
return matchTypes(
73427345
desugar1->is<TupleType>() ? type1
73437346
: TupleType::get({type1}, getASTContext()),

lib/Sema/TypeCheckDecl.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,13 +2248,20 @@ ParamSpecifierRequest::evaluate(Evaluator &evaluator,
22482248

22492249
auto typeRepr = param->getTypeRepr();
22502250

2251-
if (!typeRepr && !param->isImplicit()) {
2252-
// Untyped closure parameter.
2253-
return ParamSpecifier::Default;
2254-
}
2251+
if (!typeRepr) {
2252+
if (!param->isImplicit()) {
2253+
// Untyped closure parameter.
2254+
return ParamSpecifier::Default;
2255+
}
22552256

2256-
assert(typeRepr != nullptr && "Should call setSpecifier() on "
2257-
"synthesized parameter declarations");
2257+
if (param->isInvalid()) {
2258+
// Invalid parse.
2259+
return ParamSpecifier::Default;
2260+
}
2261+
2262+
ASSERT(false && "Should call setSpecifier() on "
2263+
"synthesized parameter declarations");
2264+
}
22582265

22592266
// Look through top-level pack expansions. These specifiers are
22602267
// part of what's repeated.

lib/Sema/TypeCheckEffects.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,8 @@ class ApplyClassifier {
16851685
const bool hasAnyConformances =
16861686
llvm::any_of(substitutions.getConformances(),
16871687
[](const ProtocolConformanceRef conformance) {
1688+
if (conformance.isInvalid())
1689+
return false;
16881690
auto *requirement = conformance.getProtocol();
16891691
return !requirement->getInvertibleProtocolKind();
16901692
});

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ convertToUnqualifiedLookupOptions(NameLookupOptions options) {
266266
static void synthesizeCodingKeysIfNeededForUnqualifiedLookup(ASTContext &ctx,
267267
DeclContext *dc,
268268
DeclNameRef name) {
269-
if (name.getBaseIdentifier() != ctx.Id_CodingKeys)
269+
if (!name.isSimpleName(ctx.Id_CodingKeys))
270270
return;
271271

272272
for (auto typeCtx = dc->getInnermostTypeContext(); typeCtx != nullptr;

lib/Sema/TypeCheckPattern.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ static DeclRefTypeRepr *translateExprToDeclRefTypeRepr(Expr *E, ASTContext &C) {
221221
}
222222

223223
DeclRefTypeRepr *visitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *udre) {
224+
if (!udre->getName().isSimpleName() ||
225+
udre->getName().isOperator() ||
226+
udre->getName().isSpecial())
227+
return nullptr;
228+
224229
return UnqualifiedIdentTypeRepr::create(C, udre->getNameLoc(),
225230
udre->getName());
226231
}

test/DebugInfo/parameterized_existential_composition.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
// RUN: %target-swift-frontend -emit-ir %s -g -target %target-swift-5.9-abi-triple
22

3+
// Note: The goal of this test is to exercise the mangling/demangling via
4+
// the -g flag.
5+
36
public protocol P<A, B> {
47
associatedtype A
58
associatedtype B
69
}
710

11+
public protocol P1<A> {
12+
associatedtype A
13+
}
14+
815
public protocol Q<C> {
916
associatedtype C
1017
}
@@ -31,6 +38,30 @@ public func foo(_ a: (any P<Int, Float> & Q<String> & R).Type) {}
3138
public func foo(_ a: (any P<Int, Float> & Q<String> & R & C<Bool>).Type) {}
3239
public func foo(_ a: (any P<Int, Float> & Q<String> & R & AnyObject).Type) {}
3340

41+
public func foo(_ a: (any P & P1).Type) {}
42+
public func foo(_ a: (any P & P1<String>).Type) {}
43+
public func foo(_ a: (any P & P1<String> & R).Type) {}
44+
public func foo(_ a: (any P & P1<String> & R & C<Bool>).Type) {}
45+
public func foo(_ a: (any P & P1<String> & R & AnyObject).Type) {}
46+
47+
public func foo(_ a: (any P<Int, Float> & P1).Type) {}
48+
public func foo(_ a: (any P<Int, Float> & P1 & R).Type) {}
49+
public func foo(_ a: (any P<Int, Float> & P1 & R & C<Bool>).Type) {}
50+
public func foo(_ a: (any P<Int, Float> & P1 & R & AnyObject).Type) {}
51+
52+
public protocol Q2<C>: Q {}
53+
54+
public protocol Q3<C>: Q {
55+
associatedtype C
56+
}
57+
58+
public func foo(_ a: (any Q2<Int> & R).Type) {}
59+
public func foo(_ a: (any Q3<Int> & R).Type) {}
60+
public func foo(_ a: (any Q2 & Q3).Type) {}
61+
public func foo(_ a: (any Q2 & Q3<Int>).Type) {}
62+
public func foo2(_ a: (any Q2<Int> & Q3).Type) {}
63+
public func foo3(_ a: (any Q2<Int> & Q3<Int>).Type) {}
64+
3465
public struct Foo<each T, U> {
3566
public var a1: (repeat any P<each T, U> & R)
3667
}

test/decl/ext/specialize.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ class State {
8686
extension Test.Key<State> {
8787
static let state = Self<State>()
8888
}
89+
90+
protocol P {}
91+
struct S: P {}
92+
93+
extension Sequence<any P> where Self == [S] {}
94+
// expected-error@-1 {{generic signature requires types 'S' and 'any P' to be the same}}

validation-test/compiler_crashers_2/1470917329979c9a.swift renamed to validation-test/compiler_crashers_2_fixed/1470917329979c9a.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"signature":"swift::PackExpansionType::PackExpansionType(swift::Type, swift::Type, swift::RecursiveTypeProperties, swift::ASTContext const*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
struct a < each b {
44
struct c {
55
d : (repeat(each b
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// {"signature":"(anonymous namespace)::ABIDependencyEvaluator::computeABIDependenciesForModule(swift::ModuleDecl*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
switch {
44
case init
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"swift::Lexer::formEscapedIdentifierToken(char const*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
``
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"swift::DeclRefTypeRepr::overwriteNameRef(swift::DeclNameRef)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
switch { case init(

validation-test/compiler_crashers_2/59b42964e169b6fa.swift renamed to validation-test/compiler_crashers_2_fixed/59b42964e169b6fa.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"signature":"swift::ProtocolConformanceRef::getProtocol() const"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
func a<each b {
44
enum c {
55
case struct var d: e struct e {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"swift::DeclAndTypePrinter::Implementation::visitVarDecl(swift::VarDecl*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
#init
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"swift::ParamSpecifierRequest::evaluate(swift::Evaluator&, swift::ParamDecl*) const"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
func a([0])
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"swift::Parser::parseExprSequenceElement(swift::Diag<>, bool)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
any a <

0 commit comments

Comments
 (0)