Skip to content

isCanonical should take the Clang function type into account only if UseClangFunctionTypes is enabled. #28580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3008,8 +3008,12 @@ FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
void *mem = ctx.Allocate(allocSize, alignof(FunctionType), arena);

bool isCanonical = isFunctionTypeCanonical(params, result);
if (uncommon.hasValue())
isCanonical &= uncommon->ClangFunctionType->isCanonicalUnqualified();
if (uncommon.hasValue()) {
if (ctx.LangOpts.UseClangFunctionTypes)
isCanonical &= uncommon->ClangFunctionType->isCanonicalUnqualified();
else
isCanonical = false;
}

auto funcTy = new (mem) FunctionType(params, result, info,
isCanonical ? &ctx : nullptr,
Expand Down
35 changes: 32 additions & 3 deletions test/Sema/clang_types_in_ast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH2 -sdk %clang-importer-sdk -use-clang-function-types
// RUN: %target-swift-frontend %s -DAUXMODULE -module-name Foo -emit-module -o %t

// rdar://problem/57644243 : We shouldn't crash if -use-clang-function-types is not enabled.
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH3 -I %t

// FIXME: [clang-function-type-serialization] This should stop crashing once we
// start serializing clang function types.
// RUN: not --crash %target-swift-frontend %s -typecheck -DCRASH -I %t -use-clang-function-types
Expand All @@ -25,12 +28,38 @@ func f() {
#endif

#if AUXMODULE
public var DUMMY_SIGNAL : Optional<@convention(c) (Int32) -> Void> = .none
public var DUMMY_SIGNAL1 : Optional<@convention(c) (Int32) -> ()> = .none
public var DUMMY_SIGNAL2 : Optional<@convention(c) (Int32) -> Void> = .none
#endif

#if NOCRASH3
import Foo
public func my_signal1() -> Optional<@convention(c) (Int32) -> ()> {
return Foo.DUMMY_SIGNAL1
}
public func my_signal2() -> Optional<@convention(c) (Int32) -> Void> {
return Foo.DUMMY_SIGNAL1
}
public func my_signal3() -> Optional<@convention(c) (Int32) -> ()> {
return Foo.DUMMY_SIGNAL2
}
public func my_signal4() -> Optional<@convention(c) (Int32) -> Void> {
return Foo.DUMMY_SIGNAL2
}
#endif

#if CRASH
import Foo
public func my_signal() -> Optional<@convention(c) (Int32) -> Void> {
return Foo.DUMMY_SIGNAL
public func my_signal1() -> Optional<@convention(c) (Int32) -> ()> {
return Foo.DUMMY_SIGNAL1
}
public func my_signal2() -> Optional<@convention(c) (Int32) -> Void> {
return Foo.DUMMY_SIGNAL1
}
public func my_signal3() -> Optional<@convention(c) (Int32) -> ()> {
return Foo.DUMMY_SIGNAL2
}
public func my_signal4() -> Optional<@convention(c) (Int32) -> Void> {
return Foo.DUMMY_SIGNAL2
}
#endif