Skip to content

Commit 9c53704

Browse files
committed
[ClangImporter] Add ImportHint::VAList instead of rederiving that info
We already know something's a va_list when we import it; no need to check again later.
1 parent 7ecf3dc commit 9c53704

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ namespace {
7575
/// 'Bool'.
7676
Boolean,
7777

78+
/// The source type is 'NSUInteger'.
79+
NSUInteger,
80+
81+
/// The source type is 'va_list'.
82+
VAList,
83+
7884
/// The source type is an Objective-C class type bridged to a Swift
7985
/// type.
8086
ObjCBridged,
8187

82-
/// The source type is 'NSUInteger'.
83-
NSUInteger,
84-
8588
/// The source type is an Objective-C object pointer type.
8689
ObjCPointer,
8790

@@ -139,6 +142,7 @@ namespace {
139142
case ImportHint::CFunctionPointer:
140143
case ImportHint::OtherPointer:
141144
case ImportHint::SwiftNewtypeFromCFPointer:
145+
case ImportHint::VAList:
142146
return true;
143147
}
144148

@@ -655,6 +659,7 @@ namespace {
655659
case ImportHint::CFunctionPointer:
656660
case ImportHint::OtherPointer:
657661
case ImportHint::SwiftNewtypeFromCFPointer:
662+
case ImportHint::VAList:
658663
return {mappedType, underlying.Hint};
659664

660665
case ImportHint::Boolean:
@@ -684,6 +689,10 @@ namespace {
684689
break;
685690
}
686691

692+
static const llvm::StringLiteral vaListNames[] = {
693+
"va_list", "__gnuc_va_list", "__va_list"
694+
};
695+
687696
ImportHint hint = ImportHint::None;
688697
if (type->getDecl()->getName() == "BOOL") {
689698
hint = ImportHint::Boolean;
@@ -692,6 +701,9 @@ namespace {
692701
hint = ImportHint::Boolean;
693702
} else if (type->getDecl()->getName() == "NSUInteger") {
694703
hint = ImportHint::NSUInteger;
704+
} else if (llvm::is_contained(vaListNames,
705+
type->getDecl()->getName())) {
706+
hint = ImportHint::VAList;
695707
} else if (isImportedCFPointer(type->desugar(), mappedType)) {
696708
hint = ImportHint::CFPointer;
697709
} else if (mappedType->isAnyExistentialType()) { // id, Class
@@ -770,8 +782,11 @@ namespace {
770782
ImportResult VisitDecayedType(const clang::DecayedType *type) {
771783
clang::ASTContext &clangCtx = Impl.getClangASTContext();
772784
if (clangCtx.hasSameType(type->getOriginalType(),
773-
clangCtx.getBuiltinVaListType()))
774-
return Impl.getNamedSwiftType(Impl.getStdlibModule(), "CVaListPointer");
785+
clangCtx.getBuiltinVaListType())) {
786+
return {Impl.getNamedSwiftType(Impl.getStdlibModule(),
787+
"CVaListPointer"),
788+
ImportHint::VAList};
789+
}
775790
return Visit(type->desugar());
776791
}
777792

@@ -1273,6 +1288,16 @@ static ImportedType adjustTypeForConcreteImport(
12731288
importedType = getUnmanagedType(impl, underlyingType);
12741289
}
12751290
break;
1291+
1292+
case ImportHint::VAList:
1293+
// Treat va_list specially: null-unspecified va_list parameters should be
1294+
// assumed to be non-optional. (Most people don't even think of va_list as a
1295+
// pointer, and it's not a portable assumption anyway.)
1296+
if (importKind == ImportTypeKind::Parameter &&
1297+
optKind == OTK_ImplicitlyUnwrappedOptional) {
1298+
optKind = OTK_None;
1299+
}
1300+
break;
12761301
}
12771302

12781303
// For anything else, if we completely failed to import the type
@@ -1382,19 +1407,6 @@ static ImportedType adjustTypeForConcreteImport(
13821407
importedType = getUnmanagedType(impl, importedType);
13831408
}
13841409

1385-
// Treat va_list specially: null-unspecified va_list parameters should be
1386-
// assumed to be non-optional. (Most people don't even think of va_list as a
1387-
// pointer, and it's not a portable assumption anyway.)
1388-
if (importKind == ImportTypeKind::Parameter &&
1389-
optKind == OTK_ImplicitlyUnwrappedOptional) {
1390-
if (auto *nominal = importedType->getNominalOrBoundGenericNominal()) {
1391-
if (nominal->getName().str() == "CVaListPointer" &&
1392-
nominal->getParentModule()->isStdlibModule()) {
1393-
optKind = OTK_None;
1394-
}
1395-
}
1396-
}
1397-
13981410
// Wrap class, class protocol, function, and metatype types in an
13991411
// optional type.
14001412
bool isIUO = false;

0 commit comments

Comments
 (0)