Skip to content

Commit 96c8e2e

Browse files
authored
[APINotes] For a re-exported module, look for APINotes in the re-exporting module's apinotes file
This upstreams swiftlang#8063. If module FooCore is re-exported through module Foo (by using `export_as` in the modulemap), look for attributes of FooCore symbols in Foo.apinotes file. Swift bundles `std.apinotes` file that adds Swift-specific attributes to the C++ stdlib symbols. In recent versions of libc++, module std got split into multiple top-level modules, each of them is re-exported through std. This change allows us to keep using a single modulemap file for all supported C++ stdlibs. rdar://121680760
1 parent a2982a2 commit 96c8e2e

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

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

234235
APINotes.push_back(*File);
235236
}
237+
// If module FooCore is re-exported through module Foo, try Foo.apinotes.
238+
if (!ExportedModuleName.empty())
239+
if (auto File = findAPINotesFile(Dir, ExportedModuleName, WantPublic))
240+
APINotes.push_back(*File);
236241
};
237242

238243
if (M->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)