Skip to content

🍒[APINotes] For a re-exported module, look for APINotes in the re-exporting module's apinotes file #8067

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
Jan 27, 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
5 changes: 5 additions & 0 deletions clang/lib/APINotes/APINotesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ llvm::SmallVector<const FileEntry *, 2> APINotesManager::getCurrentModuleAPINote
Module *module, bool lookInModule, ArrayRef<std::string> searchPaths) {
FileManager &fileMgr = SourceMgr.getFileManager();
auto moduleName = module->getTopLevelModuleName();
auto ExportedModuleName = module->getTopLevelModule()->ExportAsModule;
llvm::SmallVector<const FileEntry *, 2> APINotes;

// First, look relative to the module itself.
Expand All @@ -263,6 +264,10 @@ llvm::SmallVector<const FileEntry *, 2> APINotesManager::getCurrentModuleAPINote

APINotes.push_back(file);
}
// If module FooCore is re-exported through module Foo, try Foo.apinotes.
if (!ExportedModuleName.empty())
if (auto File = findAPINotesFile(dir, ExportedModuleName, wantPublic))
APINotes.push_back(File);
};

if (module->IsFramework) {
Expand Down
5 changes: 5 additions & 0 deletions clang/test/APINotes/Inputs/Headers/ExportAs.apinotes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name: ExportAs
Globals:
- Name: globalInt
Availability: none
AvailabilityMsg: "oh no"
1 change: 1 addition & 0 deletions clang/test/APINotes/Inputs/Headers/ExportAs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "ExportAsCore.h"
1 change: 1 addition & 0 deletions clang/test/APINotes/Inputs/Headers/ExportAsCore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static int globalInt = 123;
10 changes: 10 additions & 0 deletions clang/test/APINotes/Inputs/Headers/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ module ExternCtx {
header "ExternCtx.h"
}

module ExportAsCore {
header "ExportAsCore.h"
export_as ExportAs
}

module ExportAs {
header "ExportAs.h"
export *
}

module HeaderLib {
header "HeaderLib.h"
}
Expand Down
8 changes: 8 additions & 0 deletions clang/test/APINotes/export-as.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers %s -ast-dump -ast-dump-filter globalInt -x c | FileCheck %s

#include "ExportAs.h"

// CHECK: Dumping globalInt:
// CHECK: VarDecl {{.+}} imported in ExportAsCore globalInt 'int'
// CHECK: UnavailableAttr {{.+}} <<invalid sloc>> "oh no"