Skip to content

Commit d6bf34e

Browse files
[CSSimplify] Thin to thin is also allowed
1 parent baccbde commit d6bf34e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,15 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
13671367
if (!(last && last->is<LocatorPathElt::FunctionArgument>()))
13681368
return false;
13691369

1370+
auto isThin = [](FunctionTypeRepresentation rep) {
1371+
return rep == FunctionTypeRepresentation::CFunctionPointer ||
1372+
rep == FunctionTypeRepresentation::Thin;
1373+
};
1374+
1375+
// Allowing "thin" (c, thin) to "thin" conventions
1376+
if (isThin(rep1) && isThin(rep2))
1377+
return false;
1378+
13701379
// Allowing all to "thick" (swift, block) conventions
13711380
// "thin" (c, thin) to "thick" or "thick" to "thick"
13721381
if (rep2 == FunctionTypeRepresentation::Swift ||

validation-test/compiler_crashers_2_fixed/sr12723.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ func cContext() {
4242

4343
let _ : (@convention(c) () -> Void) -> Void = c.function // OK
4444

45-
let _ : (@convention(thin) () -> Void) -> Void = c.function
46-
// expected-error@-1 {{cannot convert value of type '(@convention(c) () -> Void) -> Void' to specified type '(@convention(thin) () -> Void) -> Void'}}
47-
45+
let _ : (@convention(thin) () -> Void) -> Void = c.function // OK
46+
4847
let _ : (() -> Void) -> Void = c.function
4948
// expected-error@-1 {{cannot convert value of type '(@convention(c) () -> Void) -> Void' to specified type '(() -> Void) -> Void'}}
5049

@@ -59,8 +58,7 @@ func thinContext() {
5958
let _ : (@convention(block) () -> Void) -> Void = thin.function
6059
// expected-error@-1 {{cannot convert value of type '(@convention(thin) () -> Void) -> Void' to specified type '(@convention(block) () -> Void) -> Void'}}
6160

62-
let _ : (@convention(c) () -> Void) -> Void = thin.function
63-
// expected-error@-1 {{cannot convert value of type '(@convention(thin) () -> Void) -> Void' to specified type '(@convention(c) () -> Void) -> Void'}}
61+
let _ : (@convention(c) () -> Void) -> Void = thin.function // OK
6462

6563
let _ : (@convention(thin) () -> Void) -> Void = thin.function // OK
6664

0 commit comments

Comments
 (0)