@@ -75,13 +75,16 @@ namespace {
75
75
// / 'Bool'.
76
76
Boolean,
77
77
78
+ // / The source type is 'NSUInteger'.
79
+ NSUInteger,
80
+
81
+ // / The source type is 'va_list'.
82
+ VAList,
83
+
78
84
// / The source type is an Objective-C class type bridged to a Swift
79
85
// / type.
80
86
ObjCBridged,
81
87
82
- // / The source type is 'NSUInteger'.
83
- NSUInteger,
84
-
85
88
// / The source type is an Objective-C object pointer type.
86
89
ObjCPointer,
87
90
@@ -139,6 +142,7 @@ namespace {
139
142
case ImportHint::CFunctionPointer:
140
143
case ImportHint::OtherPointer:
141
144
case ImportHint::SwiftNewtypeFromCFPointer:
145
+ case ImportHint::VAList:
142
146
return true ;
143
147
}
144
148
@@ -655,6 +659,7 @@ namespace {
655
659
case ImportHint::CFunctionPointer:
656
660
case ImportHint::OtherPointer:
657
661
case ImportHint::SwiftNewtypeFromCFPointer:
662
+ case ImportHint::VAList:
658
663
return {mappedType, underlying.Hint };
659
664
660
665
case ImportHint::Boolean:
@@ -684,6 +689,10 @@ namespace {
684
689
break ;
685
690
}
686
691
692
+ static const llvm::StringLiteral vaListNames[] = {
693
+ " va_list" , " __gnuc_va_list" , " __va_list"
694
+ };
695
+
687
696
ImportHint hint = ImportHint::None;
688
697
if (type->getDecl ()->getName () == " BOOL" ) {
689
698
hint = ImportHint::Boolean;
@@ -692,6 +701,9 @@ namespace {
692
701
hint = ImportHint::Boolean;
693
702
} else if (type->getDecl ()->getName () == " NSUInteger" ) {
694
703
hint = ImportHint::NSUInteger;
704
+ } else if (llvm::is_contained (vaListNames,
705
+ type->getDecl ()->getName ())) {
706
+ hint = ImportHint::VAList;
695
707
} else if (isImportedCFPointer (type->desugar (), mappedType)) {
696
708
hint = ImportHint::CFPointer;
697
709
} else if (mappedType->isAnyExistentialType ()) { // id, Class
@@ -770,8 +782,11 @@ namespace {
770
782
ImportResult VisitDecayedType (const clang::DecayedType *type) {
771
783
clang::ASTContext &clangCtx = Impl.getClangASTContext ();
772
784
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
+ }
775
790
return Visit (type->desugar ());
776
791
}
777
792
@@ -1273,6 +1288,16 @@ static ImportedType adjustTypeForConcreteImport(
1273
1288
importedType = getUnmanagedType (impl, underlyingType);
1274
1289
}
1275
1290
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 ;
1276
1301
}
1277
1302
1278
1303
// For anything else, if we completely failed to import the type
@@ -1382,19 +1407,6 @@ static ImportedType adjustTypeForConcreteImport(
1382
1407
importedType = getUnmanagedType (impl, importedType);
1383
1408
}
1384
1409
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
-
1398
1410
// Wrap class, class protocol, function, and metatype types in an
1399
1411
// optional type.
1400
1412
bool isIUO = false ;
0 commit comments