Skip to content

Commit 3016a89

Browse files
Merge pull request #34102 from varungandhi-apple/vg-gate-clang-type-serde
[Serialization] Gate Clang type (de)serialization behind UseClangFunctionTypes
2 parents 0756c40 + 88e2562 commit 3016a89

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5799,6 +5799,9 @@ class SwiftToClangBasicReader :
57995799

58005800
llvm::Expected<const clang::Type *>
58015801
ModuleFile::getClangType(ClangTypeID TID) {
5802+
if (!getContext().LangOpts.UseClangFunctionTypes)
5803+
return nullptr;
5804+
58025805
if (TID == 0)
58035806
return nullptr;
58045807

lib/Serialization/Serialization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4140,7 +4140,10 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
41404140
using namespace decls_block;
41414141

41424142
auto resultType = S.addTypeRef(fnTy->getResult());
4143-
auto clangType = S.addClangTypeRef(fnTy->getClangTypeInfo().getType());
4143+
auto clangType =
4144+
S.getASTContext().LangOpts.UseClangFunctionTypes
4145+
? S.addClangTypeRef(fnTy->getClangTypeInfo().getType())
4146+
: ClangTypeID(0);
41444147

41454148
unsigned abbrCode = S.DeclTypeAbbrCodes[FunctionTypeLayout::Code];
41464149
FunctionTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,

test/Sema/clang_types_in_ast.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH1 -use-clang-function-types
44
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH2 -sdk %clang-importer-sdk
55
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH2 -sdk %clang-importer-sdk -use-clang-function-types
6-
// RUN: %target-swift-frontend %s -DAUXMODULE -module-name Foo -emit-module -o %t
76

87
// rdar://problem/57644243 : We shouldn't crash if -use-clang-function-types is not enabled.
8+
// RUN: %target-swift-frontend %s -DAUXMODULE -module-name Foo -emit-module -o %t
99
// RUN: %target-swift-frontend %s -typecheck -DNOCRASH3 -I %t
1010

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

1315
#if NOCRASH1
1416
public func my_signal() -> Optional<@convention(c) (Int32) -> Void> {
@@ -45,19 +47,3 @@ public func my_signal4() -> Optional<@convention(c) (Int32) -> Void> {
4547
return Foo.DUMMY_SIGNAL2
4648
}
4749
#endif
48-
49-
#if CRASH
50-
import Foo
51-
public func my_signal1() -> Optional<@convention(c) (Int32) -> ()> {
52-
return Foo.DUMMY_SIGNAL1
53-
}
54-
public func my_signal2() -> Optional<@convention(c) (Int32) -> Void> {
55-
return Foo.DUMMY_SIGNAL1
56-
}
57-
public func my_signal3() -> Optional<@convention(c) (Int32) -> ()> {
58-
return Foo.DUMMY_SIGNAL2
59-
}
60-
public func my_signal4() -> Optional<@convention(c) (Int32) -> Void> {
61-
return Foo.DUMMY_SIGNAL2
62-
}
63-
#endif

0 commit comments

Comments
 (0)