Skip to content

Commit

Permalink
Merge pull request swiftlang#34102 from varungandhi-apple/vg-gate-cla…
Browse files Browse the repository at this point in the history
…ng-type-serde

[Serialization] Gate Clang type (de)serialization behind UseClangFunctionTypes
  • Loading branch information
varungandhi-apple committed Sep 29, 2020
2 parents 0756c40 + 88e2562 commit 3016a89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
3 changes: 3 additions & 0 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5799,6 +5799,9 @@ class SwiftToClangBasicReader :

llvm::Expected<const clang::Type *>
ModuleFile::getClangType(ClangTypeID TID) {
if (!getContext().LangOpts.UseClangFunctionTypes)
return nullptr;

if (TID == 0)
return nullptr;

Expand Down
5 changes: 4 additions & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4140,7 +4140,10 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
using namespace decls_block;

auto resultType = S.addTypeRef(fnTy->getResult());
auto clangType = S.addClangTypeRef(fnTy->getClangTypeInfo().getType());
auto clangType =
S.getASTContext().LangOpts.UseClangFunctionTypes
? S.addClangTypeRef(fnTy->getClangTypeInfo().getType())
: ClangTypeID(0);

unsigned abbrCode = S.DeclTypeAbbrCodes[FunctionTypeLayout::Code];
FunctionTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
Expand Down
22 changes: 4 additions & 18 deletions test/Sema/clang_types_in_ast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH1 -use-clang-function-types
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH2 -sdk %clang-importer-sdk
// 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 -DAUXMODULE -module-name Foo -emit-module -o %t
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH3 -I %t

// RUN: %target-swift-frontend %s -typecheck -DCRASH -I %t -use-clang-function-types
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -DAUXMODULE -module-name Foo -emit-module -o %t -use-clang-function-types
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH3 -I %t -use-clang-function-types

#if NOCRASH1
public func my_signal() -> Optional<@convention(c) (Int32) -> Void> {
Expand Down Expand Up @@ -45,19 +47,3 @@ public func my_signal4() -> Optional<@convention(c) (Int32) -> Void> {
return Foo.DUMMY_SIGNAL2
}
#endif

#if CRASH
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

0 comments on commit 3016a89

Please sign in to comment.