Skip to content

Commit abc42b4

Browse files
committed
[Clang importer] Allow a CF type spelled with "void *".
There wasn't any justification for the "const" restriction. Fixes rdar://problem/24821660.
1 parent 381a12d commit abc42b4

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

lib/ClangImporter/CFTypeInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ CFPointeeInfo::classifyTypedef(const clang::TypedefNameDecl *typedefDecl) {
8989
isWhitelistedCFTypeName(typedefDecl->getName())) {
9090
return forRecord(isConst, record->getDecl());
9191
}
92-
} else if (isConst && pointee->isVoidType()) {
92+
} else if (pointee->isVoidType()) {
9393
if (typedefDecl->hasAttr<clang::ObjCBridgeAttr>() ||
9494
isWhitelistedCFTypeName(typedefDecl->getName())) {
95-
return forConstVoid();
95+
return isConst ? forConstVoid() : forVoid();
9696
}
9797
}
9898
}

lib/ClangImporter/CFTypeInfo.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ class CFPointeeInfo {
5959
return info;
6060
}
6161

62+
static CFPointeeInfo forVoid() {
63+
CFPointeeInfo info;
64+
info.IsValid = true;
65+
info.IsConst = false;
66+
info.Decl = nullptr;
67+
return info;
68+
}
69+
6270
static CFPointeeInfo forInvalid() {
6371
CFPointeeInfo info;
6472
info.IsValid = false;
@@ -73,7 +81,7 @@ class CFPointeeInfo {
7381

7482
bool isConst() const { return IsConst; }
7583

76-
bool isConstVoid() const {
84+
bool isVoid() const {
7785
assert(isValid());
7886
return Decl.isNull();
7987
}

lib/ClangImporter/IAMInference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ class IAMInference {
472472
typedefType->getDecl()->getCanonicalDecl())) {
473473
if (pointeeInfo.isRecord() || pointeeInfo.isTypedef())
474474
return {typedefType->getDecl()->getCanonicalDecl()};
475-
assert(pointeeInfo.isConstVoid() && "no other type");
475+
assert(pointeeInfo.isVoid() && "no other type");
476476
return {};
477477
}
478478
qt = qt.getSingleStepDesugaredType(clangSema.getASTContext());

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,9 +1550,9 @@ namespace {
15501550
return typealias;
15511551
}
15521552

1553-
// If the pointee is 'const void', 'CFTypeRef', bring it
1553+
// If the pointee is 'void', 'CFTypeRef', bring it
15541554
// in specifically as AnyObject.
1555-
if (pointee.isConstVoid()) {
1555+
if (pointee.isVoid()) {
15561556
auto proto = Impl.SwiftContext.getProtocol(
15571557
KnownProtocolKind::AnyObject);
15581558
if (!proto)

test/ClangModules/Inputs/custom-modules/CoreCooling.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ void CCRefrigeratorCreateIndirect(CCRefrigeratorRef * __nullable __attribute__((
4848
// Note that the fridge parameter is incorrectly annotated.
4949
void CCRefrigeratorGetPowerSupplyIndirect(CCRefrigeratorRef __attribute__((cf_returns_not_retained)) fridge, CCPowerSupplyRef * __nonnull __attribute__((cf_returns_not_retained)) outPower);
5050
void CCRefrigeratorGetItemUnaudited(CCRefrigeratorRef fridge, unsigned index, CCItemRef *outItem);
51+
52+
typedef void *CFNonConstVoidRef __attribute__((objc_bridge(id)));
53+
CFNonConstVoidRef CFNonConstBottom();

test/ClangModules/cf.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,8 @@ func nameCollisions() {
144144
np = np2
145145
np2 = np
146146
}
147+
148+
func testNonConstVoid() {
149+
let value: Unmanaged<CFNonConstVoidRef> = CFNonConstBottom()!
150+
assertUnmanaged(value)
151+
}

0 commit comments

Comments
 (0)