Skip to content

ClangImporter: support SDK for APINotes #75635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
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
22 changes: 18 additions & 4 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,24 @@ void importer::getNormalInvocationArguments(
invocationArgStrs.push_back("-fapinotes-modules");
invocationArgStrs.push_back("-fapinotes-swift-version=" +
languageVersion.asAPINotesVersionString());
invocationArgStrs.push_back("-iapinotes-modules");
invocationArgStrs.push_back((llvm::Twine(searchPathOpts.RuntimeResourcePath) +
llvm::sys::path::get_separator() +
"apinotes").str());

// Prefer `-sdk` paths.
if (!searchPathOpts.getSDKPath().empty()) {
llvm::SmallString<261> path{searchPathOpts.getSDKPath()};
llvm::sys::path::append(path, "usr", "lib", "swift", "apinotes");

invocationArgStrs.push_back("-iapinotes-modules");
invocationArgStrs.push_back(path.str().str());
}

// Fallback to "legacy" `-resource-dir` paths.
{
llvm::SmallString<261> path{searchPathOpts.RuntimeResourcePath};
llvm::sys::path::append(path, "apinotes");

invocationArgStrs.push_back("-iapinotes-modules");
invocationArgStrs.push_back(path.str().str());
}
}

static void
Expand Down
6 changes: 6 additions & 0 deletions test/ClangImporter/sdk-apinotes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s -verify

import cfuncs

let array: [UnsafePointer<CChar>?] = [nil]
array.withUnsafeBufferPointer { nullability_note($0.baseAddress!) }
2 changes: 2 additions & 0 deletions test/Inputs/clang-importer-sdk/usr/include/cfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ void opaque_pointer_param(struct not_importable *);

int unsupported_parameter_type(int param1, _Complex int param2);
_Complex int unsupported_return_type();

void nullability_note(const char * _Nonnull const * _Nonnull parameter);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Name: cfuncs
Functions:
- Name: nullability_note
Parameters:
- Position: 0
Type: "const char * _Nullable const * _Nonnull"