[clang] 96c8e2e - [APINotes] For a re-exported module, look for APINotes in the re-exporting module's apinotes file
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 28 06:00:01 PDT 2024
Author: Egor Zhdan
Date: 2024-03-28T12:59:57Z
New Revision: 96c8e2e88cc68416ddce4a9bf1a9221387b6d4b3
URL: https://github.com/llvm/llvm-project/commit/96c8e2e88cc68416ddce4a9bf1a9221387b6d4b3
DIFF: https://github.com/llvm/llvm-project/commit/96c8e2e88cc68416ddce4a9bf1a9221387b6d4b3.diff
LOG: [APINotes] For a re-exported module, look for APINotes in the re-exporting module's apinotes file
This upstreams https://github.com/apple/llvm-project/pull/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
Added:
clang/test/APINotes/Inputs/Headers/ExportAs.apinotes
clang/test/APINotes/Inputs/Headers/ExportAs.h
clang/test/APINotes/Inputs/Headers/ExportAsCore.h
clang/test/APINotes/export-as.c
Modified:
clang/lib/APINotes/APINotesManager.cpp
clang/test/APINotes/Inputs/Headers/module.modulemap
Removed:
################################################################################
diff --git a/clang/lib/APINotes/APINotesManager.cpp b/clang/lib/APINotes/APINotesManager.cpp
index f60f09e2b3c231..789bb97d81de00 100644
--- a/clang/lib/APINotes/APINotesManager.cpp
+++ b/clang/lib/APINotes/APINotesManager.cpp
@@ -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.
@@ -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) {
diff --git a/clang/test/APINotes/Inputs/Headers/ExportAs.apinotes b/clang/test/APINotes/Inputs/Headers/ExportAs.apinotes
new file mode 100644
index 00000000000000..14c77afd8c30a1
--- /dev/null
+++ b/clang/test/APINotes/Inputs/Headers/ExportAs.apinotes
@@ -0,0 +1,5 @@
+Name: ExportAs
+Globals:
+ - Name: globalInt
+ Availability: none
+ AvailabilityMsg: "oh no"
diff --git a/clang/test/APINotes/Inputs/Headers/ExportAs.h b/clang/test/APINotes/Inputs/Headers/ExportAs.h
new file mode 100644
index 00000000000000..ff490e09641760
--- /dev/null
+++ b/clang/test/APINotes/Inputs/Headers/ExportAs.h
@@ -0,0 +1 @@
+#include "ExportAsCore.h"
diff --git a/clang/test/APINotes/Inputs/Headers/ExportAsCore.h b/clang/test/APINotes/Inputs/Headers/ExportAsCore.h
new file mode 100644
index 00000000000000..f7674c19935d64
--- /dev/null
+++ b/clang/test/APINotes/Inputs/Headers/ExportAsCore.h
@@ -0,0 +1 @@
+static int globalInt = 123;
diff --git a/clang/test/APINotes/Inputs/Headers/module.modulemap b/clang/test/APINotes/Inputs/Headers/module.modulemap
index 98b4ee3e96cfe7..99fb1aec86481a 100644
--- a/clang/test/APINotes/Inputs/Headers/module.modulemap
+++ b/clang/test/APINotes/Inputs/Headers/module.modulemap
@@ -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"
}
diff --git a/clang/test/APINotes/export-as.c b/clang/test/APINotes/export-as.c
new file mode 100644
index 00000000000000..7a8a652ab75575
--- /dev/null
+++ b/clang/test/APINotes/export-as.c
@@ -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"
More information about the cfe-commits
mailing list