Skip to content

Commit

Permalink
[APINotes] For a re-exported module, look for APINotes in the re-expo…
Browse files Browse the repository at this point in the history
…rting module's apinotes file

This upstreams apple#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
  • Loading branch information
egorzhdan committed Mar 28, 2024
1 parent a2982a2 commit 96c8e2e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
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"

0 comments on commit 96c8e2e

Please sign in to comment.