Skip to content

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

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
Mar 28, 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 @@ -221,6 +221,7 @@ APINotesManager::getCurrentModuleAPINotes(Module *M, bool LookInModule,
ArrayRef<std::string> SearchPaths) {
FileManager &FM = SM.getFileManager();
auto ModuleName = M->getTopLevelModuleName();
auto ExportedModuleName = M->getTopLevelModule()->ExportAsModule;
llvm::SmallVector<FileEntryRef, 2> APINotes;

// First, look relative to the module itself.
Expand All @@ -233,6 +234,10 @@ APINotesManager::getCurrentModuleAPINotes(Module *M, bool LookInModule,

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 (M->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"