Skip to content

Commit 50fef73

Browse files
authored
Merge pull request #28580 from varungandhi-apple/vg-fix-borked-isCanonical-calc
isCanonical should take the Clang function type into account only if UseClangFunctionTypes is enabled.
2 parents a526cb0 + 9d83b7d commit 50fef73

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,8 +3008,12 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
30083008
void *mem = ctx.Allocate(allocSize, alignof(FunctionType), arena);
30093009

30103010
bool isCanonical = isFunctionTypeCanonical(params, result);
3011-
if (uncommon.hasValue())
3012-
isCanonical &= uncommon->ClangFunctionType->isCanonicalUnqualified();
3011+
if (uncommon.hasValue()) {
3012+
if (ctx.LangOpts.UseClangFunctionTypes)
3013+
isCanonical &= uncommon->ClangFunctionType->isCanonicalUnqualified();
3014+
else
3015+
isCanonical = false;
3016+
}
30133017

30143018
auto funcTy = new (mem) FunctionType(params, result, info,
30153019
isCanonical ? &ctx : nullptr,

test/Sema/clang_types_in_ast.swift

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH2 -sdk %clang-importer-sdk -use-clang-function-types
66
// RUN: %target-swift-frontend %s -DAUXMODULE -module-name Foo -emit-module -o %t
77

8+
// rdar://problem/57644243 : We shouldn't crash if -use-clang-function-types is not enabled.
9+
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH3 -I %t
10+
811
// FIXME: [clang-function-type-serialization] This should stop crashing once we
912
// start serializing clang function types.
1013
// RUN: not --crash %target-swift-frontend %s -typecheck -DCRASH -I %t -use-clang-function-types
@@ -25,12 +28,38 @@ func f() {
2528
#endif
2629

2730
#if AUXMODULE
28-
public var DUMMY_SIGNAL : Optional<@convention(c) (Int32) -> Void> = .none
31+
public var DUMMY_SIGNAL1 : Optional<@convention(c) (Int32) -> ()> = .none
32+
public var DUMMY_SIGNAL2 : Optional<@convention(c) (Int32) -> Void> = .none
33+
#endif
34+
35+
#if NOCRASH3
36+
import Foo
37+
public func my_signal1() -> Optional<@convention(c) (Int32) -> ()> {
38+
return Foo.DUMMY_SIGNAL1
39+
}
40+
public func my_signal2() -> Optional<@convention(c) (Int32) -> Void> {
41+
return Foo.DUMMY_SIGNAL1
42+
}
43+
public func my_signal3() -> Optional<@convention(c) (Int32) -> ()> {
44+
return Foo.DUMMY_SIGNAL2
45+
}
46+
public func my_signal4() -> Optional<@convention(c) (Int32) -> Void> {
47+
return Foo.DUMMY_SIGNAL2
48+
}
2949
#endif
3050

3151
#if CRASH
3252
import Foo
33-
public func my_signal() -> Optional<@convention(c) (Int32) -> Void> {
34-
return Foo.DUMMY_SIGNAL
53+
public func my_signal1() -> Optional<@convention(c) (Int32) -> ()> {
54+
return Foo.DUMMY_SIGNAL1
55+
}
56+
public func my_signal2() -> Optional<@convention(c) (Int32) -> Void> {
57+
return Foo.DUMMY_SIGNAL1
58+
}
59+
public func my_signal3() -> Optional<@convention(c) (Int32) -> ()> {
60+
return Foo.DUMMY_SIGNAL2
61+
}
62+
public func my_signal4() -> Optional<@convention(c) (Int32) -> Void> {
63+
return Foo.DUMMY_SIGNAL2
3564
}
3665
#endif

0 commit comments

Comments
 (0)