Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8678,7 +8678,7 @@ class SwiftifyInfoPrinter {
~SwiftifyInfoPrinter() { out << ")"; }

void printCountedBy(const clang::CountAttributedType *CAT,
size_t pointerIndex) {
ssize_t pointerIndex) {
printSeparator();
clang::Expr *countExpr = CAT->getCountExpr();
bool isSizedBy = CAT->isCountInBytes();
Expand All @@ -8687,7 +8687,9 @@ class SwiftifyInfoPrinter {
out << "sizedBy";
else
out << "countedBy";
out << "(pointer: " << pointerIndex + 1 << ", ";
out << "(pointer: ";
printParamOrReturn(pointerIndex);
out << ", ";
if (isSizedBy)
out << "size";
else
Expand All @@ -8700,7 +8702,9 @@ class SwiftifyInfoPrinter {

void printNonEscaping(int idx) {
printSeparator();
out << ".nonescaping(pointer: " << idx << ")";
out << ".nonescaping(pointer: ";
printParamOrReturn(idx);
out << ")";
}

void printTypeMapping(const llvm::StringMap<std::string> &mapping) {
Expand All @@ -8724,6 +8728,13 @@ class SwiftifyInfoPrinter {
firstParam = false;
}
}

void printParamOrReturn(ssize_t pointerIndex) {
if (pointerIndex == -1)
out << ".return";
else
out << ".param(" << pointerIndex + 1 << ")";
}
};
} // namespace

Expand All @@ -8750,7 +8761,7 @@ void ClangImporter::Implementation::importSpanAttributes(FuncDecl *MappedDecl) {
if (decl->getName() != "span")
continue;
if (param->hasAttr<clang::NoEscapeAttr>()) {
printer.printNonEscaping(index + 1);
printer.printNonEscaping(index);
clang::PrintingPolicy policy(param->getASTContext().getLangOpts());
policy.SuppressTagKeyword = true;
auto param = MappedDecl->getParameters()->get(index);
Expand Down Expand Up @@ -8787,6 +8798,10 @@ void ClangImporter::Implementation::importBoundsAttributes(
printer.printCountedBy(CAT, index);
}
}
if (auto CAT =
ClangDecl->getReturnType()->getAs<clang::CountAttributedType>()) {
printer.printCountedBy(CAT, -1);
}
}

importNontrivialAttribute(MappedDecl, MacroString);
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
: ImportTypeKind::Result),
ImportDiagnosticAdder(*this, clangDecl, clangDecl->getLocation()),
allowNSUIntegerAsInt, Bridgeability::Full, getImportTypeAttrs(clangDecl),
OptionalityOfReturn, isBoundsAnnotated);
OptionalityOfReturn, true, std::nullopt, isBoundsAnnotated);
}

static Type
Expand Down
Loading