Skip to content

Commit 9bb8aee

Browse files
authored
Merge pull request #8067 from apple/egorzhdan/apinotes-export-as-20230725
🍒[APINotes] For a re-exported module, look for APINotes in the re-exporting module's apinotes file
2 parents 03c61e6 + c54ec99 commit 9bb8aee

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

clang/lib/APINotes/APINotesManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ llvm::SmallVector<const FileEntry *, 2> APINotesManager::getCurrentModuleAPINote
251251
Module *module, bool lookInModule, ArrayRef<std::string> searchPaths) {
252252
FileManager &fileMgr = SourceMgr.getFileManager();
253253
auto moduleName = module->getTopLevelModuleName();
254+
auto ExportedModuleName = module->getTopLevelModule()->ExportAsModule;
254255
llvm::SmallVector<const FileEntry *, 2> APINotes;
255256

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

264265
APINotes.push_back(file);
265266
}
267+
// If module FooCore is re-exported through module Foo, try Foo.apinotes.
268+
if (!ExportedModuleName.empty())
269+
if (auto File = findAPINotesFile(dir, ExportedModuleName, wantPublic))
270+
APINotes.push_back(File);
266271
};
267272

268273
if (module->IsFramework) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Name: ExportAs
2+
Globals:
3+
- Name: globalInt
4+
Availability: none
5+
AvailabilityMsg: "oh no"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "ExportAsCore.h"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
static int globalInt = 123;

clang/test/APINotes/Inputs/Headers/module.modulemap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ module ExternCtx {
22
header "ExternCtx.h"
33
}
44

5+
module ExportAsCore {
6+
header "ExportAsCore.h"
7+
export_as ExportAs
8+
}
9+
10+
module ExportAs {
11+
header "ExportAs.h"
12+
export *
13+
}
14+
515
module HeaderLib {
616
header "HeaderLib.h"
717
}

clang/test/APINotes/export-as.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// 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
3+
4+
#include "ExportAs.h"
5+
6+
// CHECK: Dumping globalInt:
7+
// CHECK: VarDecl {{.+}} imported in ExportAsCore globalInt 'int'
8+
// CHECK: UnavailableAttr {{.+}} <<invalid sloc>> "oh no"

0 commit comments

Comments
 (0)