[clang] 89a0c40 - [clang][diagnostics] Add '-Wundef-prefix' warning option

2020-06-30 Thread Cyndy Ishida via cfe-commits

Author: Zixu Wang
Date: 2020-06-30T13:57:47-07:00
New Revision: 89a0c4066b0e70edd257e30d7189f303e26251a0

URL: 
https://github.com/llvm/llvm-project/commit/89a0c4066b0e70edd257e30d7189f303e26251a0
DIFF: 
https://github.com/llvm/llvm-project/commit/89a0c4066b0e70edd257e30d7189f303e26251a0.diff

LOG: [clang][diagnostics] Add '-Wundef-prefix' warning option

Summary:
Add an `-Wundef-prefix=,...` option, which is similar to `-Wundef`, 
but only give warnings for undefined macros with the given prefixes.

Reviewers: ributzka, steven_wu, cishida, bruno, arphaman, rsmith

Reviewed By: ributzka, arphaman

Subscribers: riccibruno, dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80751

This patch was authored by Zixu Wang 

Added: 
clang/test/Preprocessor/warn-macro-undef.c

Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/DiagnosticOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Lex/PPExpressions.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index fa07e9ae76c8..9cb06cf5b5e1 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -312,6 +312,9 @@ def pp_macro_not_used : Warning<"macro is not used">, 
DefaultIgnore,
 def warn_pp_undef_identifier : Warning<
   "%0 is not defined, evaluates to 0">,
   InGroup>, DefaultIgnore;
+def warn_pp_undef_prefix : Warning<
+  "%0 is not defined, evaluates to 0">,
+  InGroup>, DefaultIgnore;
 def warn_pp_ambiguous_macro : Warning<
   "ambiguous expansion of macro %0">, InGroup;
 def note_pp_ambiguous_macro_chosen : Note<

diff  --git a/clang/include/clang/Basic/DiagnosticOptions.h 
b/clang/include/clang/Basic/DiagnosticOptions.h
index 3e3c4e50a9e0..7fbe534c5994 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.h
+++ b/clang/include/clang/Basic/DiagnosticOptions.h
@@ -98,6 +98,10 @@ class DiagnosticOptions : public 
RefCountedBase{
   /// prefixes removed.
   std::vector Warnings;
 
+  /// The list of prefixes from -Wundef-prefix=... used to generate warnings
+  /// for undefined macros.
+  std::vector UndefPrefixes;
+
   /// The list of -R... options used to alter the diagnostic mappings, with the
   /// prefixes removed.
   std::vector Remarks;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index eca822c6afa3..d030468514c3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -483,6 +483,9 @@ def Wnonportable_cfstrings : Joined<["-"], 
"Wnonportable-cfstrings">, Group,
   HelpText<"Pass the comma separated arguments in  to the preprocessor">,
   MetaVarName<"">, Group;
+def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, 
Group,
+  Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"">,
+  HelpText<"Enable warnings for undefined macros with a prefix in the comma 
separated list ">;
 def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, 
CoreOption]>,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 8bd248c95030..e12931a5a1b4 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1688,6 +1688,9 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, 
ArgList &Args,
   }
   Opts.MessageLength =
   getLastArgIntValue(Args, OPT_fmessage_length_EQ, 0, Diags);
+
+  Opts.UndefPrefixes = Args.getAllArgValues(OPT_Wundef_prefix_EQ);
+
   addDiagnosticArgs(Args, OPT_W_Group, OPT_W_value_Group, Opts.Warnings);
   addDiagnosticArgs(Args, OPT_R_Group, OPT_R_value_Group, Opts.Remarks);
 

diff  --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index e5ec2b99f507..7a158a31490d 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -15,7 +15,6 @@
 //
 
//===--===//
 
-#include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
@@ -26,9 +25,12 @@
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/SaveAndRestore.h"
@@ -251,8 +253,24

[clang] b6c67c3 - [clang] Track how headers get included generally during lookup time

2022-05-04 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2022-05-04T09:52:31-07:00
New Revision: b6c67c3c67893d532fe741c508dfa2ac40fae1ad

URL: 
https://github.com/llvm/llvm-project/commit/b6c67c3c67893d532fe741c508dfa2ac40fae1ad
DIFF: 
https://github.com/llvm/llvm-project/commit/b6c67c3c67893d532fe741c508dfa2ac40fae1ad.diff

LOG: [clang] Track how headers get included generally during lookup time

tapi & clang-extractapi both attempt to construct then check against
how a header was included to determine api information when working
against multiple search paths, headermap, and vfsoverlay mechanisms.
Validating this against what the preprocessor sees during lookup time
makes this check more reliable.

Reviewed By: zixuw, jansvoboda11

Differential Revision: https://reviews.llvm.org/D124638

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Lex/HeaderSearch.cpp
clang/unittests/Lex/HeaderSearchTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index e88e600ba2b974..b523ad5ef9ff23 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -20,6 +20,7 @@
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
@@ -314,6 +315,9 @@ class HeaderSearch {
   /// whether they were valid or not.
   llvm::DenseMap LoadedModuleMaps;
 
+  // A map of discovered headers with their associated include file name.
+  llvm::DenseMap> IncludeNames;
+
   /// Uniqued set of framework names, which is used to track which
   /// headers were included as framework headers.
   llvm::StringSet FrameworkNames;
@@ -823,6 +827,13 @@ class HeaderSearch {
   /// Retrieve a uniqued framework name.
   StringRef getUniqueFrameworkName(StringRef Framework);
 
+  /// Retrieve the include name for the header.
+  ///
+  /// \param File The entry for a given header.
+  /// \returns The name of how the file was included when the header's location
+  /// was resolved.
+  StringRef getIncludeNameForHeader(const FileEntry *File) const;
+
   /// Suggest a path by which the specified file could be found, for use in
   /// diagnostics to suggest a #include. Returned path will only contain 
forward
   /// slashes as separators. MainFile is the absolute path of the file that we

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 14b9a1d7f68be1..5fd853541b6a21 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1030,8 +1030,11 @@ Optional HeaderSearch::LookupFile(
 
 CurDir = It;
 
+const auto FE = &File->getFileEntry();
+IncludeNames[FE] = Filename;
+
 // This file is a system header or C++ unfriendly if the dir is.
-HeaderFileInfo &HFI = getFileInfo(&File->getFileEntry());
+HeaderFileInfo &HFI = getFileInfo(FE);
 HFI.DirInfo = CurDir->getDirCharacteristic();
 
 // If the directory characteristic is User but this framework was
@@ -1460,6 +1463,13 @@ StringRef HeaderSearch::getUniqueFrameworkName(StringRef 
Framework) {
   return FrameworkNames.insert(Framework).first->first();
 }
 
+StringRef HeaderSearch::getIncludeNameForHeader(const FileEntry *File) const {
+  auto It = IncludeNames.find(File);
+  if (It == IncludeNames.end())
+return {};
+  return It->second;
+}
+
 bool HeaderSearch::hasModuleMap(StringRef FileName,
 const DirectoryEntry *Root,
 bool IsSystem) {

diff  --git a/clang/unittests/Lex/HeaderSearchTest.cpp 
b/clang/unittests/Lex/HeaderSearchTest.cpp
index fbb5cb30754a79..87d1c01650987b 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -207,6 +207,7 @@ TEST_F(HeaderSearchTest, HeaderFrameworkLookup) {
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
 }
 
 // Helper struct with null terminator character to make MemoryBuffer happy.
@@ -275,6 +276,7 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) {
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
 }
 
 } // namespace



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a1a14e8 - [Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.

2022-05-24 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2022-05-24T08:43:31-07:00
New Revision: a1a14e817eeb5a0663b1342a125674348b8aac06

URL: 
https://github.com/llvm/llvm-project/commit/a1a14e817eeb5a0663b1342a125674348b8aac06
DIFF: 
https://github.com/llvm/llvm-project/commit/a1a14e817eeb5a0663b1342a125674348b8aac06.diff

LOG: [Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype 
decls.

Clang has recently started diagnosing prototype redeclaration errors like 
[rG385e7df33046](https://reviews.llvm.org/rG385e7df33046d7292612ee1e3ac00a59d8bc0441)

This flagged legitimate issues in a codebase but was confusing to resolve 
because it actually conflicted with a function declaration from a system header 
and not from the one emitted with "note: ".

This patch updates the error handling to use the canonical declaration's source 
location instead to avoid misleading errors like the one described.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D126258

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/prototype-redecls.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index df3e8804c7d55..b150a88e0aa21 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3911,6 +3911,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl 
*&OldD, Scope *S,
 // ASTContext::typesAreCompatible().
 if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn &&
 Old->getNumParams() != New->getNumParams()) {
+  if (Old->hasInheritedPrototype())
+Old = Old->getCanonicalDecl();
   Diag(New->getLocation(), diag::err_conflicting_types) << New;
   Diag(Old->getLocation(), PrevDiag) << Old << Old->getType();
   return true;

diff  --git a/clang/test/Sema/prototype-redecls.c 
b/clang/test/Sema/prototype-redecls.c
index ca3355f79d69a..ed569b5223ce2 100644
--- a/clang/test/Sema/prototype-redecls.c
+++ b/clang/test/Sema/prototype-redecls.c
@@ -12,6 +12,10 @@ void blarg() {}   // expected-error {{conflicting types 
for 'blarg'}}
 void blerp(short);  // expected-note {{previous}}
 void blerp(x) int x; {} // expected-error {{conflicting types for 'blerp'}}
 
+void foo(int); // expected-note {{previous}}
+void foo();
+void foo() {} // expected-error {{conflicting types for 'foo'}}
+
 void glerp(int);
 void glerp(x) short x; {} // Okay, promoted type is fine
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-13 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/85100

* A lot of `tapi installapi` options are already shared with clang, but not 
all. This patch handles installapi specific options by filtering for them in 
initial argv input, then passing the rest to the clang driver.
* Installapi not only generates a text file but also reports to library 
developers when there are inconsistences between an interface and it's 
implementation. To allow this, add support for reporting installapi 
diagnostics. This will be leveraged in the verifier service.

>From a71d8d338c9a5cc2f21957b7907f676f2f11d4d6 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 09:16:20 -0800
Subject: [PATCH] [InstallAPI] Add installapi specific options & diagnostics

* A lot of `tapi installapi` options are already shared with clang, but not all.
  This patch handles installapi specific options by filtering for them in 
initial argv input, then passing the rest to the clang driver.
* Installapi not only generates a text file but also reports to library
  developers when there are inconsistences between an interface and it's
  implementation. To allow this, add support for reporting installapi
  diagnostics. This will be leveraged in the verifier service.
---
 clang/include/clang/Basic/AllDiagnostics.h|   1 +
 clang/include/clang/Basic/CMakeLists.txt  |   1 +
 clang/include/clang/Basic/Diagnostic.td   |   1 +
 clang/include/clang/Basic/DiagnosticIDs.h |   4 +-
 .../clang/Basic/DiagnosticInstallAPI.h|  26 +++
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  20 ++
 .../include/clang/InstallAPI/DylibVerifier.h  |  27 +++
 .../clang/InstallAPI/InstallAPIDiagnostic.h   |  14 ++
 clang/lib/Basic/DiagnosticIDs.cpp |  10 +-
 .../InstallAPI/driver-invalid-options.test|   7 +-
 clang/test/InstallAPI/functions.test  |   2 +-
 clang/tools/clang-installapi/CMakeLists.txt   |   8 +
 .../clang-installapi/ClangInstallAPI.cpp  |  23 +--
 .../tools/clang-installapi/InstallAPIOpts.td  |  31 +++
 clang/tools/clang-installapi/Options.cpp  | 192 +++---
 clang/tools/clang-installapi/Options.h|  25 ++-
 16 files changed, 342 insertions(+), 50 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPI.h
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
 create mode 100644 clang/include/clang/InstallAPI/DylibVerifier.h
 create mode 100644 clang/include/clang/InstallAPI/InstallAPIDiagnostic.h
 create mode 100644 clang/tools/clang-installapi/InstallAPIOpts.td

diff --git a/clang/include/clang/Basic/AllDiagnostics.h 
b/clang/include/clang/Basic/AllDiagnostics.h
index cc6aa631534a5d..e64634cc138f7f 100644
--- a/clang/include/clang/Basic/AllDiagnostics.h
+++ b/clang/include/clang/Basic/AllDiagnostics.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticCrossTU.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/DiagnosticInstallAPI.h"
 #include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..7d53c751c13ac4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
 clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
+clang_diag_gen(InstallAPI)
 clang_diag_gen(Lex)
 clang_diag_gen(Parse)
 clang_diag_gen(Refactoring)
diff --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 8d66e265fbaef0..0b8b3af939ba0e 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
 include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
+include "DiagnosticInstallAPIKinds.td"
 include "DiagnosticLexKinds.td"
 include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 0cdda42793f6f0..95b502b1e97ab1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -42,6 +42,7 @@ namespace clang {
   DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
+  DIAG_SIZE_INSTALLAPI=  100,
 };
 // Start position for diagnostics.
 enum {
@@ -57,7 +58,8 @@ namespace clang {
   DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
   DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
-  DIAG_UPPE

[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-13 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/85100
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-13 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85100

>From 7a7c5103a20b35a00c87fe47f1a4bc4a24dc205e Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 09:16:20 -0800
Subject: [PATCH] [InstallAPI] Add installapi specific options & diagnostics

* A lot of `tapi installapi` options are already shared with clang, but not all.
  This patch handles installapi specific options by filtering for them in 
initial argv input, then passing the rest to the clang driver.
* Installapi not only generates a text file but also reports to library
  developers when there are inconsistences between an interface and it's
  implementation. To allow this, add support for reporting installapi
  diagnostics. This will be leveraged in the verifier service.
---
 clang/include/clang/Basic/AllDiagnostics.h|   1 +
 clang/include/clang/Basic/CMakeLists.txt  |   1 +
 clang/include/clang/Basic/Diagnostic.td   |   1 +
 clang/include/clang/Basic/DiagnosticIDs.h |   4 +-
 .../clang/Basic/DiagnosticInstallAPI.h|  26 +++
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  20 ++
 .../include/clang/InstallAPI/DylibVerifier.h  |  27 +++
 .../clang/InstallAPI/InstallAPIDiagnostic.h   |  14 ++
 clang/lib/Basic/DiagnosticIDs.cpp |  10 +-
 .../InstallAPI/driver-invalid-options.test|   7 +-
 clang/test/InstallAPI/functions.test  |   2 +-
 clang/tools/clang-installapi/CMakeLists.txt   |   8 +
 .../clang-installapi/ClangInstallAPI.cpp  |  23 +--
 .../tools/clang-installapi/InstallAPIOpts.td  |  31 +++
 clang/tools/clang-installapi/Options.cpp  | 192 +++---
 clang/tools/clang-installapi/Options.h|  25 ++-
 16 files changed, 342 insertions(+), 50 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPI.h
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
 create mode 100644 clang/include/clang/InstallAPI/DylibVerifier.h
 create mode 100644 clang/include/clang/InstallAPI/InstallAPIDiagnostic.h
 create mode 100644 clang/tools/clang-installapi/InstallAPIOpts.td

diff --git a/clang/include/clang/Basic/AllDiagnostics.h 
b/clang/include/clang/Basic/AllDiagnostics.h
index cc6aa631534a5d..e64634cc138f7f 100644
--- a/clang/include/clang/Basic/AllDiagnostics.h
+++ b/clang/include/clang/Basic/AllDiagnostics.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticCrossTU.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/DiagnosticInstallAPI.h"
 #include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..7d53c751c13ac4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
 clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
+clang_diag_gen(InstallAPI)
 clang_diag_gen(Lex)
 clang_diag_gen(Parse)
 clang_diag_gen(Refactoring)
diff --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 8d66e265fbaef0..0b8b3af939ba0e 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
 include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
+include "DiagnosticInstallAPIKinds.td"
 include "DiagnosticLexKinds.td"
 include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 0cdda42793f6f0..95b502b1e97ab1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -42,6 +42,7 @@ namespace clang {
   DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
+  DIAG_SIZE_INSTALLAPI=  100,
 };
 // Start position for diagnostics.
 enum {
@@ -57,7 +58,8 @@ namespace clang {
   DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
   DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
-  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING)
+  DIAG_START_INSTALLAPI= DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING),
+  DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI+ 
static_cast(DIAG_SIZE_INSTALLAPI)
 };
 
 class CustomDiagInfo;
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h 
b/clang/include/clang/Basic/DiagnosticInstallAPI.h
new file mode 100644
index 00..a76f6e087a2b0a
--- /dev/n

[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-13 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85100

>From 7a7c5103a20b35a00c87fe47f1a4bc4a24dc205e Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 09:16:20 -0800
Subject: [PATCH 1/2] [InstallAPI] Add installapi specific options &
 diagnostics

* A lot of `tapi installapi` options are already shared with clang, but not all.
  This patch handles installapi specific options by filtering for them in 
initial argv input, then passing the rest to the clang driver.
* Installapi not only generates a text file but also reports to library
  developers when there are inconsistences between an interface and it's
  implementation. To allow this, add support for reporting installapi
  diagnostics. This will be leveraged in the verifier service.
---
 clang/include/clang/Basic/AllDiagnostics.h|   1 +
 clang/include/clang/Basic/CMakeLists.txt  |   1 +
 clang/include/clang/Basic/Diagnostic.td   |   1 +
 clang/include/clang/Basic/DiagnosticIDs.h |   4 +-
 .../clang/Basic/DiagnosticInstallAPI.h|  26 +++
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  20 ++
 .../include/clang/InstallAPI/DylibVerifier.h  |  27 +++
 .../clang/InstallAPI/InstallAPIDiagnostic.h   |  14 ++
 clang/lib/Basic/DiagnosticIDs.cpp |  10 +-
 .../InstallAPI/driver-invalid-options.test|   7 +-
 clang/test/InstallAPI/functions.test  |   2 +-
 clang/tools/clang-installapi/CMakeLists.txt   |   8 +
 .../clang-installapi/ClangInstallAPI.cpp  |  23 +--
 .../tools/clang-installapi/InstallAPIOpts.td  |  31 +++
 clang/tools/clang-installapi/Options.cpp  | 192 +++---
 clang/tools/clang-installapi/Options.h|  25 ++-
 16 files changed, 342 insertions(+), 50 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPI.h
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
 create mode 100644 clang/include/clang/InstallAPI/DylibVerifier.h
 create mode 100644 clang/include/clang/InstallAPI/InstallAPIDiagnostic.h
 create mode 100644 clang/tools/clang-installapi/InstallAPIOpts.td

diff --git a/clang/include/clang/Basic/AllDiagnostics.h 
b/clang/include/clang/Basic/AllDiagnostics.h
index cc6aa631534a5d..e64634cc138f7f 100644
--- a/clang/include/clang/Basic/AllDiagnostics.h
+++ b/clang/include/clang/Basic/AllDiagnostics.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticCrossTU.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/DiagnosticInstallAPI.h"
 #include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..7d53c751c13ac4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
 clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
+clang_diag_gen(InstallAPI)
 clang_diag_gen(Lex)
 clang_diag_gen(Parse)
 clang_diag_gen(Refactoring)
diff --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 8d66e265fbaef0..0b8b3af939ba0e 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
 include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
+include "DiagnosticInstallAPIKinds.td"
 include "DiagnosticLexKinds.td"
 include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 0cdda42793f6f0..95b502b1e97ab1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -42,6 +42,7 @@ namespace clang {
   DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
+  DIAG_SIZE_INSTALLAPI=  100,
 };
 // Start position for diagnostics.
 enum {
@@ -57,7 +58,8 @@ namespace clang {
   DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
   DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
-  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING)
+  DIAG_START_INSTALLAPI= DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING),
+  DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI+ 
static_cast(DIAG_SIZE_INSTALLAPI)
 };
 
 class CustomDiagInfo;
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h 
b/clang/include/clang/Basic/DiagnosticInstallAPI.h
new file mode 100644
index 00..a76f6e087a2b0a
--- /

[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-14 Thread Cyndy Ishida via cfe-commits




cyndyishida wrote:

Strictly speaking no, I don't. From looking at the git history, I think this is 
a pattern for supporting older includes through refactors. I figured to follow 
it for parity with the other DiagnosticKind files. 

https://github.com/llvm/llvm-project/pull/85100
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] capture compatibility versions (PR #85261)

2024-03-14 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/85261

None

>From 18fec7f57a4da9dbd6b724fd91fce226bd412a17 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Thu, 14 Mar 2024 09:27:40 -0700
Subject: [PATCH] [InstallAPI] capture compatability versions

---
 clang/test/InstallAPI/basic.test | 8 ++--
 clang/tools/clang-installapi/Options.cpp | 4 
 clang/tools/clang-installapi/Options.h   | 3 +++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/clang/test/InstallAPI/basic.test b/clang/test/InstallAPI/basic.test
index 5b41ccd517b0af..096911039d114e 100644
--- a/clang/test/InstallAPI/basic.test
+++ b/clang/test/InstallAPI/basic.test
@@ -2,7 +2,8 @@
 // RUN: split-file %s %t
 /// Check basic arguments are captured.
 // RUN: clang-installapi -x objective-c -target arm64-apple-ios13.0.0 \
-// RUN: -fapplication-extension -current_version 1 -install_name 
/usr/lib/basic.dylib \
+// RUN: -fapplication-extension -current_version 1 -compatibility_version 1 \
+// RUN: -install_name /usr/lib/basic.dylib \
 // RUN: %t/basic_inputs.json -o %t/basic.tbd 2>&1 | FileCheck %s --allow-empty
 // RUN: llvm-readtapi -compare %t/basic.tbd %t/expected.tbd 2>&1 | FileCheck 
%s --allow-empty
 
@@ -25,11 +26,6 @@
 //--- expected.tbd
 {
   "main_library": {
-"compatibility_versions": [
-  {
-"version": "0"
-  }
-],
 "install_names": [
   {
 "name": "/usr/lib/basic.dylib"
diff --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 701ab81c57c3d0..70cb80f0fdb36f 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -85,6 +85,9 @@ bool Options::processLinkerOptions(InputArgList &Args) {
   if (auto *Arg = Args.getLastArg(OPT_current__version))
 LinkerOpts.CurrentVersion.parse64(Arg->getValue());
 
+  if (auto *Arg = Args.getLastArg(OPT_compatibility__version))
+LinkerOpts.CompatVersion.parse64(Arg->getValue());
+
   LinkerOpts.IsDylib = Args.hasArg(OPT_dynamiclib);
 
   LinkerOpts.AppExtensionSafe =
@@ -159,6 +162,7 @@ InstallAPIContext Options::createContext() {
 
   Ctx.BA.InstallName = LinkerOpts.InstallName;
   Ctx.BA.CurrentVersion = LinkerOpts.CurrentVersion;
+  Ctx.BA.CompatVersion = LinkerOpts.CompatVersion;
   Ctx.BA.AppExtensionSafe = LinkerOpts.AppExtensionSafe;
   Ctx.FT = DriverOpts.OutFT;
   Ctx.OutputLoc = DriverOpts.OutputPath;
diff --git a/clang/tools/clang-installapi/Options.h 
b/clang/tools/clang-installapi/Options.h
index 06f79b62c531ec..2f8baf4a518f90 100644
--- a/clang/tools/clang-installapi/Options.h
+++ b/clang/tools/clang-installapi/Options.h
@@ -49,6 +49,9 @@ struct LinkerOptions {
   /// \brief The current version to use for the dynamic library.
   PackedVersion CurrentVersion;
 
+  /// \brief The compatability version to use for the dynamic library.
+  PackedVersion CompatVersion;
+
   /// \brief Is application extension safe.
   bool AppExtensionSafe = false;
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] capture compatibility versions (PR #85261)

2024-03-14 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85261

>From 18fec7f57a4da9dbd6b724fd91fce226bd412a17 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Thu, 14 Mar 2024 09:27:40 -0700
Subject: [PATCH 1/2] [InstallAPI] capture compatability versions

---
 clang/test/InstallAPI/basic.test | 8 ++--
 clang/tools/clang-installapi/Options.cpp | 4 
 clang/tools/clang-installapi/Options.h   | 3 +++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/clang/test/InstallAPI/basic.test b/clang/test/InstallAPI/basic.test
index 5b41ccd517b0af..096911039d114e 100644
--- a/clang/test/InstallAPI/basic.test
+++ b/clang/test/InstallAPI/basic.test
@@ -2,7 +2,8 @@
 // RUN: split-file %s %t
 /// Check basic arguments are captured.
 // RUN: clang-installapi -x objective-c -target arm64-apple-ios13.0.0 \
-// RUN: -fapplication-extension -current_version 1 -install_name 
/usr/lib/basic.dylib \
+// RUN: -fapplication-extension -current_version 1 -compatibility_version 1 \
+// RUN: -install_name /usr/lib/basic.dylib \
 // RUN: %t/basic_inputs.json -o %t/basic.tbd 2>&1 | FileCheck %s --allow-empty
 // RUN: llvm-readtapi -compare %t/basic.tbd %t/expected.tbd 2>&1 | FileCheck 
%s --allow-empty
 
@@ -25,11 +26,6 @@
 //--- expected.tbd
 {
   "main_library": {
-"compatibility_versions": [
-  {
-"version": "0"
-  }
-],
 "install_names": [
   {
 "name": "/usr/lib/basic.dylib"
diff --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 701ab81c57c3d0..70cb80f0fdb36f 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -85,6 +85,9 @@ bool Options::processLinkerOptions(InputArgList &Args) {
   if (auto *Arg = Args.getLastArg(OPT_current__version))
 LinkerOpts.CurrentVersion.parse64(Arg->getValue());
 
+  if (auto *Arg = Args.getLastArg(OPT_compatibility__version))
+LinkerOpts.CompatVersion.parse64(Arg->getValue());
+
   LinkerOpts.IsDylib = Args.hasArg(OPT_dynamiclib);
 
   LinkerOpts.AppExtensionSafe =
@@ -159,6 +162,7 @@ InstallAPIContext Options::createContext() {
 
   Ctx.BA.InstallName = LinkerOpts.InstallName;
   Ctx.BA.CurrentVersion = LinkerOpts.CurrentVersion;
+  Ctx.BA.CompatVersion = LinkerOpts.CompatVersion;
   Ctx.BA.AppExtensionSafe = LinkerOpts.AppExtensionSafe;
   Ctx.FT = DriverOpts.OutFT;
   Ctx.OutputLoc = DriverOpts.OutputPath;
diff --git a/clang/tools/clang-installapi/Options.h 
b/clang/tools/clang-installapi/Options.h
index 06f79b62c531ec..2f8baf4a518f90 100644
--- a/clang/tools/clang-installapi/Options.h
+++ b/clang/tools/clang-installapi/Options.h
@@ -49,6 +49,9 @@ struct LinkerOptions {
   /// \brief The current version to use for the dynamic library.
   PackedVersion CurrentVersion;
 
+  /// \brief The compatability version to use for the dynamic library.
+  PackedVersion CompatVersion;
+
   /// \brief Is application extension safe.
   bool AppExtensionSafe = false;
 

>From 5f7cafcf6312eaaa119d7dc83d8fd1109bf55195 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Thu, 14 Mar 2024 09:32:19 -0700
Subject: [PATCH 2/2] fix typo in doc string

---
 clang/tools/clang-installapi/Options.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-installapi/Options.h 
b/clang/tools/clang-installapi/Options.h
index 2f8baf4a518f90..e218d57b30518e 100644
--- a/clang/tools/clang-installapi/Options.h
+++ b/clang/tools/clang-installapi/Options.h
@@ -49,7 +49,7 @@ struct LinkerOptions {
   /// \brief The current version to use for the dynamic library.
   PackedVersion CurrentVersion;
 
-  /// \brief The compatability version to use for the dynamic library.
+  /// \brief The compatibility version to use for the dynamic library.
   PackedVersion CompatVersion;
 
   /// \brief Is application extension safe.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] capture compatibility versions (PR #85261)

2024-03-14 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/85261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-14 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85100

>From 7a7c5103a20b35a00c87fe47f1a4bc4a24dc205e Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 09:16:20 -0800
Subject: [PATCH 1/2] [InstallAPI] Add installapi specific options &
 diagnostics

* A lot of `tapi installapi` options are already shared with clang, but not all.
  This patch handles installapi specific options by filtering for them in 
initial argv input, then passing the rest to the clang driver.
* Installapi not only generates a text file but also reports to library
  developers when there are inconsistences between an interface and it's
  implementation. To allow this, add support for reporting installapi
  diagnostics. This will be leveraged in the verifier service.
---
 clang/include/clang/Basic/AllDiagnostics.h|   1 +
 clang/include/clang/Basic/CMakeLists.txt  |   1 +
 clang/include/clang/Basic/Diagnostic.td   |   1 +
 clang/include/clang/Basic/DiagnosticIDs.h |   4 +-
 .../clang/Basic/DiagnosticInstallAPI.h|  26 +++
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  20 ++
 .../include/clang/InstallAPI/DylibVerifier.h  |  27 +++
 .../clang/InstallAPI/InstallAPIDiagnostic.h   |  14 ++
 clang/lib/Basic/DiagnosticIDs.cpp |  10 +-
 .../InstallAPI/driver-invalid-options.test|   7 +-
 clang/test/InstallAPI/functions.test  |   2 +-
 clang/tools/clang-installapi/CMakeLists.txt   |   8 +
 .../clang-installapi/ClangInstallAPI.cpp  |  23 +--
 .../tools/clang-installapi/InstallAPIOpts.td  |  31 +++
 clang/tools/clang-installapi/Options.cpp  | 192 +++---
 clang/tools/clang-installapi/Options.h|  25 ++-
 16 files changed, 342 insertions(+), 50 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPI.h
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
 create mode 100644 clang/include/clang/InstallAPI/DylibVerifier.h
 create mode 100644 clang/include/clang/InstallAPI/InstallAPIDiagnostic.h
 create mode 100644 clang/tools/clang-installapi/InstallAPIOpts.td

diff --git a/clang/include/clang/Basic/AllDiagnostics.h 
b/clang/include/clang/Basic/AllDiagnostics.h
index cc6aa631534a5d..e64634cc138f7f 100644
--- a/clang/include/clang/Basic/AllDiagnostics.h
+++ b/clang/include/clang/Basic/AllDiagnostics.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticCrossTU.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/DiagnosticInstallAPI.h"
 #include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..7d53c751c13ac4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
 clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
+clang_diag_gen(InstallAPI)
 clang_diag_gen(Lex)
 clang_diag_gen(Parse)
 clang_diag_gen(Refactoring)
diff --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 8d66e265fbaef0..0b8b3af939ba0e 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
 include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
+include "DiagnosticInstallAPIKinds.td"
 include "DiagnosticLexKinds.td"
 include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 0cdda42793f6f0..95b502b1e97ab1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -42,6 +42,7 @@ namespace clang {
   DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
+  DIAG_SIZE_INSTALLAPI=  100,
 };
 // Start position for diagnostics.
 enum {
@@ -57,7 +58,8 @@ namespace clang {
   DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
   DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
-  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING)
+  DIAG_START_INSTALLAPI= DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING),
+  DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI+ 
static_cast(DIAG_SIZE_INSTALLAPI)
 };
 
 class CustomDiagInfo;
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h 
b/clang/include/clang/Basic/DiagnosticInstallAPI.h
new file mode 100644
index 00..a76f6e087a2b0a
--- /

[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-14 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85100

>From 1281dfa43781cd544b80575d6b8e76a89204e7ff Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 09:16:20 -0800
Subject: [PATCH] [InstallAPI] Add installapi specific options & diagnostics

* A lot of `tapi installapi` options are already shared with clang, but not all.
  This patch handles installapi specific options by filtering for them in 
initial argv input, then passing the rest to the clang driver.
* Installapi not only generates a text file but also reports to library
  developers when there are inconsistences between an interface and it's
  implementation. To allow this, add support for reporting installapi
  diagnostics. This will be leveraged in the verifier service.
---
 clang/include/clang/Basic/AllDiagnostics.h|   1 +
 clang/include/clang/Basic/CMakeLists.txt  |   1 +
 clang/include/clang/Basic/Diagnostic.td   |   1 +
 clang/include/clang/Basic/DiagnosticIDs.h |   4 +-
 .../clang/Basic/DiagnosticInstallAPI.h|  26 +++
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  20 ++
 .../include/clang/InstallAPI/DylibVerifier.h  |  27 +++
 .../clang/InstallAPI/InstallAPIDiagnostic.h   |  14 ++
 clang/lib/Basic/DiagnosticIDs.cpp |  10 +-
 .../InstallAPI/driver-invalid-options.test|   7 +-
 clang/test/InstallAPI/functions.test  |   2 +-
 clang/tools/clang-installapi/CMakeLists.txt   |   8 +
 .../clang-installapi/ClangInstallAPI.cpp  |  23 +--
 .../tools/clang-installapi/InstallAPIOpts.td  |  31 +++
 clang/tools/clang-installapi/Options.cpp  | 194 +++---
 clang/tools/clang-installapi/Options.h|  25 ++-
 16 files changed, 343 insertions(+), 51 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPI.h
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
 create mode 100644 clang/include/clang/InstallAPI/DylibVerifier.h
 create mode 100644 clang/include/clang/InstallAPI/InstallAPIDiagnostic.h
 create mode 100644 clang/tools/clang-installapi/InstallAPIOpts.td

diff --git a/clang/include/clang/Basic/AllDiagnostics.h 
b/clang/include/clang/Basic/AllDiagnostics.h
index cc6aa631534a5d..e64634cc138f7f 100644
--- a/clang/include/clang/Basic/AllDiagnostics.h
+++ b/clang/include/clang/Basic/AllDiagnostics.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticCrossTU.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/DiagnosticInstallAPI.h"
 #include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..7d53c751c13ac4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
 clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
+clang_diag_gen(InstallAPI)
 clang_diag_gen(Lex)
 clang_diag_gen(Parse)
 clang_diag_gen(Refactoring)
diff --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 8d66e265fbaef0..0b8b3af939ba0e 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
 include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
+include "DiagnosticInstallAPIKinds.td"
 include "DiagnosticLexKinds.td"
 include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 0cdda42793f6f0..95b502b1e97ab1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -42,6 +42,7 @@ namespace clang {
   DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
+  DIAG_SIZE_INSTALLAPI=  100,
 };
 // Start position for diagnostics.
 enum {
@@ -57,7 +58,8 @@ namespace clang {
   DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
   DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
-  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING)
+  DIAG_START_INSTALLAPI= DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING),
+  DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI+ 
static_cast(DIAG_SIZE_INSTALLAPI)
 };
 
 class CustomDiagInfo;
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h 
b/clang/include/clang/Basic/DiagnosticInstallAPI.h
new file mode 100644
index 00..a76f6e087a2b0a
--- /dev/n

[clang] [llvm] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-15 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85100

>From 1281dfa43781cd544b80575d6b8e76a89204e7ff Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 09:16:20 -0800
Subject: [PATCH 1/2] [InstallAPI] Add installapi specific options &
 diagnostics

* A lot of `tapi installapi` options are already shared with clang, but not all.
  This patch handles installapi specific options by filtering for them in 
initial argv input, then passing the rest to the clang driver.
* Installapi not only generates a text file but also reports to library
  developers when there are inconsistences between an interface and it's
  implementation. To allow this, add support for reporting installapi
  diagnostics. This will be leveraged in the verifier service.
---
 clang/include/clang/Basic/AllDiagnostics.h|   1 +
 clang/include/clang/Basic/CMakeLists.txt  |   1 +
 clang/include/clang/Basic/Diagnostic.td   |   1 +
 clang/include/clang/Basic/DiagnosticIDs.h |   4 +-
 .../clang/Basic/DiagnosticInstallAPI.h|  26 +++
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  20 ++
 .../include/clang/InstallAPI/DylibVerifier.h  |  27 +++
 .../clang/InstallAPI/InstallAPIDiagnostic.h   |  14 ++
 clang/lib/Basic/DiagnosticIDs.cpp |  10 +-
 .../InstallAPI/driver-invalid-options.test|   7 +-
 clang/test/InstallAPI/functions.test  |   2 +-
 clang/tools/clang-installapi/CMakeLists.txt   |   8 +
 .../clang-installapi/ClangInstallAPI.cpp  |  23 +--
 .../tools/clang-installapi/InstallAPIOpts.td  |  31 +++
 clang/tools/clang-installapi/Options.cpp  | 194 +++---
 clang/tools/clang-installapi/Options.h|  25 ++-
 16 files changed, 343 insertions(+), 51 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPI.h
 create mode 100644 clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
 create mode 100644 clang/include/clang/InstallAPI/DylibVerifier.h
 create mode 100644 clang/include/clang/InstallAPI/InstallAPIDiagnostic.h
 create mode 100644 clang/tools/clang-installapi/InstallAPIOpts.td

diff --git a/clang/include/clang/Basic/AllDiagnostics.h 
b/clang/include/clang/Basic/AllDiagnostics.h
index cc6aa631534a5d..e64634cc138f7f 100644
--- a/clang/include/clang/Basic/AllDiagnostics.h
+++ b/clang/include/clang/Basic/AllDiagnostics.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticCrossTU.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Basic/DiagnosticInstallAPI.h"
 #include "clang/Basic/DiagnosticLex.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..7d53c751c13ac4 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -12,6 +12,7 @@ clang_diag_gen(Common)
 clang_diag_gen(CrossTU)
 clang_diag_gen(Driver)
 clang_diag_gen(Frontend)
+clang_diag_gen(InstallAPI)
 clang_diag_gen(Lex)
 clang_diag_gen(Parse)
 clang_diag_gen(Refactoring)
diff --git a/clang/include/clang/Basic/Diagnostic.td 
b/clang/include/clang/Basic/Diagnostic.td
index 8d66e265fbaef0..0b8b3af939ba0e 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -162,6 +162,7 @@ include "DiagnosticCommonKinds.td"
 include "DiagnosticCrossTUKinds.td"
 include "DiagnosticDriverKinds.td"
 include "DiagnosticFrontendKinds.td"
+include "DiagnosticInstallAPIKinds.td"
 include "DiagnosticLexKinds.td"
 include "DiagnosticParseKinds.td"
 include "DiagnosticRefactoringKinds.td"
diff --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index 0cdda42793f6f0..95b502b1e97ab1 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -42,6 +42,7 @@ namespace clang {
   DIAG_SIZE_SEMA  = 4500,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
+  DIAG_SIZE_INSTALLAPI=  100,
 };
 // Start position for diagnostics.
 enum {
@@ -57,7 +58,8 @@ namespace clang {
   DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
   DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
   DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
-  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING)
+  DIAG_START_INSTALLAPI= DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING),
+  DIAG_UPPER_LIMIT = DIAG_START_INSTALLAPI+ 
static_cast(DIAG_SIZE_INSTALLAPI)
 };
 
 class CustomDiagInfo;
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPI.h 
b/clang/include/clang/Basic/DiagnosticInstallAPI.h
new file mode 100644
index 00..a76f6e087a2b0a
--- /

[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/85106
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/85100
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85106

>From 3f0def7f7f56c80af04eecb7b6d11bf3757c8c82 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 12 Mar 2024 20:56:23 -0700
Subject: [PATCH] [InstallAPI] Introduce Basic Verifier

This adds basic support for calling the verifier on global declarations
that are expected to represent symbol exports. The driver now
exclusively uses this for knowing what symbols make up a TBD file.
Future patches will actually check against the dylib's symbol table.
---
 clang/include/clang/AST/Availability.h|   3 +
 clang/include/clang/InstallAPI/Context.h  |   4 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  79 ++-
 clang/include/clang/InstallAPI/Frontend.h |   1 -
 .../clang/InstallAPI/FrontendRecords.h|  49 ++--
 clang/include/clang/InstallAPI/MachO.h|   3 +
 clang/lib/InstallAPI/CMakeLists.txt   |   2 +
 clang/lib/InstallAPI/DylibVerifier.cpp| 212 ++
 clang/lib/InstallAPI/Frontend.cpp |  49 ++--
 clang/lib/InstallAPI/Visitor.cpp  | 101 +
 clang/test/InstallAPI/asm.test|  90 
 .../clang-installapi/ClangInstallAPI.cpp  |  12 +-
 clang/tools/clang-installapi/Options.cpp  |   9 +-
 llvm/include/llvm/TextAPI/Record.h|   7 +-
 14 files changed, 524 insertions(+), 97 deletions(-)
 create mode 100644 clang/lib/InstallAPI/DylibVerifier.cpp
 create mode 100644 clang/test/InstallAPI/asm.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index ae3acbeffe7f18..5cfbaf0cdfbd21 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -75,6 +75,9 @@ struct AvailabilityInfo {
   /// Determine if this AvailabilityInfo represents the default availability.
   bool isDefault() const { return *this == AvailabilityInfo(); }
 
+  /// Check if the symbol has been obsoleted.
+  bool isObsoleted() const { return !Obsoleted.empty(); }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index bdb576d7d85fb6..074ff6f969773c 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -18,6 +18,7 @@
 namespace clang {
 namespace installapi {
 class FrontendRecordsSlice;
+class DylibVerifier;
 
 /// Struct used for generating validating InstallAPI.
 /// The attributes captured represent all necessary information
@@ -45,6 +46,9 @@ struct InstallAPIContext {
   /// DiagnosticsEngine for all error reporting.
   DiagnosticsEngine *Diags = nullptr;
 
+  /// Verifier when binary dylib is passed as input.
+  std::unique_ptr Verifier = nullptr;
+
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
 
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 1a6121b3a258b5..72c4743fdf65e0 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -9,10 +9,12 @@
 #ifndef LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 #define LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 
-#include "llvm/TextAPI/Target.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/InstallAPI/MachO.h"
 
 namespace clang {
 namespace installapi {
+struct FrontendAttrs;
 
 /// A list of InstallAPI verification modes.
 enum class VerificationMode {
@@ -22,6 +24,81 @@ enum class VerificationMode {
   Pedantic,
 };
 
+/// Service responsible to tracking state of verification across the
+/// lifetime of InstallAPI.
+/// As declarations are collected during AST traversal, they are
+/// compared as symbols against what is available in the binary dylib.
+class DylibVerifier {
+private:
+  struct SymbolContext;
+
+public:
+  enum class Result { NoVerify, Ignore, Valid, Invalid };
+  struct VerifierContext {
+// Current target being verified against the AST.
+llvm::MachO::Target Target;
+
+// Query state of verification after AST has been traversed.
+Result FrontendState;
+
+// First error for AST traversal, which is tied to the target triple.
+bool DiscoveredFirstError;
+  };
+
+  DylibVerifier() = default;
+
+  DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
+VerificationMode Mode, bool Demangle)
+  : Dylib(std::move(Dylib)), Diag(Diag), Mode(Mode), Demangle(Demangle),
+Exports(std::make_unique()) {}
+
+  Result verify(GlobalRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
+const StringRef SuperClass);
+
+  /// Initialize target for verification.
+  void setTarget(const Target &T);
+
+  /// Release ownership over exports.
+  std::unique_ptr getE

[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85106

>From 3f0def7f7f56c80af04eecb7b6d11bf3757c8c82 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 12 Mar 2024 20:56:23 -0700
Subject: [PATCH 1/2] [InstallAPI] Introduce Basic Verifier

This adds basic support for calling the verifier on global declarations
that are expected to represent symbol exports. The driver now
exclusively uses this for knowing what symbols make up a TBD file.
Future patches will actually check against the dylib's symbol table.
---
 clang/include/clang/AST/Availability.h|   3 +
 clang/include/clang/InstallAPI/Context.h  |   4 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  79 ++-
 clang/include/clang/InstallAPI/Frontend.h |   1 -
 .../clang/InstallAPI/FrontendRecords.h|  49 ++--
 clang/include/clang/InstallAPI/MachO.h|   3 +
 clang/lib/InstallAPI/CMakeLists.txt   |   2 +
 clang/lib/InstallAPI/DylibVerifier.cpp| 212 ++
 clang/lib/InstallAPI/Frontend.cpp |  49 ++--
 clang/lib/InstallAPI/Visitor.cpp  | 101 +
 clang/test/InstallAPI/asm.test|  90 
 .../clang-installapi/ClangInstallAPI.cpp  |  12 +-
 clang/tools/clang-installapi/Options.cpp  |   9 +-
 llvm/include/llvm/TextAPI/Record.h|   7 +-
 14 files changed, 524 insertions(+), 97 deletions(-)
 create mode 100644 clang/lib/InstallAPI/DylibVerifier.cpp
 create mode 100644 clang/test/InstallAPI/asm.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index ae3acbeffe7f18..5cfbaf0cdfbd21 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -75,6 +75,9 @@ struct AvailabilityInfo {
   /// Determine if this AvailabilityInfo represents the default availability.
   bool isDefault() const { return *this == AvailabilityInfo(); }
 
+  /// Check if the symbol has been obsoleted.
+  bool isObsoleted() const { return !Obsoleted.empty(); }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index bdb576d7d85fb6..074ff6f969773c 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -18,6 +18,7 @@
 namespace clang {
 namespace installapi {
 class FrontendRecordsSlice;
+class DylibVerifier;
 
 /// Struct used for generating validating InstallAPI.
 /// The attributes captured represent all necessary information
@@ -45,6 +46,9 @@ struct InstallAPIContext {
   /// DiagnosticsEngine for all error reporting.
   DiagnosticsEngine *Diags = nullptr;
 
+  /// Verifier when binary dylib is passed as input.
+  std::unique_ptr Verifier = nullptr;
+
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
 
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 1a6121b3a258b5..72c4743fdf65e0 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -9,10 +9,12 @@
 #ifndef LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 #define LLVM_CLANG_INSTALLAPI_DYLIBVERIFIER_H
 
-#include "llvm/TextAPI/Target.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/InstallAPI/MachO.h"
 
 namespace clang {
 namespace installapi {
+struct FrontendAttrs;
 
 /// A list of InstallAPI verification modes.
 enum class VerificationMode {
@@ -22,6 +24,81 @@ enum class VerificationMode {
   Pedantic,
 };
 
+/// Service responsible to tracking state of verification across the
+/// lifetime of InstallAPI.
+/// As declarations are collected during AST traversal, they are
+/// compared as symbols against what is available in the binary dylib.
+class DylibVerifier {
+private:
+  struct SymbolContext;
+
+public:
+  enum class Result { NoVerify, Ignore, Valid, Invalid };
+  struct VerifierContext {
+// Current target being verified against the AST.
+llvm::MachO::Target Target;
+
+// Query state of verification after AST has been traversed.
+Result FrontendState;
+
+// First error for AST traversal, which is tied to the target triple.
+bool DiscoveredFirstError;
+  };
+
+  DylibVerifier() = default;
+
+  DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
+VerificationMode Mode, bool Demangle)
+  : Dylib(std::move(Dylib)), Diag(Diag), Mode(Mode), Demangle(Demangle),
+Exports(std::make_unique()) {}
+
+  Result verify(GlobalRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
+  Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
+const StringRef SuperClass);
+
+  /// Initialize target for verification.
+  void setTarget(const Target &T);
+
+  /// Release ownership over exports.
+  std::unique_ptr 

[clang] [llvm] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/85348
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Introduce Basic Verifier (PR #85106)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/85106
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd212..2ccc607d4b63dcd 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1ce..5ed2e23425dc5fe 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-16 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH 1/2] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd21..2ccc607d4b63dc 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1c..5ed2e23425dc5f 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-18 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH 1/2] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd21..2ccc607d4b63dc 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1c..5ed2e23425dc5f 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-19 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH 1/3] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd21..2ccc607d4b63dc 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1c..5ed2e23425dc5f 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-19 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH 1/3] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd21..2ccc607d4b63dc 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1c..5ed2e23425dc5f 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-19 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH 1/4] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd21..2ccc607d4b63dc 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1c..5ed2e23425dc5f 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-19 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/85348

>From d45081b0270f20a1313a35bd4ae12343e265ce7b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 13 Mar 2024 18:57:14 -0700
Subject: [PATCH 1/5] [InstallAPI] Verify that declarations in header map to
 symbols found in dylib

* This patch completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that is representable in TBD files.

* This patch also now captures unavailable attributes that depend on target 
triples. This is needed for proper tbd file generation.
---
 clang/include/clang/AST/Availability.h|  13 +-
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  23 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  57 +-
 clang/include/clang/InstallAPI/Frontend.h |   3 +
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/AST/Availability.cpp|   6 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 326 -
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 clang/test/InstallAPI/availability.test   | 626 ++
 clang/test/InstallAPI/diagnostics-cpp.test| 461 +
 clang/test/InstallAPI/hiddens.test| 262 
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.cpp  |   4 +-
 13 files changed, 1766 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/InstallAPI/availability.test
 create mode 100644 clang/test/InstallAPI/diagnostics-cpp.test
 create mode 100644 clang/test/InstallAPI/hiddens.test

diff --git a/clang/include/clang/AST/Availability.h 
b/clang/include/clang/AST/Availability.h
index 5cfbaf0cdfbd21..2ccc607d4b63dc 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -67,6 +67,7 @@ struct AvailabilityInfo {
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable = false;
   bool UnconditionallyDeprecated = false;
   bool UnconditionallyUnavailable = false;
 
@@ -78,6 +79,9 @@ struct AvailabilityInfo {
   /// Check if the symbol has been obsoleted.
   bool isObsoleted() const { return !Obsoleted.empty(); }
 
+  /// Check if the symbol is unavailable for the active platform and os 
version.
+  bool isUnavailable() const { return Unavailable; }
+
   /// Check if the symbol is unconditionally deprecated.
   ///
   /// i.e. \code __attribute__((deprecated)) \endcode
@@ -91,9 +95,10 @@ struct AvailabilityInfo {
   }
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-   VersionTuple O, bool UD, bool UU)
+   VersionTuple O, bool U, bool UD, bool UU)
   : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+Unavailable(U), UnconditionallyDeprecated(UD),
+UnconditionallyUnavailable(UU) {}
 
   friend bool operator==(const AvailabilityInfo &Lhs,
  const AvailabilityInfo &Rhs);
@@ -105,10 +110,10 @@ struct AvailabilityInfo {
 inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-  Lhs.UnconditionallyDeprecated,
+  Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
   Lhs.UnconditionallyUnavailable) ==
  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-  Rhs.UnconditionallyDeprecated,
+  Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
   Rhs.UnconditionallyUnavailable);
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 31be4f09cf3a1c..5ed2e23425dc5f 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -17,4 +17,27 @@ def err_no_install_name : Error<"no install name specified: 
add -install_name ;
 } // end of command line category.
 
+let CategoryName = "Verification" in {
+def warn_target: Warning<"violations found for %0">;
+def err_library_missing_symbol : Error<"declaration has external linkage, but 
dynamic library doesn't have symbol '%0'">;
+def warn_library_missing_symbol : Warning<"declaration has external linkage, 
but dynamic library doesn't have symbol '%0'">;
+def err_library_hidden_symbol : Error<"declaration has external linkage, but 
symbol has internal linkage in dynamic library '%0'">;
+def warn_library_hidden_symbol : Warning<"declaration has external linkage, 
but symbol has internal linkage in dynamic library '%0'">;
+def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">;
+def err_header_hidden_symbol : Error<"symbol exported in dynami

[clang] [InstallAPI] Verify that declarations in headers map to exports found in dylib (PR #85348)

2024-03-19 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/85348
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Simplify & improve symbol printing for diagnostics (PR #85894)

2024-03-19 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/85894

* Defer mangling of symbols until an error is ready to report
* Pass around fewer parameters when reporting

>From f172f1c95c7011af4216b9e412fbb305d4f37e95 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 19 Mar 2024 21:32:29 -0700
Subject: [PATCH] [InstallAPI] Simplify & improve symbol printing for
 diagnostics

* Defer mangling of symbols until error is ready to report.
* Pass around less parameters when reporting
---
 .../include/clang/InstallAPI/DylibVerifier.h  |   4 +
 clang/include/clang/InstallAPI/MachO.h|   2 +
 clang/lib/InstallAPI/DylibVerifier.cpp| 134 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   4 +-
 4 files changed, 73 insertions(+), 71 deletions(-)

diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 8269715c7f2345..bbfa8711313e47 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -128,6 +128,10 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Gather annotations for symbol for error reporting.
+  std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
+   bool ValidSourceLoc = true);
+
   // Symbols in dylib.
   llvm::MachO::Records Dylib;
 
diff --git a/clang/include/clang/InstallAPI/MachO.h 
b/clang/include/clang/InstallAPI/MachO.h
index a77766511fa3e5..f0dea8bbd24ccd 100644
--- a/clang/include/clang/InstallAPI/MachO.h
+++ b/clang/include/clang/InstallAPI/MachO.h
@@ -26,11 +26,13 @@
 using SymbolFlags = llvm::MachO::SymbolFlags;
 using RecordLinkage = llvm::MachO::RecordLinkage;
 using Record = llvm::MachO::Record;
+using EncodeKind = llvm::MachO::EncodeKind;
 using GlobalRecord = llvm::MachO::GlobalRecord;
 using ObjCContainerRecord = llvm::MachO::ObjCContainerRecord;
 using ObjCInterfaceRecord = llvm::MachO::ObjCInterfaceRecord;
 using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
 using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
+using ObjCIFSymbolKind = llvm::MachO::ObjCIFSymbolKind;
 using Records = llvm::MachO::Records;
 using RecordsSlice = llvm::MachO::RecordsSlice;
 using BinaryAttrs = llvm::MachO::RecordsSlice::BinaryAttrs;
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 700763b3fee0db..24e0d0addf2f46 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -10,9 +10,6 @@ namespace installapi {
 
 /// Metadata stored about a mapping of a declaration to a symbol.
 struct DylibVerifier::SymbolContext {
-  // Name to use for printing in diagnostics.
-  std::string PrettyPrintName{""};
-
   // Name to use for all querying and verification
   // purposes.
   std::string SymbolName{""};
@@ -30,11 +27,35 @@ struct DylibVerifier::SymbolContext {
   bool Inlined = false;
 };
 
-static std::string
-getAnnotatedName(const Record *R, EncodeKind Kind, StringRef Name,
- bool ValidSourceLoc = true,
- ObjCIFSymbolKind ObjCIF = ObjCIFSymbolKind::None) {
-  assert(!Name.empty() && "Need symbol name for printing");
+static bool isCppMangled(StringRef Name) {
+  // InstallAPI currently only supports itanium manglings.
+  return (Name.starts_with("_Z") || Name.starts_with("__Z") ||
+  Name.starts_with("___Z"));
+}
+
+static std::string demangle(StringRef Name) {
+  // InstallAPI currently only supports itanium manglings.
+  if (!isCppMangled(Name))
+return Name.str();
+  char *Result = llvm::itaniumDemangle(Name);
+  if (!Result)
+return Name.str();
+
+  std::string Demangled(Result);
+  free(Result);
+  return Demangled;
+}
+
+std::string DylibVerifier::getAnnotatedName(const Record *R,
+SymbolContext &SymCtx,
+bool ValidSourceLoc) {
+  assert(!SymCtx.SymbolName.empty() && "Expected symbol name");
+
+  const StringRef SymbolName = SymCtx.SymbolName;
+  std::string PrettyName =
+  (Demangle && (SymCtx.Kind == EncodeKind::GlobalSymbol))
+  ? demangle(SymbolName)
+  : SymbolName.str();
 
   std::string Annotation;
   if (R->isWeakDefined())
@@ -45,15 +66,16 @@ getAnnotatedName(const Record *R, EncodeKind Kind, 
StringRef Name,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass = ((ObjCIF != ObjCIFSymbolKind::None) &&
- (ObjCIF <= ObjCIFSymbolKind::EHType));
+  const bool IsAnnotatedObjCClass =
+  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
+   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
 
   if (IsAnnotatedObjCClass) {
-if (ObjCIF == ObjCIFSymbolKind::EHType)
+if (SymCtx.ObjCIFKind == ObjCIFSymbolKin

[clang] [InstallAPI] Simplify & improve symbol printing for diagnostics (PR #85894)

2024-03-20 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/85894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/86025

This patch completes the classes of errors installapi can detect.

>From b01001d6420bd21dbd332930c4aae82d00958016 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 19 Mar 2024 06:44:26 -0700
Subject: [PATCH] [InstallAPI] Report exports discovered in binary but not in
 interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..20e31c87b75ad2 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -127,6 +130,14 @@ class DylibVerifier {
 
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
+  
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext& SymCtx);
+  
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
 
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..0cc6a4bad91a25 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metac

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86025

>From 9c75bb6dac672fedef114618500cd8600501f8aa Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 20 Mar 2024 15:50:01 -0700
Subject: [PATCH] [InstallAPI] Report exports discovered in binary but not in
 interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..49de24763f1f93 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -128,6 +131,14 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
+
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..2f71cd1a8044f8 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of " + 

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86025

>From 9c75bb6dac672fedef114618500cd8600501f8aa Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 20 Mar 2024 15:50:01 -0700
Subject: [PATCH 1/2] [InstallAPI] Report exports discovered in binary but not
 in interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..49de24763f1f93 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -128,6 +131,14 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
+
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..2f71cd1a8044f8 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of 

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-21 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86025

>From 9c75bb6dac672fedef114618500cd8600501f8aa Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 20 Mar 2024 15:50:01 -0700
Subject: [PATCH 1/3] [InstallAPI] Report exports discovered in binary but not
 in interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..49de24763f1f93 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -128,6 +131,14 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
+
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..2f71cd1a8044f8 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of 

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-21 Thread Cyndy Ishida via cfe-commits


@@ -21,6 +21,9 @@ CHECK-NEXT: CPP.h:5:7: error: declaration has external 
linkage, but symbol has i
 CHECK-NEXT: CPP.h:6:7: error: dynamic library symbol '(weak-def) Bar::init()' 
is weak defined, but its declaration is not
 CHECK-NEXT:   int init();
 CHECK-NEXT:   ^
+CHECK-NEXT: warning: violations found for arm64
+CHECK-NEXT: error: no declaration found for exported symbol 'int foo(unsigned int)' in dyn

cyndyishida wrote:

It was a mistake between the chair and the keyboard.

https://github.com/llvm/llvm-project/pull/86025
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-21 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86025

>From 9c75bb6dac672fedef114618500cd8600501f8aa Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 20 Mar 2024 15:50:01 -0700
Subject: [PATCH 1/4] [InstallAPI] Report exports discovered in binary but not
 in interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..49de24763f1f93 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -128,6 +131,14 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
+
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..2f71cd1a8044f8 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of 

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-21 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/86025
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add --extra* and --exclude* cli options for header input (PR #86522)

2024-03-25 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/86522
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a9d8bf4 - [InstallAPI] Silence unused variable warning, NFC

2024-03-25 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-25T17:20:24-04:00
New Revision: a9d8bf41bf9538154bcc3afcef55bdf309890c6f

URL: 
https://github.com/llvm/llvm-project/commit/a9d8bf41bf9538154bcc3afcef55bdf309890c6f
DIFF: 
https://github.com/llvm/llvm-project/commit/a9d8bf41bf9538154bcc3afcef55bdf309890c6f.diff

LOG: [InstallAPI] Silence unused variable warning, NFC

Added: 


Modified: 
clang/lib/InstallAPI/Visitor.cpp

Removed: 




diff  --git a/clang/lib/InstallAPI/Visitor.cpp 
b/clang/lib/InstallAPI/Visitor.cpp
index 452c8f2fb1e489..f8f5d8d53d5691 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -205,9 +205,10 @@ bool InstallAPIVisitor::VisitObjCCategoryDecl(const 
ObjCCategoryDecl *D) {
   const ObjCInterfaceDecl *InterfaceD = D->getClassInterface();
   const StringRef InterfaceName = InterfaceD->getName();
 
-  auto [Category, FA] = Ctx.Slice->addObjCCategory(InterfaceName, CategoryName,
-   Avail, D, *Access);
-  recordObjCInstanceVariables(D->getASTContext(), Category, InterfaceName,
+  std::pair Category =
+  Ctx.Slice->addObjCCategory(InterfaceName, CategoryName, Avail, D,
+ *Access);
+  recordObjCInstanceVariables(D->getASTContext(), Category.first, 
InterfaceName,
   D->ivars());
   return true;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Reapply "[InstallAPI] Add --extra* and --exclude* cli options for header input (#86522)" (PR #86574)

2024-03-25 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/86574
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-25 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/86587

Umbrella headers are a concept for Darwin-based libraries. They allow framework 
authors to control the order in which their headers should be parsed and allow 
clients to access available headers by including a single header.

InstallAPI will attempt to find the umbrella based on the name of the 
framework. Users can also specify this explicitly by using command line options 
specifying the umbrella header by file path. There can be an umbrella header 
per access level. 

>From 9b25b0486d8f3c8409ee199a9f4695da7780e6cb Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 25 Mar 2024 17:12:14 -0400
Subject: [PATCH] [InstallAPI] Add *umbrella-header options

Umbrella headers are a concept for darwin based libraries. They allow
framework authors control the order of which their headers should be
parsed and allows clients to access available headers by including a
single header.

InstallAPI will attempt to find the umbrella based on the name of the
framework. Users can also specify this explicitly by using command line
options specifying the umbrella header by file path.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  1 +
 clang/include/clang/InstallAPI/HeaderFile.h   | 12 ++-
 clang/test/InstallAPI/umbrella-headers.test   | 59 +++
 .../tools/clang-installapi/InstallAPIOpts.td  | 12 +++
 clang/tools/clang-installapi/Options.cpp  | 74 +++
 clang/tools/clang-installapi/Options.h|  9 +++
 llvm/include/llvm/TextAPI/Utils.h |  3 +
 7 files changed, 167 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/InstallAPI/umbrella-headers.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 27df731fa28627..d710688fc1fe20 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -18,6 +18,7 @@ def err_no_output_file: Error<"no output file specified">;
 def err_no_such_header_file : Error<"no such %select{public|private|project}1 
header file: '%0'">;
 def warn_no_such_excluded_header_file : Warning<"no such excluded 
%select{public|private}0 header file: '%1'">, InGroup;
 def warn_glob_did_not_match: Warning<"glob '%0' did not match any header 
file">, InGroup;
+def err_no_such_umbrella_header_file : Error<"no such 
%select{public|private|project}1 umbrella header file: '%0'">;
 } // end of command line category.
 
 let CategoryName = "Verification" in {
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index 235b4da3add840..332cd415b39ae4 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/include/clang/InstallAPI/HeaderFile.h
@@ -62,6 +62,8 @@ class HeaderFile {
   bool Excluded{false};
   /// Add header file to processing.
   bool Extra{false};
+  /// Specify that header file is the umbrella header for library.
+  bool Umbrella{false};
 
 public:
   HeaderFile() = delete;
@@ -79,17 +81,21 @@ class HeaderFile {
 
   void setExtra(bool V = true) { Extra = V; }
   void setExcluded(bool V = true) { Excluded = V; }
+  void setUmbrellaHeader(bool V = true) { Umbrella = V; }
   bool isExtra() const { return Extra; }
   bool isExcluded() const { return Excluded; }
+  bool isUmbrellaHeader() const { return Umbrella; }
 
   bool useIncludeName() const {
 return Type != HeaderType::Project && !IncludeName.empty();
   }
 
   bool operator==(const HeaderFile &Other) const {
-return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra) ==
-   std::tie(Other.Type, Other.FullPath, Other.IncludeName,
-Other.Language, Other.Excluded, Other.Extra);
+return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
+Umbrella) == std::tie(Other.Type, Other.FullPath,
+  Other.IncludeName, Other.Language,
+  Other.Excluded, Other.Extra,
+  Other.Umbrella);
   }
 };
 
diff --git a/clang/test/InstallAPI/umbrella-headers.test 
b/clang/test/InstallAPI/umbrella-headers.test
new file mode 100644
index 00..b91d3df25b38ec
--- /dev/null
+++ b/clang/test/InstallAPI/umbrella-headers.test
@@ -0,0 +1,59 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
+
+// Try umbrella header flags with different spellings.
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN:  -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: 
--public-umbrella-header=%t/Frameworks/Umbrella2.framework/Headers/SpecialUmbrella.h
 \
+; RUN: -private-umbrella-header \
+; RUN: 
%t/Frameworks/Umbrella2.framework/PrivateHeaders/SpecialPrivateU

[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86587

>From 9b25b0486d8f3c8409ee199a9f4695da7780e6cb Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 25 Mar 2024 17:12:14 -0400
Subject: [PATCH 1/2] [InstallAPI] Add *umbrella-header options

Umbrella headers are a concept for darwin based libraries. They allow
framework authors control the order of which their headers should be
parsed and allows clients to access available headers by including a
single header.

InstallAPI will attempt to find the umbrella based on the name of the
framework. Users can also specify this explicitly by using command line
options specifying the umbrella header by file path.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  1 +
 clang/include/clang/InstallAPI/HeaderFile.h   | 12 ++-
 clang/test/InstallAPI/umbrella-headers.test   | 59 +++
 .../tools/clang-installapi/InstallAPIOpts.td  | 12 +++
 clang/tools/clang-installapi/Options.cpp  | 74 +++
 clang/tools/clang-installapi/Options.h|  9 +++
 llvm/include/llvm/TextAPI/Utils.h |  3 +
 7 files changed, 167 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/InstallAPI/umbrella-headers.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 27df731fa28627..d710688fc1fe20 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -18,6 +18,7 @@ def err_no_output_file: Error<"no output file specified">;
 def err_no_such_header_file : Error<"no such %select{public|private|project}1 
header file: '%0'">;
 def warn_no_such_excluded_header_file : Warning<"no such excluded 
%select{public|private}0 header file: '%1'">, InGroup;
 def warn_glob_did_not_match: Warning<"glob '%0' did not match any header 
file">, InGroup;
+def err_no_such_umbrella_header_file : Error<"no such 
%select{public|private|project}1 umbrella header file: '%0'">;
 } // end of command line category.
 
 let CategoryName = "Verification" in {
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index 235b4da3add840..332cd415b39ae4 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/include/clang/InstallAPI/HeaderFile.h
@@ -62,6 +62,8 @@ class HeaderFile {
   bool Excluded{false};
   /// Add header file to processing.
   bool Extra{false};
+  /// Specify that header file is the umbrella header for library.
+  bool Umbrella{false};
 
 public:
   HeaderFile() = delete;
@@ -79,17 +81,21 @@ class HeaderFile {
 
   void setExtra(bool V = true) { Extra = V; }
   void setExcluded(bool V = true) { Excluded = V; }
+  void setUmbrellaHeader(bool V = true) { Umbrella = V; }
   bool isExtra() const { return Extra; }
   bool isExcluded() const { return Excluded; }
+  bool isUmbrellaHeader() const { return Umbrella; }
 
   bool useIncludeName() const {
 return Type != HeaderType::Project && !IncludeName.empty();
   }
 
   bool operator==(const HeaderFile &Other) const {
-return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra) ==
-   std::tie(Other.Type, Other.FullPath, Other.IncludeName,
-Other.Language, Other.Excluded, Other.Extra);
+return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
+Umbrella) == std::tie(Other.Type, Other.FullPath,
+  Other.IncludeName, Other.Language,
+  Other.Excluded, Other.Extra,
+  Other.Umbrella);
   }
 };
 
diff --git a/clang/test/InstallAPI/umbrella-headers.test 
b/clang/test/InstallAPI/umbrella-headers.test
new file mode 100644
index 00..b91d3df25b38ec
--- /dev/null
+++ b/clang/test/InstallAPI/umbrella-headers.test
@@ -0,0 +1,59 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
+
+// Try umbrella header flags with different spellings.
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN:  -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: 
--public-umbrella-header=%t/Frameworks/Umbrella2.framework/Headers/SpecialUmbrella.h
 \
+; RUN: -private-umbrella-header \
+; RUN: 
%t/Frameworks/Umbrella2.framework/PrivateHeaders/SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN: -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: --public-umbrella-header=SpecialUmbrella.h \
+; RUN: --private-umbrella-header=SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; CHECK-NOT: error
+; CHECK-N

[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits


@@ -424,6 +448,56 @@ InstallAPIContext Options::createContext() {
 if (!Glob->didMatch())
   Diags->Report(diag::warn_glob_did_not_match) << Glob->str();
 
+  // Mark any explicit or inferred umbrella headers. If one exists, move
+  // that to the beginning of the input headers.
+  auto MarkandMoveUmbrellaInHeaders = [&](Regex &Regex,
+  HeaderType Type) -> bool {
+auto It = find_if(Ctx.InputHeaders, [&Regex, Type](const HeaderFile &H) {
+  return (H.getType() == Type) && Regex.match(H.getPath());
+});
+
+if (It == Ctx.InputHeaders.end())
+  return false;
+It->setUmbrellaHeader();
+
+// Because there can be an umbrella header per header type,
+// find the first non umbrella header to swap position with.
+auto BeginPos = find_if(Ctx.InputHeaders, [](const HeaderFile &H) {
+  return !H.isUmbrellaHeader();
+});
+if (BeginPos != Ctx.InputHeaders.end() && BeginPos < It)
+  std::swap(*BeginPos, *It);
+return true;
+  };
+
+  auto FindUmbrellaHeader = [&](StringRef HeaderPath, HeaderType Type) -> bool 
{
+if (!HeaderPath.empty()) {
+  auto EscapedString = Regex::escape(HeaderPath);
+  Regex UmbrellaRegex(EscapedString);
+  if (!MarkandMoveUmbrellaInHeaders(UmbrellaRegex, Type)) {
+Diags->Report(diag::err_no_such_umbrella_header_file)
+<< HeaderPath << (unsigned)Type - 1;

cyndyishida wrote:

No, added asserts.

https://github.com/llvm/llvm-project/pull/86587
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6d579cd - [InstallAPI] Add missing license header to file, NFC

2024-03-26 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-26T11:56:16-04:00
New Revision: 6d579cd1d91cdde5adfa455bda7903e737e9d5cf

URL: 
https://github.com/llvm/llvm-project/commit/6d579cd1d91cdde5adfa455bda7903e737e9d5cf
DIFF: 
https://github.com/llvm/llvm-project/commit/6d579cd1d91cdde5adfa455bda7903e737e9d5cf.diff

LOG: [InstallAPI] Add missing license header to file, NFC

Added: 


Modified: 
clang/lib/InstallAPI/DylibVerifier.cpp

Removed: 




diff  --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 94b8e9cd3233a9..ba25e4183a9b89 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -1,3 +1,11 @@
+//===- DylibVerifier.cpp *- 
C++--*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
 #include "clang/InstallAPI/DylibVerifier.h"
 #include "clang/InstallAPI/FrontendRecords.h"
 #include "clang/InstallAPI/InstallAPIDiagnostic.h"



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86587

>From 9b25b0486d8f3c8409ee199a9f4695da7780e6cb Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 25 Mar 2024 17:12:14 -0400
Subject: [PATCH 1/3] [InstallAPI] Add *umbrella-header options

Umbrella headers are a concept for darwin based libraries. They allow
framework authors control the order of which their headers should be
parsed and allows clients to access available headers by including a
single header.

InstallAPI will attempt to find the umbrella based on the name of the
framework. Users can also specify this explicitly by using command line
options specifying the umbrella header by file path.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  1 +
 clang/include/clang/InstallAPI/HeaderFile.h   | 12 ++-
 clang/test/InstallAPI/umbrella-headers.test   | 59 +++
 .../tools/clang-installapi/InstallAPIOpts.td  | 12 +++
 clang/tools/clang-installapi/Options.cpp  | 74 +++
 clang/tools/clang-installapi/Options.h|  9 +++
 llvm/include/llvm/TextAPI/Utils.h |  3 +
 7 files changed, 167 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/InstallAPI/umbrella-headers.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 27df731fa28627..d710688fc1fe20 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -18,6 +18,7 @@ def err_no_output_file: Error<"no output file specified">;
 def err_no_such_header_file : Error<"no such %select{public|private|project}1 
header file: '%0'">;
 def warn_no_such_excluded_header_file : Warning<"no such excluded 
%select{public|private}0 header file: '%1'">, InGroup;
 def warn_glob_did_not_match: Warning<"glob '%0' did not match any header 
file">, InGroup;
+def err_no_such_umbrella_header_file : Error<"no such 
%select{public|private|project}1 umbrella header file: '%0'">;
 } // end of command line category.
 
 let CategoryName = "Verification" in {
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index 235b4da3add840..332cd415b39ae4 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/include/clang/InstallAPI/HeaderFile.h
@@ -62,6 +62,8 @@ class HeaderFile {
   bool Excluded{false};
   /// Add header file to processing.
   bool Extra{false};
+  /// Specify that header file is the umbrella header for library.
+  bool Umbrella{false};
 
 public:
   HeaderFile() = delete;
@@ -79,17 +81,21 @@ class HeaderFile {
 
   void setExtra(bool V = true) { Extra = V; }
   void setExcluded(bool V = true) { Excluded = V; }
+  void setUmbrellaHeader(bool V = true) { Umbrella = V; }
   bool isExtra() const { return Extra; }
   bool isExcluded() const { return Excluded; }
+  bool isUmbrellaHeader() const { return Umbrella; }
 
   bool useIncludeName() const {
 return Type != HeaderType::Project && !IncludeName.empty();
   }
 
   bool operator==(const HeaderFile &Other) const {
-return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra) ==
-   std::tie(Other.Type, Other.FullPath, Other.IncludeName,
-Other.Language, Other.Excluded, Other.Extra);
+return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
+Umbrella) == std::tie(Other.Type, Other.FullPath,
+  Other.IncludeName, Other.Language,
+  Other.Excluded, Other.Extra,
+  Other.Umbrella);
   }
 };
 
diff --git a/clang/test/InstallAPI/umbrella-headers.test 
b/clang/test/InstallAPI/umbrella-headers.test
new file mode 100644
index 00..b91d3df25b38ec
--- /dev/null
+++ b/clang/test/InstallAPI/umbrella-headers.test
@@ -0,0 +1,59 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
+
+// Try umbrella header flags with different spellings.
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN:  -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: 
--public-umbrella-header=%t/Frameworks/Umbrella2.framework/Headers/SpecialUmbrella.h
 \
+; RUN: -private-umbrella-header \
+; RUN: 
%t/Frameworks/Umbrella2.framework/PrivateHeaders/SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN: -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: --public-umbrella-header=SpecialUmbrella.h \
+; RUN: --private-umbrella-header=SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; CHECK-NOT: error
+; CHECK-N

[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits


@@ -424,6 +448,56 @@ InstallAPIContext Options::createContext() {
 if (!Glob->didMatch())
   Diags->Report(diag::warn_glob_did_not_match) << Glob->str();
 
+  // Mark any explicit or inferred umbrella headers. If one exists, move
+  // that to the beginning of the input headers.
+  auto MarkandMoveUmbrellaInHeaders = [&](Regex &Regex,
+  HeaderType Type) -> bool {
+auto It = find_if(Ctx.InputHeaders, [&Regex, Type](const HeaderFile &H) {
+  return (H.getType() == Type) && Regex.match(H.getPath());
+});
+
+if (It == Ctx.InputHeaders.end())
+  return false;
+It->setUmbrellaHeader();
+
+// Because there can be an umbrella header per header type,
+// find the first non umbrella header to swap position with.
+auto BeginPos = find_if(Ctx.InputHeaders, [](const HeaderFile &H) {
+  return !H.isUmbrellaHeader();
+});
+if (BeginPos != Ctx.InputHeaders.end() && BeginPos < It)
+  std::swap(*BeginPos, *It);
+return true;
+  };
+
+  auto FindUmbrellaHeader = [&](StringRef HeaderPath, HeaderType Type) -> bool 
{
+if (!HeaderPath.empty()) {
+  auto EscapedString = Regex::escape(HeaderPath);
+  Regex UmbrellaRegex(EscapedString);
+  if (!MarkandMoveUmbrellaInHeaders(UmbrellaRegex, Type)) {
+Diags->Report(diag::err_no_such_umbrella_header_file)
+<< HeaderPath << (unsigned)Type - 1;

cyndyishida wrote:

Oh sorry, I thought you meant for umbrella headers. In general, it's used as a 
default value. E.g. When non-input header files that are parsed through 
includes, cached then skipped over when picking up declarations during AST 
traversal. 
I think that's generally good to have a concept of null for enum values.

https://github.com/llvm/llvm-project/pull/86587
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/86587
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-26 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86587

>From 9b25b0486d8f3c8409ee199a9f4695da7780e6cb Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 25 Mar 2024 17:12:14 -0400
Subject: [PATCH 1/3] [InstallAPI] Add *umbrella-header options

Umbrella headers are a concept for darwin based libraries. They allow
framework authors control the order of which their headers should be
parsed and allows clients to access available headers by including a
single header.

InstallAPI will attempt to find the umbrella based on the name of the
framework. Users can also specify this explicitly by using command line
options specifying the umbrella header by file path.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  1 +
 clang/include/clang/InstallAPI/HeaderFile.h   | 12 ++-
 clang/test/InstallAPI/umbrella-headers.test   | 59 +++
 .../tools/clang-installapi/InstallAPIOpts.td  | 12 +++
 clang/tools/clang-installapi/Options.cpp  | 74 +++
 clang/tools/clang-installapi/Options.h|  9 +++
 llvm/include/llvm/TextAPI/Utils.h |  3 +
 7 files changed, 167 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/InstallAPI/umbrella-headers.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 27df731fa28627..d710688fc1fe20 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -18,6 +18,7 @@ def err_no_output_file: Error<"no output file specified">;
 def err_no_such_header_file : Error<"no such %select{public|private|project}1 
header file: '%0'">;
 def warn_no_such_excluded_header_file : Warning<"no such excluded 
%select{public|private}0 header file: '%1'">, InGroup;
 def warn_glob_did_not_match: Warning<"glob '%0' did not match any header 
file">, InGroup;
+def err_no_such_umbrella_header_file : Error<"no such 
%select{public|private|project}1 umbrella header file: '%0'">;
 } // end of command line category.
 
 let CategoryName = "Verification" in {
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index 235b4da3add840..332cd415b39ae4 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/include/clang/InstallAPI/HeaderFile.h
@@ -62,6 +62,8 @@ class HeaderFile {
   bool Excluded{false};
   /// Add header file to processing.
   bool Extra{false};
+  /// Specify that header file is the umbrella header for library.
+  bool Umbrella{false};
 
 public:
   HeaderFile() = delete;
@@ -79,17 +81,21 @@ class HeaderFile {
 
   void setExtra(bool V = true) { Extra = V; }
   void setExcluded(bool V = true) { Excluded = V; }
+  void setUmbrellaHeader(bool V = true) { Umbrella = V; }
   bool isExtra() const { return Extra; }
   bool isExcluded() const { return Excluded; }
+  bool isUmbrellaHeader() const { return Umbrella; }
 
   bool useIncludeName() const {
 return Type != HeaderType::Project && !IncludeName.empty();
   }
 
   bool operator==(const HeaderFile &Other) const {
-return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra) ==
-   std::tie(Other.Type, Other.FullPath, Other.IncludeName,
-Other.Language, Other.Excluded, Other.Extra);
+return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
+Umbrella) == std::tie(Other.Type, Other.FullPath,
+  Other.IncludeName, Other.Language,
+  Other.Excluded, Other.Extra,
+  Other.Umbrella);
   }
 };
 
diff --git a/clang/test/InstallAPI/umbrella-headers.test 
b/clang/test/InstallAPI/umbrella-headers.test
new file mode 100644
index 00..b91d3df25b38ec
--- /dev/null
+++ b/clang/test/InstallAPI/umbrella-headers.test
@@ -0,0 +1,59 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
+
+// Try umbrella header flags with different spellings.
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN:  -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: 
--public-umbrella-header=%t/Frameworks/Umbrella2.framework/Headers/SpecialUmbrella.h
 \
+; RUN: -private-umbrella-header \
+; RUN: 
%t/Frameworks/Umbrella2.framework/PrivateHeaders/SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; RUN: clang-installapi --target=arm64-apple-macosx13 \
+; RUN: -install_name 
/System/Library/Frameworks/Umbrella2.framework/Versions/A/Umbrella2 \
+; RUN: -ObjC -F%t/Frameworks/ %t/inputs.json \
+; RUN: --public-umbrella-header=SpecialUmbrella.h \
+; RUN: --private-umbrella-header=SpecialPrivateUmbrella.h \
+; RUN: -o %t/output.tbd 2>&1 | FileCheck -allow-empty %s
+
+; CHECK-NOT: error
+; CHECK-N

[clang] [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto keyword (PR #86808)

2024-03-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida approved this pull request.

Can you condense the title to something more like `[clang-installapi] Remove 
unnecessary copy`? 


A couple of nits but in general looks good. Thanks for fixing this! 

https://github.com/llvm/llvm-project/pull/86808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto keyword (PR #86808)

2024-03-27 Thread Cyndy Ishida via cfe-commits


@@ -255,7 +255,7 @@ bool InstallAPIVisitor::VisitFunctionDecl(const 
FunctionDecl *D) {
   return true;
 
 // Skip methods in CXX RecordDecls.
-for (auto P : D->getASTContext().getParents(*M)) {
+for (const auto &P : D->getASTContext().getParents(*M)) {

cyndyishida wrote:

```suggestion
for (const DynTypedNode &P : D->getASTContext().getParents(*M)) {
```
An improvement would be to be explicit about the type.

https://github.com/llvm/llvm-project/pull/86808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto keyword (PR #86808)

2024-03-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/86808
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86587

>From 5be17ceb3272253aa52d77fbf8426782e9c21f72 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 25 Mar 2024 17:12:14 -0400
Subject: [PATCH] [InstallAPI] Add *umbrella-header options

Umbrella headers are a concept for darwin based libraries. They allow
framework authors control the order of which their headers should be
parsed and allows clients to access available headers by including a
single header.

InstallAPI will attempt to find the umbrella based on the name of the
framework. Users can also specify this explicitly by using command line
options specifying the umbrella header by file path.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |  1 +
 clang/include/clang/InstallAPI/HeaderFile.h   | 16 ++--
 .../Umbrella/Umbrella.framework/Headers/AAA.h |  3 +
 .../Headers/SpecialUmbrella.h |  1 +
 .../PrivateHeaders/AAA_Private.h  |  3 +
 .../PrivateHeaders/SpecialPrivateUmbrella.h   |  1 +
 .../InstallAPI/umbrella-headers-unix.test | 40 ++
 clang/test/InstallAPI/umbrella-headers.test   | 48 +++
 .../tools/clang-installapi/InstallAPIOpts.td  | 12 +++
 clang/tools/clang-installapi/Options.cpp  | 79 ++-
 clang/tools/clang-installapi/Options.h|  9 +++
 11 files changed, 206 insertions(+), 7 deletions(-)
 create mode 100644 
clang/test/InstallAPI/Inputs/Umbrella/Umbrella.framework/Headers/AAA.h
 create mode 100644 
clang/test/InstallAPI/Inputs/Umbrella/Umbrella.framework/Headers/SpecialUmbrella.h
 create mode 100644 
clang/test/InstallAPI/Inputs/Umbrella/Umbrella.framework/PrivateHeaders/AAA_Private.h
 create mode 100644 
clang/test/InstallAPI/Inputs/Umbrella/Umbrella.framework/PrivateHeaders/SpecialPrivateUmbrella.h
 create mode 100644 clang/test/InstallAPI/umbrella-headers-unix.test
 create mode 100644 clang/test/InstallAPI/umbrella-headers.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index 27df731fa28627..e3263fe9ccb9d4 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -18,6 +18,7 @@ def err_no_output_file: Error<"no output file specified">;
 def err_no_such_header_file : Error<"no such %select{public|private|project}1 
header file: '%0'">;
 def warn_no_such_excluded_header_file : Warning<"no such excluded 
%select{public|private}0 header file: '%1'">, InGroup;
 def warn_glob_did_not_match: Warning<"glob '%0' did not match any header 
file">, InGroup;
+def err_no_such_umbrella_header_file : Error<"%select{public|private|project}1 
umbrella header file not found in input: '%0'">;
 } // end of command line category.
 
 let CategoryName = "Verification" in {
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index 235b4da3add840..c67503d4ad49e9 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/include/clang/InstallAPI/HeaderFile.h
@@ -24,8 +24,6 @@
 
 namespace clang::installapi {
 enum class HeaderType {
-  /// Unset or unknown type.
-  Unknown,
   /// Represents declarations accessible to all clients.
   Public,
   /// Represents declarations accessible to a disclosed set of clients.
@@ -33,6 +31,8 @@ enum class HeaderType {
   /// Represents declarations only accessible as implementation details to the
   /// input library.
   Project,
+  /// Unset or unknown type.
+  Unknown,
 };
 
 inline StringRef getName(const HeaderType T) {
@@ -62,6 +62,8 @@ class HeaderFile {
   bool Excluded{false};
   /// Add header file to processing.
   bool Extra{false};
+  /// Specify that header file is the umbrella header for library.
+  bool Umbrella{false};
 
 public:
   HeaderFile() = delete;
@@ -79,17 +81,21 @@ class HeaderFile {
 
   void setExtra(bool V = true) { Extra = V; }
   void setExcluded(bool V = true) { Excluded = V; }
+  void setUmbrellaHeader(bool V = true) { Umbrella = V; }
   bool isExtra() const { return Extra; }
   bool isExcluded() const { return Excluded; }
+  bool isUmbrellaHeader() const { return Umbrella; }
 
   bool useIncludeName() const {
 return Type != HeaderType::Project && !IncludeName.empty();
   }
 
   bool operator==(const HeaderFile &Other) const {
-return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra) ==
-   std::tie(Other.Type, Other.FullPath, Other.IncludeName,
-Other.Language, Other.Excluded, Other.Extra);
+return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
+Umbrella) == std::tie(Other.Type, Other.FullPath,
+  Other.IncludeName, Other.Language,
+  Other.Excluded, Other.Extra,
+  Other.Umbrella);
   }
 };
 
diff --git 
a/clang/test/InstallAPI/Inputs/Umbrella/Umbrel

[clang] [InstallAPI] Add *umbrella-header options (PR #86587)

2024-03-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/86587
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/86852

InstallAPI does not directly look at object files in the dylib for 
verification. To help diagnose violations where a declaration is undiscovered 
in headers, parse the dSYM and look up the source location for symbols. 
Emitting out the source location with a diagnostic is enough for some IDE's 
(e.g. Xcode) to have them map back to editable source files.

>From 9ddf01a4f28df19914aa393b1ac518410693af5b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 27 Mar 2024 14:33:15 -0400
Subject: [PATCH] [InstallAPI] Add support for parsing dSYMs

InstallAPI does not directly look at object files in the dylib. To help
diagnose violations where a declaration is undiscovered in headers,
parse the dSYM and lookup the source location for symbols.
Emitting out the source location with a diagnostic is enough for
some IDE's (e.g. Xcode) to have them map back to editable source files.
---
 .../include/clang/InstallAPI/DylibVerifier.h  |  20 +++-
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/InstallAPI/CMakeLists.txt   |   1 +
 clang/lib/InstallAPI/DylibVerifier.cpp|  71 ---
 clang/test/CMakeLists.txt |   1 +
 clang/test/InstallAPI/diagnostics-dsym.test   |  40 +++
 clang/test/lit.cfg.py |   1 +
 .../tools/clang-installapi/InstallAPIOpts.td  |   2 +
 clang/tools/clang-installapi/Options.cpp  |   6 +-
 clang/tools/clang-installapi/Options.h|   3 +
 llvm/include/llvm/TextAPI/DylibReader.h   |   9 ++
 llvm/include/llvm/TextAPI/Record.h|  17 +++
 llvm/lib/TextAPI/BinaryReader/CMakeLists.txt  |   1 +
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp | 112 +-
 14 files changed, 263 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/InstallAPI/diagnostics-dsym.test

diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 49de24763f1f93..22cdc234486cf3 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -31,6 +31,7 @@ enum class VerificationMode {
 class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
+  struct DWARFContext;
 
 public:
   enum class Result { NoVerify, Ignore, Valid, Invalid };
@@ -54,7 +55,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
 DiagnosticsEngine *Diag = nullptr;
 
 // Handle diagnostics reporting for target level violations.
-void emitDiag(llvm::function_ref Report);
+void emitDiag(llvm::function_ref Report, RecordLoc *Loc = nullptr);
 
 VerifierContext() = default;
 VerifierContext(DiagnosticsEngine *Diag) : Diag(Diag) {}
@@ -63,9 +64,10 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   DylibVerifier() = default;
 
   DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
-VerificationMode Mode, bool Demangle)
+VerificationMode Mode, bool Demangle, StringRef DSYMPath)
   : Dylib(std::move(Dylib)), Mode(Mode), Demangle(Demangle),
-Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {}
+DSYMPath(DSYMPath), Exports(std::make_unique()),
+Ctx(VerifierContext{Diag}) {}
 
   Result verify(GlobalRecord *R, const FrontendAttrs *FA);
   Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
@@ -143,6 +145,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
 
+  /// Extract source location for symbol implementations.
+  /// As this is a relatively expensive operation, it is only used
+  /// when there is a violation to report and there is not a known declaration
+  /// in the interface.
+  void accumulateSrcLocForDylibSymbols();
+
   // Symbols in dylib.
   llvm::MachO::Records Dylib;
 
@@ -152,11 +160,17 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   // Attempt to demangle when reporting violations.
   bool Demangle = false;
 
+  // File path to DSYM file.
+  StringRef DSYMPath;
+
   // Valid symbols in final text file.
   std::unique_ptr Exports = std::make_unique();
 
   // Track current state of verification while traversing AST.
   VerifierContext Ctx;
+
+  // Track DWARF provided source location for dylibs.
+  DWARFContext *DWARFCtx = nullptr;
 };
 
 } // namespace installapi
diff --git a/clang/include/clang/InstallAPI/MachO.h 
b/clang/include/clang/InstallAPI/MachO.h
index 4961c596fd68ae..827220dbf39fb8 100644
--- a/clang/include/clang/InstallAPI/MachO.h
+++ b/clang/include/clang/InstallAPI/MachO.h
@@ -34,6 +34,7 @@ using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
 using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
 using ObjCIFSymbolKind = llvm::MachO::ObjCIFSymbolKind;
 using Records = llvm::MachO::Records;
+using RecordLoc = llvm::MachO:

[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-27 Thread Cyndy Ishida via cfe-commits


@@ -0,0 +1,40 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+
+// Build a simple dylib with debug info.
+; RUN: %clang --target=arm64-apple-macos13 -g -dynamiclib %t/foo.c \

cyndyishida wrote:

@JDevlieghere Is there a better/known practice for generating full dylibs with 
debug info for tests? Hopefully, PR CI will let me know, but I'm a little 
worried about different linker semantics. 
e.g. Xcode's ld requires all userspace dylibs link against libSystem. 

https://github.com/llvm/llvm-project/pull/86852
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86852

>From 9ddf01a4f28df19914aa393b1ac518410693af5b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 27 Mar 2024 14:33:15 -0400
Subject: [PATCH 1/2] [InstallAPI] Add support for parsing dSYMs

InstallAPI does not directly look at object files in the dylib. To help
diagnose violations where a declaration is undiscovered in headers,
parse the dSYM and lookup the source location for symbols.
Emitting out the source location with a diagnostic is enough for
some IDE's (e.g. Xcode) to have them map back to editable source files.
---
 .../include/clang/InstallAPI/DylibVerifier.h  |  20 +++-
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/InstallAPI/CMakeLists.txt   |   1 +
 clang/lib/InstallAPI/DylibVerifier.cpp|  71 ---
 clang/test/CMakeLists.txt |   1 +
 clang/test/InstallAPI/diagnostics-dsym.test   |  40 +++
 clang/test/lit.cfg.py |   1 +
 .../tools/clang-installapi/InstallAPIOpts.td  |   2 +
 clang/tools/clang-installapi/Options.cpp  |   6 +-
 clang/tools/clang-installapi/Options.h|   3 +
 llvm/include/llvm/TextAPI/DylibReader.h   |   9 ++
 llvm/include/llvm/TextAPI/Record.h|  17 +++
 llvm/lib/TextAPI/BinaryReader/CMakeLists.txt  |   1 +
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp | 112 +-
 14 files changed, 263 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/InstallAPI/diagnostics-dsym.test

diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 49de24763f1f93..22cdc234486cf3 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -31,6 +31,7 @@ enum class VerificationMode {
 class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
+  struct DWARFContext;
 
 public:
   enum class Result { NoVerify, Ignore, Valid, Invalid };
@@ -54,7 +55,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
 DiagnosticsEngine *Diag = nullptr;
 
 // Handle diagnostics reporting for target level violations.
-void emitDiag(llvm::function_ref Report);
+void emitDiag(llvm::function_ref Report, RecordLoc *Loc = nullptr);
 
 VerifierContext() = default;
 VerifierContext(DiagnosticsEngine *Diag) : Diag(Diag) {}
@@ -63,9 +64,10 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   DylibVerifier() = default;
 
   DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
-VerificationMode Mode, bool Demangle)
+VerificationMode Mode, bool Demangle, StringRef DSYMPath)
   : Dylib(std::move(Dylib)), Mode(Mode), Demangle(Demangle),
-Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {}
+DSYMPath(DSYMPath), Exports(std::make_unique()),
+Ctx(VerifierContext{Diag}) {}
 
   Result verify(GlobalRecord *R, const FrontendAttrs *FA);
   Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
@@ -143,6 +145,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
 
+  /// Extract source location for symbol implementations.
+  /// As this is a relatively expensive operation, it is only used
+  /// when there is a violation to report and there is not a known declaration
+  /// in the interface.
+  void accumulateSrcLocForDylibSymbols();
+
   // Symbols in dylib.
   llvm::MachO::Records Dylib;
 
@@ -152,11 +160,17 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   // Attempt to demangle when reporting violations.
   bool Demangle = false;
 
+  // File path to DSYM file.
+  StringRef DSYMPath;
+
   // Valid symbols in final text file.
   std::unique_ptr Exports = std::make_unique();
 
   // Track current state of verification while traversing AST.
   VerifierContext Ctx;
+
+  // Track DWARF provided source location for dylibs.
+  DWARFContext *DWARFCtx = nullptr;
 };
 
 } // namespace installapi
diff --git a/clang/include/clang/InstallAPI/MachO.h 
b/clang/include/clang/InstallAPI/MachO.h
index 4961c596fd68ae..827220dbf39fb8 100644
--- a/clang/include/clang/InstallAPI/MachO.h
+++ b/clang/include/clang/InstallAPI/MachO.h
@@ -34,6 +34,7 @@ using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
 using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
 using ObjCIFSymbolKind = llvm::MachO::ObjCIFSymbolKind;
 using Records = llvm::MachO::Records;
+using RecordLoc = llvm::MachO::RecordLoc;
 using RecordsSlice = llvm::MachO::RecordsSlice;
 using BinaryAttrs = llvm::MachO::RecordsSlice::BinaryAttrs;
 using SymbolSet = llvm::MachO::SymbolSet;
diff --git a/clang/lib/InstallAPI/CMakeLists.txt 
b/clang/lib/InstallAPI/CMakeLists.txt
index 894db699578f20..e0bc8d969ecb3a 100644
--- a/clang/lib/InstallAPI/CMakeLists.txt
+++ b/clang/lib/

[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86852

>From 9ddf01a4f28df19914aa393b1ac518410693af5b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 27 Mar 2024 14:33:15 -0400
Subject: [PATCH 1/3] [InstallAPI] Add support for parsing dSYMs

InstallAPI does not directly look at object files in the dylib. To help
diagnose violations where a declaration is undiscovered in headers,
parse the dSYM and lookup the source location for symbols.
Emitting out the source location with a diagnostic is enough for
some IDE's (e.g. Xcode) to have them map back to editable source files.
---
 .../include/clang/InstallAPI/DylibVerifier.h  |  20 +++-
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/InstallAPI/CMakeLists.txt   |   1 +
 clang/lib/InstallAPI/DylibVerifier.cpp|  71 ---
 clang/test/CMakeLists.txt |   1 +
 clang/test/InstallAPI/diagnostics-dsym.test   |  40 +++
 clang/test/lit.cfg.py |   1 +
 .../tools/clang-installapi/InstallAPIOpts.td  |   2 +
 clang/tools/clang-installapi/Options.cpp  |   6 +-
 clang/tools/clang-installapi/Options.h|   3 +
 llvm/include/llvm/TextAPI/DylibReader.h   |   9 ++
 llvm/include/llvm/TextAPI/Record.h|  17 +++
 llvm/lib/TextAPI/BinaryReader/CMakeLists.txt  |   1 +
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp | 112 +-
 14 files changed, 263 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/InstallAPI/diagnostics-dsym.test

diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 49de24763f1f93..22cdc234486cf3 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -31,6 +31,7 @@ enum class VerificationMode {
 class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
+  struct DWARFContext;
 
 public:
   enum class Result { NoVerify, Ignore, Valid, Invalid };
@@ -54,7 +55,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
 DiagnosticsEngine *Diag = nullptr;
 
 // Handle diagnostics reporting for target level violations.
-void emitDiag(llvm::function_ref Report);
+void emitDiag(llvm::function_ref Report, RecordLoc *Loc = nullptr);
 
 VerifierContext() = default;
 VerifierContext(DiagnosticsEngine *Diag) : Diag(Diag) {}
@@ -63,9 +64,10 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   DylibVerifier() = default;
 
   DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
-VerificationMode Mode, bool Demangle)
+VerificationMode Mode, bool Demangle, StringRef DSYMPath)
   : Dylib(std::move(Dylib)), Mode(Mode), Demangle(Demangle),
-Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {}
+DSYMPath(DSYMPath), Exports(std::make_unique()),
+Ctx(VerifierContext{Diag}) {}
 
   Result verify(GlobalRecord *R, const FrontendAttrs *FA);
   Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
@@ -143,6 +145,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
 
+  /// Extract source location for symbol implementations.
+  /// As this is a relatively expensive operation, it is only used
+  /// when there is a violation to report and there is not a known declaration
+  /// in the interface.
+  void accumulateSrcLocForDylibSymbols();
+
   // Symbols in dylib.
   llvm::MachO::Records Dylib;
 
@@ -152,11 +160,17 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   // Attempt to demangle when reporting violations.
   bool Demangle = false;
 
+  // File path to DSYM file.
+  StringRef DSYMPath;
+
   // Valid symbols in final text file.
   std::unique_ptr Exports = std::make_unique();
 
   // Track current state of verification while traversing AST.
   VerifierContext Ctx;
+
+  // Track DWARF provided source location for dylibs.
+  DWARFContext *DWARFCtx = nullptr;
 };
 
 } // namespace installapi
diff --git a/clang/include/clang/InstallAPI/MachO.h 
b/clang/include/clang/InstallAPI/MachO.h
index 4961c596fd68ae..827220dbf39fb8 100644
--- a/clang/include/clang/InstallAPI/MachO.h
+++ b/clang/include/clang/InstallAPI/MachO.h
@@ -34,6 +34,7 @@ using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
 using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
 using ObjCIFSymbolKind = llvm::MachO::ObjCIFSymbolKind;
 using Records = llvm::MachO::Records;
+using RecordLoc = llvm::MachO::RecordLoc;
 using RecordsSlice = llvm::MachO::RecordsSlice;
 using BinaryAttrs = llvm::MachO::RecordsSlice::BinaryAttrs;
 using SymbolSet = llvm::MachO::SymbolSet;
diff --git a/clang/lib/InstallAPI/CMakeLists.txt 
b/clang/lib/InstallAPI/CMakeLists.txt
index 894db699578f20..e0bc8d969ecb3a 100644
--- a/clang/lib/InstallAPI/CMakeLists.txt
+++ b/clang/lib/

[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-27 Thread Cyndy Ishida via cfe-commits


@@ -511,14 +520,16 @@ DylibVerifier::Result DylibVerifier::verify(GlobalRecord 
*R,
   return verifyImpl(R, SymCtx);
 }
 
-void DylibVerifier::VerifierContext::emitDiag(
-llvm::function_ref Report) {
+void DylibVerifier::VerifierContext::emitDiag(llvm::function_ref 
Report,
+  RecordLoc *Loc) {
   if (!DiscoveredFirstError) {
 Diag->Report(diag::warn_target)
 << (PrintArch ? getArchitectureName(Target.Arch)
   : getTargetTripleName(Target));
 DiscoveredFirstError = true;
   }
+  if (Loc && Loc->isValid())
+llvm::errs() << Loc->File << ":" << Loc->Line << ":" << 0 << ": ";

cyndyishida wrote:

Yep https://llvm.org/doxygen/classllvm_1_1DWARFDie.html Doubt its too hard to 
add, but
for stuff like jump to definition, it doesn't impact usability.

https://github.com/llvm/llvm-project/pull/86852
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-27 Thread Cyndy Ishida via cfe-commits


@@ -0,0 +1,40 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+
+// Build a simple dylib with debug info.
+; RUN: %clang --target=arm64-apple-macos13 -g -dynamiclib %t/foo.c \

cyndyishida wrote:

Looks like the linker on the linux bot doesn't support building Darwin anyway
```
/usr/bin/ld: unrecognised emulation mode: llvm
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om 
elf_k1om i386pep i386pe
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
Perhaps I'll require Darwin env to run the test and then I won't need to 
introduce a `dsymutil` dependency at all since it can come from xcode.

https://github.com/llvm/llvm-project/pull/86852
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-28 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86852

>From 9ddf01a4f28df19914aa393b1ac518410693af5b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 27 Mar 2024 14:33:15 -0400
Subject: [PATCH 1/4] [InstallAPI] Add support for parsing dSYMs

InstallAPI does not directly look at object files in the dylib. To help
diagnose violations where a declaration is undiscovered in headers,
parse the dSYM and lookup the source location for symbols.
Emitting out the source location with a diagnostic is enough for
some IDE's (e.g. Xcode) to have them map back to editable source files.
---
 .../include/clang/InstallAPI/DylibVerifier.h  |  20 +++-
 clang/include/clang/InstallAPI/MachO.h|   1 +
 clang/lib/InstallAPI/CMakeLists.txt   |   1 +
 clang/lib/InstallAPI/DylibVerifier.cpp|  71 ---
 clang/test/CMakeLists.txt |   1 +
 clang/test/InstallAPI/diagnostics-dsym.test   |  40 +++
 clang/test/lit.cfg.py |   1 +
 .../tools/clang-installapi/InstallAPIOpts.td  |   2 +
 clang/tools/clang-installapi/Options.cpp  |   6 +-
 clang/tools/clang-installapi/Options.h|   3 +
 llvm/include/llvm/TextAPI/DylibReader.h   |   9 ++
 llvm/include/llvm/TextAPI/Record.h|  17 +++
 llvm/lib/TextAPI/BinaryReader/CMakeLists.txt  |   1 +
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp | 112 +-
 14 files changed, 263 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/InstallAPI/diagnostics-dsym.test

diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 49de24763f1f93..22cdc234486cf3 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -31,6 +31,7 @@ enum class VerificationMode {
 class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
+  struct DWARFContext;
 
 public:
   enum class Result { NoVerify, Ignore, Valid, Invalid };
@@ -54,7 +55,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
 DiagnosticsEngine *Diag = nullptr;
 
 // Handle diagnostics reporting for target level violations.
-void emitDiag(llvm::function_ref Report);
+void emitDiag(llvm::function_ref Report, RecordLoc *Loc = nullptr);
 
 VerifierContext() = default;
 VerifierContext(DiagnosticsEngine *Diag) : Diag(Diag) {}
@@ -63,9 +64,10 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   DylibVerifier() = default;
 
   DylibVerifier(llvm::MachO::Records &&Dylib, DiagnosticsEngine *Diag,
-VerificationMode Mode, bool Demangle)
+VerificationMode Mode, bool Demangle, StringRef DSYMPath)
   : Dylib(std::move(Dylib)), Mode(Mode), Demangle(Demangle),
-Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {}
+DSYMPath(DSYMPath), Exports(std::make_unique()),
+Ctx(VerifierContext{Diag}) {}
 
   Result verify(GlobalRecord *R, const FrontendAttrs *FA);
   Result verify(ObjCInterfaceRecord *R, const FrontendAttrs *FA);
@@ -143,6 +145,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
 
+  /// Extract source location for symbol implementations.
+  /// As this is a relatively expensive operation, it is only used
+  /// when there is a violation to report and there is not a known declaration
+  /// in the interface.
+  void accumulateSrcLocForDylibSymbols();
+
   // Symbols in dylib.
   llvm::MachO::Records Dylib;
 
@@ -152,11 +160,17 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
   // Attempt to demangle when reporting violations.
   bool Demangle = false;
 
+  // File path to DSYM file.
+  StringRef DSYMPath;
+
   // Valid symbols in final text file.
   std::unique_ptr Exports = std::make_unique();
 
   // Track current state of verification while traversing AST.
   VerifierContext Ctx;
+
+  // Track DWARF provided source location for dylibs.
+  DWARFContext *DWARFCtx = nullptr;
 };
 
 } // namespace installapi
diff --git a/clang/include/clang/InstallAPI/MachO.h 
b/clang/include/clang/InstallAPI/MachO.h
index 4961c596fd68ae..827220dbf39fb8 100644
--- a/clang/include/clang/InstallAPI/MachO.h
+++ b/clang/include/clang/InstallAPI/MachO.h
@@ -34,6 +34,7 @@ using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
 using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
 using ObjCIFSymbolKind = llvm::MachO::ObjCIFSymbolKind;
 using Records = llvm::MachO::Records;
+using RecordLoc = llvm::MachO::RecordLoc;
 using RecordsSlice = llvm::MachO::RecordsSlice;
 using BinaryAttrs = llvm::MachO::RecordsSlice::BinaryAttrs;
 using SymbolSet = llvm::MachO::SymbolSet;
diff --git a/clang/lib/InstallAPI/CMakeLists.txt 
b/clang/lib/InstallAPI/CMakeLists.txt
index 894db699578f20..e0bc8d969ecb3a 100644
--- a/clang/lib/InstallAPI/CMakeLists.txt
+++ b/clang/lib/

[clang] [clang][Darwin] Handle reexported library arguments in driver (PR #86980)

2024-03-28 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/86980

`-reexport*` is the newer spelling for `-sub-library` which is already 
supported by the clang driver when invoking ld.
Support the new spellings when passed by the user. This also helps simplify 
`clang-installapi` driver logic.

>From 8a0443608ece499d929ddda83d21872da117dd16 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Thu, 28 Mar 2024 12:57:46 -0400
Subject: [PATCH] [clang][Darwin] Handle reexported library arguments in driver

`-reexport*` is the newer spelling for `-sub-library` which is already
supported by the clang driver when invoking ld.
Support the new spellings when passed by the user. This also helps
simplify `clang-installapi` driver logic.
---
 clang/include/clang/Driver/Options.td   |  3 +++
 clang/test/Driver/darwin-ld-reexports.c | 21 +
 2 files changed, 24 insertions(+)
 create mode 100644 clang/test/Driver/darwin-ld-reexports.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29066ea14280c2..8a3929eeb6692b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3635,6 +3635,9 @@ defm preserve_as_comments : 
BoolFOption<"preserve-as-comments",
   "Do not preserve comments in inline assembly">,
   PosFlag>;
 def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>;
+def reexport_framework : Separate<["-"], "reexport_framework">, 
Flags<[LinkerInput]>;
+def reexport_l : Joined<["-"], "reexport-l">, Flags<[LinkerInput]>;
+def reexport_library : JoinedOrSeparate<["-"], "reexport_library">, 
Flags<[LinkerInput]>;
 def frandom_seed_EQ : Joined<["-"], "frandom-seed=">, 
Group;
 def freg_struct_return : Flag<["-"], "freg-struct-return">, Group,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/test/Driver/darwin-ld-reexports.c 
b/clang/test/Driver/darwin-ld-reexports.c
new file mode 100644
index 00..2e96db49a8a387
--- /dev/null
+++ b/clang/test/Driver/darwin-ld-reexports.c
@@ -0,0 +1,21 @@
+// RUN: touch %t.o
+// RUN: %clang -target arm64-apple-darwin13 -### \
+// RUN: -reexport_framework Foo -reexport-lBar -reexport_library Baz %t.o 2> 
%t.log
+
+// Check older spellings also work.
+// RUN: %clang -target arm64-apple-darwin13 -### \
+// RUN: -Xlinker -reexport_framework -Xlinker Forest \
+// RUN: -Xlinker -reexport-lBranch \
+// RUN: -Xlinker -reexport_library -Xlinker Flower %t.o 2>> %t.log
+// RUN: FileCheck -check-prefix=LINK_REEXPORT %s < %t.log
+
+// LINK_REEXPORT: {{ld(.exe)?"}}
+// LINK_REEXPORT: "-reexport_framework" "Foo"
+// LINK_REEXPORT: "-reexport-lBar"
+// LINK_REEXPORT: "-reexport_library" "Baz"
+// LINK_REEXPORT: "-reexport_framework" "Forest"
+// LINK_REEXPORT: "-reexport-lBranch"
+// LINK_REEXPORT: "-reexport_library" "Flower"
+
+// Make sure arguments are not repeated.
+// LINK_REEXPORT-NOT: "-reexport

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Darwin] Handle reexported library arguments in driver (PR #86980)

2024-03-28 Thread Cyndy Ishida via cfe-commits

cyndyishida wrote:

Thanks for the reviews!

https://github.com/llvm/llvm-project/pull/86980
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Add support for parsing dSYMs (PR #86852)

2024-03-29 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/86852
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 60deb8b - [InstallAPI][test] Tweak test to run on older CI config

2024-03-29 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-29T10:00:51-07:00
New Revision: 60deb8b39afe9be90e30aa18d77ad129dacd4d55

URL: 
https://github.com/llvm/llvm-project/commit/60deb8b39afe9be90e30aa18d77ad129dacd4d55
DIFF: 
https://github.com/llvm/llvm-project/commit/60deb8b39afe9be90e30aa18d77ad129dacd4d55.diff

LOG: [InstallAPI][test] Tweak test to run on older CI config

Added: 


Modified: 
clang/test/InstallAPI/diagnostics-dsym.test

Removed: 




diff  --git a/clang/test/InstallAPI/diagnostics-dsym.test 
b/clang/test/InstallAPI/diagnostics-dsym.test
index ee2c8b32df29c3..45c69c09d2863f 100644
--- a/clang/test/InstallAPI/diagnostics-dsym.test
+++ b/clang/test/InstallAPI/diagnostics-dsym.test
@@ -4,20 +4,20 @@
 ; RUN: split-file %s %t
 
 // Build a simple dylib with debug info.
-; RUN: %clang --target=arm64-apple-macos13 -g -dynamiclib %t/foo.c \
+; RUN: %clang --target=x86_64-apple-macos10.15 -g -dynamiclib %t/foo.c \
 ; RUN: -current_version 1 -compatibility_version 1 -L%t/usr/lib \
 ; RUN: -save-temps \
 ; RUN: -o %t/foo.dylib -install_name %t/foo.dylib
 ; RUN: dsymutil %t/foo.dylib -o %t/foo.dSYM
 
-; RUN: not clang-installapi -x c++ --target=arm64-apple-macos13 \
+; RUN: not clang-installapi -x c++ --target=x86_64-apple-macos10.15 \
 ; RUN: -install_name %t/foo.dylib  \
 ; RUN: -current_version 1 -compatibility_version 1 \
 ; RUN: -o %t/output.tbd \
 ; RUN: --verify-against=%t/foo.dylib --dsym=%t/foo.dSYM \
 ; RUN: --verify-mode=Pedantic 2>&1 | FileCheck %s
 
-; CHECK: violations found for arm64 
+; CHECK: violations found for x86_64 
 ; CHECK: foo.c:5:0: error: no declaration found for exported symbol 'bar' in 
dynamic library
 ; CHECK: foo.c:1:0: error: no declaration found for exported symbol 'foo' in 
dynamic library
 
@@ -29,15 +29,11 @@ extern char bar;
 char bar = 'a';
 
 ;--- usr/lib/libSystem.tbd
-{
-  "main_library": {
-"install_names": [
-  {"name": "/usr/lib/libSystem.B.dylib"}
-],
-"target_info": [
-  {"target": "arm64-macos"}
-]
-  },
-  "tapi_tbd_version": 5
-}
-
+--- !tapi-tbd
+tbd-version: 4
+targets: [ x86_64-macos ]
+install-name:'/usr/lib/libSystem.B.dylib'
+exports: 
+  - targets: [ x86_64-macos ]
+symbols: [ dyld_stub_binder ]
+...



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bdb60e6 - [InstallAPI][test] Add requires x86_64 for hardcoded target test

2024-03-29 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-29T10:34:35-07:00
New Revision: bdb60e6f0c8e89abf9bdf36411348db304ca65ba

URL: 
https://github.com/llvm/llvm-project/commit/bdb60e6f0c8e89abf9bdf36411348db304ca65ba
DIFF: 
https://github.com/llvm/llvm-project/commit/bdb60e6f0c8e89abf9bdf36411348db304ca65ba.diff

LOG: [InstallAPI][test] Add requires x86_64 for hardcoded target test

Added: 


Modified: 
clang/test/InstallAPI/diagnostics-dsym.test

Removed: 




diff  --git a/clang/test/InstallAPI/diagnostics-dsym.test 
b/clang/test/InstallAPI/diagnostics-dsym.test
index 45c69c09d2863f..8a1b394f2f8683 100644
--- a/clang/test/InstallAPI/diagnostics-dsym.test
+++ b/clang/test/InstallAPI/diagnostics-dsym.test
@@ -1,4 +1,4 @@
-; REQUIRES: system-darwin
+; REQUIRES: 86_64-darwin
 
 ; RUN: rm -rf %t
 ; RUN: split-file %s %t



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Darwin] Handle reexported library arguments in driver (PR #86980)

2024-03-29 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/86980
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Fixup dsym test (PR #87299)

2024-04-01 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/87299

Update the test to run when the compiler is built to support arm64-darwin 
targets.

>From fc2b73a261a0eddb19d49fcbbf301ec40a1d5ed2 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 1 Apr 2024 18:09:27 -0700
Subject: [PATCH] [InstallAPI] Fixup dsym test to actually run when compiler is
 built for arm64-darwin support

---
 clang/test/InstallAPI/diagnostics-dsym.test | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/test/InstallAPI/diagnostics-dsym.test 
b/clang/test/InstallAPI/diagnostics-dsym.test
index 8a1b394f2f8683..c9cbeffef7bacc 100644
--- a/clang/test/InstallAPI/diagnostics-dsym.test
+++ b/clang/test/InstallAPI/diagnostics-dsym.test
@@ -1,23 +1,24 @@
-; REQUIRES: 86_64-darwin
+; REQUIRES: system-darwin
+; REQUIRES: target-aarch64 
 
 ; RUN: rm -rf %t
 ; RUN: split-file %s %t
 
 // Build a simple dylib with debug info.
-; RUN: %clang --target=x86_64-apple-macos10.15 -g -dynamiclib %t/foo.c \
+; RUN: %clang --target=arm64-apple-macos11 -g -dynamiclib %t/foo.c \
 ; RUN: -current_version 1 -compatibility_version 1 -L%t/usr/lib \
 ; RUN: -save-temps \
 ; RUN: -o %t/foo.dylib -install_name %t/foo.dylib
 ; RUN: dsymutil %t/foo.dylib -o %t/foo.dSYM
 
-; RUN: not clang-installapi -x c++ --target=x86_64-apple-macos10.15 \
+; RUN: not clang-installapi -x c++ --target=arm64-apple-macos11 \
 ; RUN: -install_name %t/foo.dylib  \
 ; RUN: -current_version 1 -compatibility_version 1 \
 ; RUN: -o %t/output.tbd \
 ; RUN: --verify-against=%t/foo.dylib --dsym=%t/foo.dSYM \
 ; RUN: --verify-mode=Pedantic 2>&1 | FileCheck %s
 
-; CHECK: violations found for x86_64 
+; CHECK: violations found for arm64 
 ; CHECK: foo.c:5:0: error: no declaration found for exported symbol 'bar' in 
dynamic library
 ; CHECK: foo.c:1:0: error: no declaration found for exported symbol 'foo' in 
dynamic library
 
@@ -31,9 +32,9 @@ char bar = 'a';
 ;--- usr/lib/libSystem.tbd
 --- !tapi-tbd
 tbd-version: 4
-targets: [ x86_64-macos ]
+targets: [ arm64-macos ]
 install-name:'/usr/lib/libSystem.B.dylib'
 exports: 
-  - targets: [ x86_64-macos ]
+  - targets: [ arm64-macos ]
 symbols: [ dyld_stub_binder ]
 ...

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Fixup dsym test (PR #87299)

2024-04-01 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/87299

>From fc2b73a261a0eddb19d49fcbbf301ec40a1d5ed2 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 1 Apr 2024 18:09:27 -0700
Subject: [PATCH] [InstallAPI] Fixup dsym test to actually run when compiler is
 built for arm64-darwin support

---
 clang/test/InstallAPI/diagnostics-dsym.test | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/test/InstallAPI/diagnostics-dsym.test 
b/clang/test/InstallAPI/diagnostics-dsym.test
index 8a1b394f2f8683..c9cbeffef7bacc 100644
--- a/clang/test/InstallAPI/diagnostics-dsym.test
+++ b/clang/test/InstallAPI/diagnostics-dsym.test
@@ -1,23 +1,24 @@
-; REQUIRES: 86_64-darwin
+; REQUIRES: system-darwin
+; REQUIRES: target-aarch64 
 
 ; RUN: rm -rf %t
 ; RUN: split-file %s %t
 
 // Build a simple dylib with debug info.
-; RUN: %clang --target=x86_64-apple-macos10.15 -g -dynamiclib %t/foo.c \
+; RUN: %clang --target=arm64-apple-macos11 -g -dynamiclib %t/foo.c \
 ; RUN: -current_version 1 -compatibility_version 1 -L%t/usr/lib \
 ; RUN: -save-temps \
 ; RUN: -o %t/foo.dylib -install_name %t/foo.dylib
 ; RUN: dsymutil %t/foo.dylib -o %t/foo.dSYM
 
-; RUN: not clang-installapi -x c++ --target=x86_64-apple-macos10.15 \
+; RUN: not clang-installapi -x c++ --target=arm64-apple-macos11 \
 ; RUN: -install_name %t/foo.dylib  \
 ; RUN: -current_version 1 -compatibility_version 1 \
 ; RUN: -o %t/output.tbd \
 ; RUN: --verify-against=%t/foo.dylib --dsym=%t/foo.dSYM \
 ; RUN: --verify-mode=Pedantic 2>&1 | FileCheck %s
 
-; CHECK: violations found for x86_64 
+; CHECK: violations found for arm64 
 ; CHECK: foo.c:5:0: error: no declaration found for exported symbol 'bar' in 
dynamic library
 ; CHECK: foo.c:1:0: error: no declaration found for exported symbol 'foo' in 
dynamic library
 
@@ -31,9 +32,9 @@ char bar = 'a';
 ;--- usr/lib/libSystem.tbd
 --- !tapi-tbd
 tbd-version: 4
-targets: [ x86_64-macos ]
+targets: [ arm64-macos ]
 install-name:'/usr/lib/libSystem.B.dylib'
 exports: 
-  - targets: [ x86_64-macos ]
+  - targets: [ arm64-macos ]
 symbols: [ dyld_stub_binder ]
 ...

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Fixup dsym test (PR #87299)

2024-04-01 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/87299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 207f153 - [InstallAPI] Condense std::pair unwrapping in CategoryRecord NFC

2024-04-02 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-04-02T09:17:06-07:00
New Revision: 207f1531d611b8add27b94e756e0bc7eb864babf

URL: 
https://github.com/llvm/llvm-project/commit/207f1531d611b8add27b94e756e0bc7eb864babf
DIFF: 
https://github.com/llvm/llvm-project/commit/207f1531d611b8add27b94e756e0bc7eb864babf.diff

LOG: [InstallAPI] Condense std::pair unwrapping in CategoryRecord NFC

Added: 


Modified: 
clang/lib/InstallAPI/Visitor.cpp

Removed: 




diff  --git a/clang/lib/InstallAPI/Visitor.cpp 
b/clang/lib/InstallAPI/Visitor.cpp
index 6476c5107cb5cc..cf3aaa4c6ec931 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -205,10 +205,10 @@ bool InstallAPIVisitor::VisitObjCCategoryDecl(const 
ObjCCategoryDecl *D) {
   const ObjCInterfaceDecl *InterfaceD = D->getClassInterface();
   const StringRef InterfaceName = InterfaceD->getName();
 
-  std::pair Category =
-  Ctx.Slice->addObjCCategory(InterfaceName, CategoryName, Avail, D,
- *Access);
-  recordObjCInstanceVariables(D->getASTContext(), Category.first, 
InterfaceName,
+  ObjCCategoryRecord *CategoryRecord =
+  Ctx.Slice->addObjCCategory(InterfaceName, CategoryName, Avail, D, 
*Access)
+  .first;
+  recordObjCInstanceVariables(D->getASTContext(), CategoryRecord, 
InterfaceName,
   D->ivars());
   return true;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fixup last value in DarwinPlatformKind enum (PR #81011)

2024-02-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/81011

None

>From a9c3775ab646d3540dc776b4363d6d95b49889fd Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 7 Feb 2024 08:52:40 -0800
Subject: [PATCH] [clang] Fixup last value in DarwinPlatformKind

---
 clang/lib/Driver/ToolChains/Darwin.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.h 
b/clang/lib/Driver/ToolChains/Darwin.h
index 5e60b0841d6d5f..10d4b69e5d5f10 100644
--- a/clang/lib/Driver/ToolChains/Darwin.h
+++ b/clang/lib/Driver/ToolChains/Darwin.h
@@ -300,7 +300,7 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
 WatchOS,
 DriverKit,
 XROS,
-LastDarwinPlatform = DriverKit
+LastDarwinPlatform = XROS
   };
   enum DarwinEnvironmentKind {
 NativeEnvironment,

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fixup last value in DarwinPlatformKind enum (PR #81011)

2024-02-07 Thread Cyndy Ishida via cfe-commits

cyndyishida wrote:

> > Why didn't this trigger:
> > https://github.com/llvm/llvm-project/blob/ab92f6274b7c3a4b4445d47017bc481aa919545f/clang/lib/Driver/ToolChains/Darwin.cpp#L1906
> > 
> > ?
> 
> XROS is missing in the env vars too:
> 
> https://github.com/llvm/llvm-project/blob/ab92f6274b7c3a4b4445d47017bc481aa919545f/clang/lib/Driver/ToolChains/Darwin.cpp#L1899

Yes. Adding proper `XROS_DEPLOYMENT_TARGET` support is a bigger patch, I'll 
need to update this PR to reflect this. 

https://github.com/llvm/llvm-project/pull/81011
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fixup last value in DarwinPlatformKind enum (PR #81011)

2024-02-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/81011

>From 5a60725a1abf5a56c4a482c56ea91990074ee17c Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 7 Feb 2024 08:52:40 -0800
Subject: [PATCH] [clang][Driver] Add support for XROS_DEPLOYMENT_TARGET env
 var

---
 clang/lib/Driver/ToolChains/Darwin.cpp  |  6 --
 clang/lib/Driver/ToolChains/Darwin.h|  2 +-
 .../test/Driver/xros-driver-requires-darwin-host.c  | 13 +
 3 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/xros-driver-requires-darwin-host.c

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fae8ad1a958ade..cc1219d69d9910 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1902,6 +1902,7 @@ getDeploymentTargetFromEnvironmentVariables(const Driver 
&TheDriver,
   "TVOS_DEPLOYMENT_TARGET",
   "WATCHOS_DEPLOYMENT_TARGET",
   "DRIVERKIT_DEPLOYMENT_TARGET",
+  "XROS_DEPLOYMENT_TARGET"
   };
   static_assert(std::size(EnvVars) == Darwin::LastDarwinPlatform + 1,
 "Missing platform");
@@ -1914,14 +1915,15 @@ getDeploymentTargetFromEnvironmentVariables(const 
Driver &TheDriver,
   // default platform.
   if (!Targets[Darwin::MacOS].empty() &&
   (!Targets[Darwin::IPhoneOS].empty() ||
-   !Targets[Darwin::WatchOS].empty() || !Targets[Darwin::TvOS].empty())) {
+   !Targets[Darwin::WatchOS].empty() || !Targets[Darwin::TvOS].empty() ||
+   !Targets[Darwin::XROS].empty())) {
 if (Triple.getArch() == llvm::Triple::arm ||
 Triple.getArch() == llvm::Triple::aarch64 ||
 Triple.getArch() == llvm::Triple::thumb)
   Targets[Darwin::MacOS] = "";
 else
   Targets[Darwin::IPhoneOS] = Targets[Darwin::WatchOS] =
-  Targets[Darwin::TvOS] = "";
+  Targets[Darwin::TvOS] = Targets[Darwin::XROS] = "";
   } else {
 // Don't allow conflicts in any other platform.
 unsigned FirstTarget = std::size(Targets);
diff --git a/clang/lib/Driver/ToolChains/Darwin.h 
b/clang/lib/Driver/ToolChains/Darwin.h
index 5e60b0841d6d5f..10d4b69e5d5f10 100644
--- a/clang/lib/Driver/ToolChains/Darwin.h
+++ b/clang/lib/Driver/ToolChains/Darwin.h
@@ -300,7 +300,7 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
 WatchOS,
 DriverKit,
 XROS,
-LastDarwinPlatform = DriverKit
+LastDarwinPlatform = XROS
   };
   enum DarwinEnvironmentKind {
 NativeEnvironment,
diff --git a/clang/test/Driver/xros-driver-requires-darwin-host.c 
b/clang/test/Driver/xros-driver-requires-darwin-host.c
new file mode 100644
index 00..e5bfccae2c2092
--- /dev/null
+++ b/clang/test/Driver/xros-driver-requires-darwin-host.c
@@ -0,0 +1,13 @@
+// REQUIRES: system-darwin
+
+// RUN: env XROS_DEPLOYMENT_TARGET=1.0 %clang -arch arm64 -c -### %s 2>&1 | 
FileCheck %s
+
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir/XROS1.0.sdk
+// RUN: %clang -arch arm64 -isysroot %t.dir/XROS1.0.sdk -c -### %s 2>&1 | 
FileCheck %s
+// RUN: mkdir -p %t.dir/XRSimulator1.0.sdk
+// RUN: %clang -arch arm64 -isysroot %t.dir/XRSimulator1.0.sdk -c -### %s 2>&1 
| FileCheck --check-prefix=CHECK_SIM %s
+
+
+// CHECK: "-cc1"{{.*}} "-triple" "arm64-apple-xros1.0.0"
+// CHECK_SIM: "-cc1"{{.*}} "-triple" "arm64-apple-xros1.0.0-simulator"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Add support for XROS_DEPLOYMENT_TARGET env var (PR #81011)

2024-02-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/81011
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Add support for XROS_DEPLOYMENT_TARGET env var (PR #81011)

2024-02-09 Thread Cyndy Ishida via cfe-commits

cyndyishida wrote:

ping

https://github.com/llvm/llvm-project/pull/81011
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Add support for XROS_DEPLOYMENT_TARGET env var (PR #81011)

2024-02-09 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/81011
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][InstallAPI] Introduce basic driver to write out tbd files (PR #81571)

2024-02-12 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/81571

This introduces a basic outline of installapi as a clang driver option. It 
captures relevant information as cc1 args, which are common arguments already 
passed to the linker to encode into TBD file outputs. This is effectively an 
upstream for what already exists as `tapi installapi` in Xcode toolchains, but 
directly in Clang. This patch does not handle any AST traversing on input yet.

InstallAPI is broadly an operation that takes a series of header files that 
represent a single dynamic library and generates a TBD file out of it which 
represents all the linkable symbols and necessary attributes for statically 
linking in clients. It is the linkable object in all Apple SDKs and when 
building dylibs in Xcode. `clang -installapi` also will support verification 
where it compares all the information recorded for the TBD files against the 
already built binary, to catch possible mismatches like when a declaration is 
missing a definition for an exported symbol.

>From 0f938ae8480f74a44bf6fe4aac6105e457315bb9 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 12 Feb 2024 20:53:25 -0800
Subject: [PATCH]  [clang][InstallAPI] Introduce basic driver to write out tbd
 files.

This introduces a basic outline of installapi as a clang driver option.
It captures relavant information as cc1 args, which is commonly
arguments already passed to the linker to encode into TBD file outputs.
This is effectively an upstream for what already exists as `tapi installapi` in
Xcode toolchains, but direclty in clang. This patch does not handle any AST 
traversing on input yet.

InstallAPI is broadly an operation thats takes a series of header files
that represent a single dynamic library and generates a TBD file out of
it which represents all the linkable symbols and necessary attributes for 
statically linking in clients.
It also will support verification where it compares all the information
recorded for the TBD file against the already built binary, to catch
possible mismatches like when an symbol export is missing a matching
declaration.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +
 clang/include/clang/Driver/Action.h   | 12 
 clang/include/clang/Driver/Options.td | 12 +++-
 clang/include/clang/Driver/Types.def  |  1 +
 .../include/clang/Frontend/CompilerInstance.h |  7 ++
 .../clang/Frontend/CompilerInvocation.h   |  9 ++-
 .../include/clang/Frontend/FrontendActions.h  | 10 +++
 .../include/clang/Frontend/FrontendOptions.h  |  3 +
 .../clang/Frontend/InstallAPIOptions.h| 28 
 clang/include/clang/InstallAPI/Context.h  | 65 +++
 clang/lib/CMakeLists.txt  |  1 +
 clang/lib/Driver/Action.cpp   |  7 ++
 clang/lib/Driver/Driver.cpp   | 15 -
 clang/lib/Driver/ToolChain.cpp|  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 11 
 clang/lib/Frontend/CMakeLists.txt |  2 +
 clang/lib/Frontend/CompilerInvocation.cpp | 41 +++-
 clang/lib/Frontend/InstallAPIConsumer.cpp | 43 
 .../ExecuteCompilerInvocation.cpp |  2 +
 clang/lib/InstallAPI/CMakeLists.txt   | 11 
 clang/lib/InstallAPI/Context.cpp  | 27 
 clang/test/CMakeLists.txt |  1 +
 clang/test/Driver/installapi.h| 13 
 clang/test/InstallAPI/installapi-basic.test   | 34 ++
 clang/test/lit.cfg.py |  2 +
 25 files changed, 356 insertions(+), 5 deletions(-)
 create mode 100644 clang/include/clang/Frontend/InstallAPIOptions.h
 create mode 100644 clang/include/clang/InstallAPI/Context.h
 create mode 100644 clang/lib/Frontend/InstallAPIConsumer.cpp
 create mode 100644 clang/lib/InstallAPI/CMakeLists.txt
 create mode 100644 clang/lib/InstallAPI/Context.cpp
 create mode 100644 clang/test/Driver/installapi.h
 create mode 100644 clang/test/InstallAPI/installapi-basic.test

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index b13181f6e70894..24cc17420c16cc 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -804,4 +804,7 @@ def warn_android_unversioned_fallback : Warning<
 
 def err_drv_triple_version_invalid : Error<
   "version '%0' in target triple '%1' is invalid">;
+
+def err_drv_installapi_unsupported : Error<
+  "the clang compiler does not support '%0' for InstallAPI">;
 }
diff --git a/clang/include/clang/Driver/Action.h 
b/clang/include/clang/Driver/Action.h
index 04fa8b01b418f8..2768e2f5df1a9e 100644
--- a/clang/include/clang/Driver/Action.h
+++ b/clang/include/clang/Driver/Action.h
@@ -59,6 +59,7 @@ class Action {
 PreprocessJobClass,
 PrecompileJobClass,
 ExtractAPIJobClass,
+InstallAPIJobClass,
 AnalyzeJobClass,
 Mig

[clang] [clang][InstallAPI] Introduce basic driver to write out tbd files (PR #81571)

2024-02-12 Thread Cyndy Ishida via cfe-commits

cyndyishida wrote:

In case anyone is interested, 
Here are relevant links for upstreaming `tapi` in LLVM: 
* [Inital 
RFC](https://discourse.llvm.org/t/rfc-open-sourcing-and-contributing-tapi-back-to-the-llvm-community/46214/24)
* [Continued 
RFC](https://discourse.llvm.org/t/rfc-continuation-of-tapi-into-llvm/52825)
* [Dev Talk](https://www.youtube.com/watch?v=B9li6EkD5zA)
* [Full TAPI sources](https://github.com/apple-oss-distributions/tapi), 
includes docs

https://github.com/llvm/llvm-project/pull/81571
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][InstallAPI] Introduce basic driver to write out tbd files (PR #81571)

2024-02-13 Thread Cyndy Ishida via cfe-commits


@@ -0,0 +1,65 @@
+//===- InstallAPI/Context.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Top level types for interacting with the generic clang driver and frontend
+// for InstallAPI operations.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
+#define LLVM_CLANG_INSTALLAPI_CONTEXT_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/TextAPI/InterfaceFile.h"
+#include "llvm/TextAPI/RecordVisitor.h"
+#include "llvm/TextAPI/RecordsSlice.h"
+
+namespace clang {
+namespace installapi {
+
+/// Struct used for generating validating InstallAPI.
+/// The attributes captured represent all necessary information
+/// to generate TextAPI output.
+struct InstallAPIContext {
+
+  /// Library attributes that are typically passed as linker inputs.
+  llvm::MachO::RecordsSlice::BinaryAttrs BA;
+
+  /// Active target triple to parse.
+  llvm::Triple TargetTriple{};
+
+  /// Output stream to write TextAPI file to.
+  std::unique_ptr OS = nullptr;
+
+  /// DiagnosticsEngine to report errors.
+  llvm::IntrusiveRefCntPtr Diags = nullptr;
+
+  /// File Path of output location.
+  StringRef OutputLoc{};
+
+  /// What encoding to write output as.
+  llvm::MachO::FileType FT = llvm::MachO::FileType::TBD_V5;

cyndyishida wrote:

Yes, `v5` is the default but will be configurable, I added it here now to 
layout the correct flow for emitting the TBD.

https://github.com/llvm/llvm-project/pull/81571
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][InstallAPI] Introduce basic driver to write out tbd files (PR #81571)

2024-02-13 Thread Cyndy Ishida via cfe-commits


@@ -4319,6 +4324,12 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 if (!MergerInputs.empty())
   Actions.push_back(
   C.MakeAction(MergerInputs, types::TY_Image));
+  } else if (Args.hasArg(options::OPT_installapi)) {
+assert(Inputs.size() == 1 && "InstallAPI action can only handle 1 input");

cyndyishida wrote:

This is temporary and will be lifted when we can handle multiple inputs. Worth 
noting though, that I'm going to keep the original `tapi` input style where we 
only accept directory structures or JSON input. 

https://github.com/llvm/llvm-project/pull/81571
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][InstallAPI] Introduce basic driver to write out tbd files (PR #81571)

2024-02-13 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/81571

>From 0f938ae8480f74a44bf6fe4aac6105e457315bb9 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 12 Feb 2024 20:53:25 -0800
Subject: [PATCH 1/2]  [clang][InstallAPI] Introduce basic driver to write out
 tbd files.

This introduces a basic outline of installapi as a clang driver option.
It captures relavant information as cc1 args, which is commonly
arguments already passed to the linker to encode into TBD file outputs.
This is effectively an upstream for what already exists as `tapi installapi` in
Xcode toolchains, but direclty in clang. This patch does not handle any AST 
traversing on input yet.

InstallAPI is broadly an operation thats takes a series of header files
that represent a single dynamic library and generates a TBD file out of
it which represents all the linkable symbols and necessary attributes for 
statically linking in clients.
It also will support verification where it compares all the information
recorded for the TBD file against the already built binary, to catch
possible mismatches like when an symbol export is missing a matching
declaration.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +
 clang/include/clang/Driver/Action.h   | 12 
 clang/include/clang/Driver/Options.td | 12 +++-
 clang/include/clang/Driver/Types.def  |  1 +
 .../include/clang/Frontend/CompilerInstance.h |  7 ++
 .../clang/Frontend/CompilerInvocation.h   |  9 ++-
 .../include/clang/Frontend/FrontendActions.h  | 10 +++
 .../include/clang/Frontend/FrontendOptions.h  |  3 +
 .../clang/Frontend/InstallAPIOptions.h| 28 
 clang/include/clang/InstallAPI/Context.h  | 65 +++
 clang/lib/CMakeLists.txt  |  1 +
 clang/lib/Driver/Action.cpp   |  7 ++
 clang/lib/Driver/Driver.cpp   | 15 -
 clang/lib/Driver/ToolChain.cpp|  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 11 
 clang/lib/Frontend/CMakeLists.txt |  2 +
 clang/lib/Frontend/CompilerInvocation.cpp | 41 +++-
 clang/lib/Frontend/InstallAPIConsumer.cpp | 43 
 .../ExecuteCompilerInvocation.cpp |  2 +
 clang/lib/InstallAPI/CMakeLists.txt   | 11 
 clang/lib/InstallAPI/Context.cpp  | 27 
 clang/test/CMakeLists.txt |  1 +
 clang/test/Driver/installapi.h| 13 
 clang/test/InstallAPI/installapi-basic.test   | 34 ++
 clang/test/lit.cfg.py |  2 +
 25 files changed, 356 insertions(+), 5 deletions(-)
 create mode 100644 clang/include/clang/Frontend/InstallAPIOptions.h
 create mode 100644 clang/include/clang/InstallAPI/Context.h
 create mode 100644 clang/lib/Frontend/InstallAPIConsumer.cpp
 create mode 100644 clang/lib/InstallAPI/CMakeLists.txt
 create mode 100644 clang/lib/InstallAPI/Context.cpp
 create mode 100644 clang/test/Driver/installapi.h
 create mode 100644 clang/test/InstallAPI/installapi-basic.test

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index b13181f6e70894..24cc17420c16cc 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -804,4 +804,7 @@ def warn_android_unversioned_fallback : Warning<
 
 def err_drv_triple_version_invalid : Error<
   "version '%0' in target triple '%1' is invalid">;
+
+def err_drv_installapi_unsupported : Error<
+  "the clang compiler does not support '%0' for InstallAPI">;
 }
diff --git a/clang/include/clang/Driver/Action.h 
b/clang/include/clang/Driver/Action.h
index 04fa8b01b418f8..2768e2f5df1a9e 100644
--- a/clang/include/clang/Driver/Action.h
+++ b/clang/include/clang/Driver/Action.h
@@ -59,6 +59,7 @@ class Action {
 PreprocessJobClass,
 PrecompileJobClass,
 ExtractAPIJobClass,
+InstallAPIJobClass,
 AnalyzeJobClass,
 MigrateJobClass,
 CompileJobClass,
@@ -448,6 +449,17 @@ class ExtractAPIJobAction : public JobAction {
   void addHeaderInput(Action *Input) { getInputs().push_back(Input); }
 };
 
+class InstallAPIJobAction : public JobAction {
+  void anchor() override;
+
+public:
+  InstallAPIJobAction(Action *Input, types::ID OutputType);
+
+  static bool classof(const Action *A) {
+return A->getKind() == InstallAPIJobClass;
+  }
+};
+
 class AnalyzeJobAction : public JobAction {
   void anchor() override;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 31e8571758bfce..52c892b8b7f82c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -309,6 +309,8 @@ class AnalyzerOpts
   : KeyPathAndMacro<"AnalyzerOpts->", base, "ANALYZER_"> {}
 class MigratorOpts
   : KeyPathAndMacro<"MigratorOpts.", base, "MIGRATOR_"> {}
+class InstallAPIOpts
+  : KeyPathAndMacro<"InstallAPIOpts.", bas

[clang] [clang][InstallAPI] Introduce basic driver to write out tbd files (PR #81571)

2024-02-13 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/81571
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ec5f4a4 - [InstallAPI] Add missing link to clangBasic

2024-02-13 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2024-02-13T18:59:18-08:00
New Revision: ec5f4a4bc6f27b044bc73668414ecefe9690d283

URL: 
https://github.com/llvm/llvm-project/commit/ec5f4a4bc6f27b044bc73668414ecefe9690d283
DIFF: 
https://github.com/llvm/llvm-project/commit/ec5f4a4bc6f27b044bc73668414ecefe9690d283.diff

LOG: [InstallAPI] Add missing link to clangBasic

Fixes CI.

Added: 


Modified: 
clang/lib/InstallAPI/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/InstallAPI/CMakeLists.txt 
b/clang/lib/InstallAPI/CMakeLists.txt
index b68d8fbbec1d37..1476b737c5e61c 100644
--- a/clang/lib/InstallAPI/CMakeLists.txt
+++ b/clang/lib/InstallAPI/CMakeLists.txt
@@ -8,4 +8,5 @@ add_clang_library(clangInstallAPI
 
   LINK_LIBS
   clangAST
+  clangBasic
   )



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Upstream visionOS Availability & DarwinSDKInfo APIs (PR #84279)

2024-03-06 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/84279

Admittedly a bit awkward, `visionos` is the correct and accepted spelling for 
annotating availability for xrOS target triples. This patch detects errors and 
handles cases when `xros` is mistakenly passed. 
In addition, add APIs for introduced/deprecated/obsoleted versioning in 
DarwinSDKInfo mappings.

>From 64ff809b6325c9b6d4f957c9bbc2d9ffc83eaa15 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 20:29:30 -0800
Subject: [PATCH 1/2] [clang] Support availability annotations for visionOS

Admittently a bit awkward, `visionos` is the correct and accepted
spelling for annotating availability for xros target triples. This patch
detects errors and handles cases when `xros` is mistakenly passed.
---
 clang/include/clang/Basic/Attr.td|  8 
 clang/lib/Parse/ParseDecl.cpp|  5 ++-
 clang/lib/Parse/ParseExpr.cpp|  3 +-
 clang/test/Sema/attr-availability-visionos.c | 39 
 4 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Sema/attr-availability-visionos.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fa191c7378dba4..ebb616fbe253fc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -983,6 +983,8 @@ def Availability : InheritableAttr {
  .Case("watchos_app_extension", "watchOS (App Extension)")
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
+ .Case("xros", "visionOS")
+ .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
  .Case("shadermodel", "HLSL ShaderModel")
  .Case("ohos", "OpenHarmony OS")
@@ -1000,6 +1002,8 @@ static llvm::StringRef 
getPlatformNameSourceSpelling(llvm::StringRef Platform) {
  .Case("watchos_app_extension", "watchOSApplicationExtension")
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", 
"macCatalystApplicationExtension")
+ .Case("xros", "visionOS")
+ .Case("xros_app_extension", "visionOSApplicationExtension")
  .Case("zos", "z/OS")
  .Case("shadermodel", "ShaderModel")
  .Default(Platform);
@@ -1016,6 +1020,10 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("watchOSApplicationExtension", "watchos_app_extension")
  .Case("macCatalyst", "maccatalyst")
  .Case("macCatalystApplicationExtension", 
"maccatalyst_app_extension")
+ .Case("visionOS", "xros")
+ .Case("visionOSApplicationExtension", "xros_app_extension")
+ .Case("visionos", "xros")
+ .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
 } }];
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 81f1c711269445..ee377b70964a28 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -1234,8 +1234,11 @@ void Parser::ParseAvailabilityAttribute(
   }
   IdentifierLoc *Platform = ParseIdentifierLoc();
   if (const IdentifierInfo *const Ident = Platform->Ident) {
+// Disallow xrOS for availability attributes.
+if (Ident->getName().contains("xrOS") || Ident->getName().contains("xros"))
+  Diag(Platform->Loc, diag::warn_availability_unknown_platform) << Ident;
 // Canonicalize platform name from "macosx" to "macos".
-if (Ident->getName() == "macosx")
+else if (Ident->getName() == "macosx")
   Platform->Ident = PP.getIdentifierInfo("macos");
 // Canonicalize platform name from "macosx_app_extension" to
 // "macos_app_extension".
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 4bf954b5cc4db5..1f07eddb0fb378 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3863,7 +3863,8 @@ std::optional 
Parser::ParseAvailabilitySpec() {
 StringRef Platform =
 AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
 
-if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
+if (AvailabilityAttr::getPrettyPlatformName(Platform).empty() ||
+(GivenPlatform.contains("xros") || GivenPlatform.contains("xrOS"))) {
   Diag(PlatformIdentifier->Loc,
diag::err_avail_query_unrecognized_platform_name)
   << GivenPlatform;
diff --git a/clang/test/Sema/attr-availability-visionos.c 
b/clang/test/Sema/attr-availability-visionos.c
new file mode 100644
index 00..2c388c5d529073
--- /dev/null
+++ b/clang/test/Sema/attr-availability-visionos.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple arm64-apple-xros1 -fapplication-extension 
-verify=visionos %s 2>&1
+
+__attribute__((

[clang] [clang] Upstream visionOS Availability & DarwinSDKInfo APIs (PR #84279)

2024-03-06 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/84279

>From 777edd2803f87308a6eb4119aacca792a8c62672 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 6 Mar 2024 20:29:30 -0800
Subject: [PATCH 1/2] [clang] Support availability annotations for visionOS

Admittently a bit awkward, `visionos` is the correct and accepted
spelling for annotating availability for xros target triples. This patch
detects errors and handles cases when `xros` is mistakenly passed.
---
 clang/include/clang/Basic/Attr.td |  8 
 clang/lib/Parse/ParseDecl.cpp |  5 ++-
 clang/lib/Parse/ParseExpr.cpp |  3 +-
 .../test/CodeGen/attr-availability-visionos.c | 10 +
 clang/test/Sema/attr-availability-visionos.c  | 39 +++
 5 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-availability-visionos.c
 create mode 100644 clang/test/Sema/attr-availability-visionos.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fa191c7378dba4..ebb616fbe253fc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -983,6 +983,8 @@ def Availability : InheritableAttr {
  .Case("watchos_app_extension", "watchOS (App Extension)")
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
+ .Case("xros", "visionOS")
+ .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
  .Case("shadermodel", "HLSL ShaderModel")
  .Case("ohos", "OpenHarmony OS")
@@ -1000,6 +1002,8 @@ static llvm::StringRef 
getPlatformNameSourceSpelling(llvm::StringRef Platform) {
  .Case("watchos_app_extension", "watchOSApplicationExtension")
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", 
"macCatalystApplicationExtension")
+ .Case("xros", "visionOS")
+ .Case("xros_app_extension", "visionOSApplicationExtension")
  .Case("zos", "z/OS")
  .Case("shadermodel", "ShaderModel")
  .Default(Platform);
@@ -1016,6 +1020,10 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("watchOSApplicationExtension", "watchos_app_extension")
  .Case("macCatalyst", "maccatalyst")
  .Case("macCatalystApplicationExtension", 
"maccatalyst_app_extension")
+ .Case("visionOS", "xros")
+ .Case("visionOSApplicationExtension", "xros_app_extension")
+ .Case("visionos", "xros")
+ .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
 } }];
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 81f1c711269445..ee377b70964a28 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -1234,8 +1234,11 @@ void Parser::ParseAvailabilityAttribute(
   }
   IdentifierLoc *Platform = ParseIdentifierLoc();
   if (const IdentifierInfo *const Ident = Platform->Ident) {
+// Disallow xrOS for availability attributes.
+if (Ident->getName().contains("xrOS") || Ident->getName().contains("xros"))
+  Diag(Platform->Loc, diag::warn_availability_unknown_platform) << Ident;
 // Canonicalize platform name from "macosx" to "macos".
-if (Ident->getName() == "macosx")
+else if (Ident->getName() == "macosx")
   Platform->Ident = PP.getIdentifierInfo("macos");
 // Canonicalize platform name from "macosx_app_extension" to
 // "macos_app_extension".
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 4bf954b5cc4db5..1f07eddb0fb378 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3863,7 +3863,8 @@ std::optional 
Parser::ParseAvailabilitySpec() {
 StringRef Platform =
 AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
 
-if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
+if (AvailabilityAttr::getPrettyPlatformName(Platform).empty() ||
+(GivenPlatform.contains("xros") || GivenPlatform.contains("xrOS"))) {
   Diag(PlatformIdentifier->Loc,
diag::err_avail_query_unrecognized_platform_name)
   << GivenPlatform;
diff --git a/clang/test/CodeGen/attr-availability-visionos.c 
b/clang/test/CodeGen/attr-availability-visionos.c
new file mode 100644
index 00..09b98fb4a7d5e3
--- /dev/null
+++ b/clang/test/CodeGen/attr-availability-visionos.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple arm64-apple-xros1 -emit-llvm -o - %s 2>&1 | 
FileCheck %s
+
+__attribute__((availability(visionOS, introduced=1.1)))
+void introduced_1_1();
+
+void use() {
+  if (__builtin_available(visionOS 1.2, *))
+introduced_1_1();
+  // CHECK: call i32 @__isPl

[clang] [clang] Upstream visionOS Availability & DarwinSDKInfo APIs (PR #84279)

2024-03-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/84279
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Collect global functions (PR #83952)

2024-03-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/83952

>From 580af4d537446637d44af03c147750af54eca05b Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 4 Mar 2024 10:46:18 -0800
Subject: [PATCH 1/2] [InstallAPI] Collect global functions

* Include whether functions are inlinable as they impact whether to add
  them into the tbd file and future verification.
* Fix how clang arguments got passed along, previously spacing was
  passed along to CC1 causing search paths to look non-existent.
---
 clang/include/clang/InstallAPI/Frontend.h |  5 +-
 clang/include/clang/InstallAPI/Visitor.h  |  3 +
 clang/lib/InstallAPI/Frontend.cpp |  2 +-
 clang/lib/InstallAPI/Visitor.cpp  | 78 +++
 clang/test/InstallAPI/functions.test  | 78 +++
 clang/tools/clang-installapi/Options.cpp  |  4 +-
 llvm/include/llvm/TextAPI/Record.h|  6 +-
 llvm/include/llvm/TextAPI/RecordsSlice.h  |  5 +-
 llvm/lib/TextAPI/RecordsSlice.cpp |  6 +-
 llvm/unittests/TextAPI/RecordTests.cpp|  3 +-
 10 files changed, 180 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/InstallAPI/functions.test

diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
index 8774321e990c13..cbc2b159ebd17a 100644
--- a/clang/include/clang/InstallAPI/Frontend.h
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -50,12 +50,15 @@ class FrontendRecordsSlice : public 
llvm::MachO::RecordsSlice {
   /// \param D The pointer to the declaration from traversing AST.
   /// \param Access The intended access level of symbol.
   /// \param Flags The flags that describe attributes of the symbol.
+  /// \param Inlined Whether declaration is inlined, only applicable to
+  /// functions.
   /// \return The non-owning pointer to added record in slice.
   GlobalRecord *addGlobal(StringRef Name, RecordLinkage Linkage,
   GlobalRecord::Kind GV,
   const clang::AvailabilityInfo Avail, const Decl *D,
   const HeaderType Access,
-  SymbolFlags Flags = SymbolFlags::None);
+  SymbolFlags Flags = SymbolFlags::None,
+  bool Inlined = false);
 
   /// Add ObjC Class record with attributes from AST.
   ///
diff --git a/clang/include/clang/InstallAPI/Visitor.h 
b/clang/include/clang/InstallAPI/Visitor.h
index ff0a9957aa86bc..71d4d9894f4205 100644
--- a/clang/include/clang/InstallAPI/Visitor.h
+++ b/clang/include/clang/InstallAPI/Visitor.h
@@ -37,6 +37,9 @@ class InstallAPIVisitor final : public ASTConsumer,
   /// Collect global variables.
   bool VisitVarDecl(const VarDecl *D);
 
+  /// Collect global functions.
+  bool VisitFunctionDecl(const FunctionDecl *D);
+
   /// Collect Objective-C Interface declarations.
   /// Every Objective-C class has an interface declaration that lists all the
   /// ivars, properties, and methods of the class.
diff --git a/clang/lib/InstallAPI/Frontend.cpp 
b/clang/lib/InstallAPI/Frontend.cpp
index 240a80e1d3d82c..efc634d80dd218 100644
--- a/clang/lib/InstallAPI/Frontend.cpp
+++ b/clang/lib/InstallAPI/Frontend.cpp
@@ -19,7 +19,7 @@ namespace clang::installapi {
 GlobalRecord *FrontendRecordsSlice::addGlobal(
 StringRef Name, RecordLinkage Linkage, GlobalRecord::Kind GV,
 const clang::AvailabilityInfo Avail, const Decl *D, const HeaderType 
Access,
-SymbolFlags Flags) {
+SymbolFlags Flags, bool Inlined) {
 
   auto *GR = llvm::MachO::RecordsSlice::addGlobal(Name, Linkage, GV, Flags);
   FrontendRecords.insert({GR, FrontendAttrs{Avail, D, Access}});
diff --git a/clang/lib/InstallAPI/Visitor.cpp b/clang/lib/InstallAPI/Visitor.cpp
index fbe6f1dabe005d..1f2ef08e5aa252 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/InstallAPI/Visitor.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/InstallAPI/Frontend.h"
 #include "llvm/ADT/SmallString.h"
@@ -27,6 +28,31 @@ static bool isExported(const NamedDecl *D) {
  (LV.getVisibility() == DefaultVisibility);
 }
 
+static bool isInlined(const FunctionDecl *D) {
+  bool HasInlineAttribute = false;
+  bool NoCXXAttr =
+  (!D->getASTContext().getLangOpts().CPlusPlus &&
+   !D->getASTContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+   !D->hasAttr());
+
+  // Check all redeclarations to find an inline attribute or keyword.
+  for (const auto *RD : D->redecls()) {
+if (!RD->isInlined())
+  continue;
+HasInlineAttribute = true;
+if (!(NoCXXAttr || RD->hasAttr()))
+  continue;
+if (RD->doesThisDeclarationHaveABody() &&
+RD->isInlineDefinitionExternallyVisible())
+  return false;
+  }
+
+  if (!HasInlineAttribute)
+return false;
+
+  return true;
+}
+

[clang] [llvm] [InstallAPI] Collect global functions (PR #83952)

2024-03-07 Thread Cyndy Ishida via cfe-commits


@@ -19,7 +19,7 @@ namespace clang::installapi {
 GlobalRecord *FrontendRecordsSlice::addGlobal(
 StringRef Name, RecordLinkage Linkage, GlobalRecord::Kind GV,
 const clang::AvailabilityInfo Avail, const Decl *D, const HeaderType 
Access,
-SymbolFlags Flags) {
+SymbolFlags Flags, bool Inlined) {

cyndyishida wrote:

Ah, thanks it's supposed to be passed along.

https://github.com/llvm/llvm-project/pull/83952
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [InstallAPI] Collect global functions (PR #83952)

2024-03-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/83952
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Add support for C++ headers (PR #84403)

2024-03-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/84403

This includes capturing symbols for global variables, functions, classes, and 
templated defintions. As pre-determing what symbols are generated from C++ 
declarations can be non-trivial, InstallAPI only parses select declarations for 
symbol generation when parsing c++.

For example, installapi only looks at explicit template instantiations or full 
template specializations, instead of general function or class templates, for 
symbol emittion.

>From 9068f8283df18ca8b3e39da67b9afa494847b6bf Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 4 Mar 2024 14:44:56 -0800
Subject: [PATCH] [InstallAPI] Add support for C++ headers

This includes capturing symbols for global variables, functions, classes, and 
templated defintions.
As pre-determing what symbols are generated from C++ declarations can be
non-trivial, InstallAPI only parses select declarations for symbol
generation when parsing c++.

For example, installapi only looks at explicit template instantiations
or full template specializations, instead of general function or class 
templates, for
symbol emittion.
---
 clang/include/clang/InstallAPI/Visitor.h |  14 +
 clang/lib/InstallAPI/Frontend.cpp|   4 +-
 clang/lib/InstallAPI/Visitor.cpp | 426 +-
 clang/test/InstallAPI/cpp.test   | 530 +++
 clang/tools/clang-installapi/Options.cpp |  33 +-
 clang/tools/clang-installapi/Options.h   |   7 +
 6 files changed, 1008 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/InstallAPI/cpp.test

diff --git a/clang/include/clang/InstallAPI/Visitor.h 
b/clang/include/clang/InstallAPI/Visitor.h
index 71d4d9894f4205..9ac948ded3e332 100644
--- a/clang/include/clang/InstallAPI/Visitor.h
+++ b/clang/include/clang/InstallAPI/Visitor.h
@@ -21,6 +21,7 @@
 #include "llvm/ADT/Twine.h"
 
 namespace clang {
+struct AvailabilityInfo;
 namespace installapi {
 
 /// ASTVisitor for collecting declarations that represent global symbols.
@@ -33,6 +34,7 @@ class InstallAPIVisitor final : public ASTConsumer,
 MC(ItaniumMangleContext::create(ASTCtx, ASTCtx.getDiagnostics())),
 Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {}
   void HandleTranslationUnit(ASTContext &ASTCtx) override;
+  bool shouldVisitTemplateInstantiations() const { return true; }
 
   /// Collect global variables.
   bool VisitVarDecl(const VarDecl *D);
@@ -51,9 +53,19 @@ class InstallAPIVisitor final : public ASTConsumer,
   /// is therefore itself not collected.
   bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
 
+  /// Collect global c++ declarations.
+  bool VisitCXXRecordDecl(const CXXRecordDecl *D);
+
 private:
   std::string getMangledName(const NamedDecl *D) const;
   std::string getBackendMangledName(llvm::Twine Name) const;
+  std::string getMangledCXXVTableName(const CXXRecordDecl *D) const;
+  std::string getMangledCXXThunk(const GlobalDecl &D,
+ const ThunkInfo &Thunk) const;
+  std::string getMangledCXXRTTI(const CXXRecordDecl *D) const;
+  std::string getMangledCXXRTTIName(const CXXRecordDecl *D) const;
+  std::string getMangledCtorDtor(const CXXMethodDecl *D, int Type) const;
+
   std::optional getAccessForDecl(const NamedDecl *D) const;
   void recordObjCInstanceVariables(
   const ASTContext &ASTCtx, llvm::MachO::ObjCContainerRecord *Record,
@@ -61,6 +73,8 @@ class InstallAPIVisitor final : public ASTConsumer,
   const llvm::iterator_range<
   DeclContext::specific_decl_iterator>
   Ivars);
+  void emitVTableSymbols(const CXXRecordDecl *D, const AvailabilityInfo &Avail,
+ const HeaderType Access, bool EmittedVTable = false);
 
   InstallAPIContext &Ctx;
   SourceManager &SrcMgr;
diff --git a/clang/lib/InstallAPI/Frontend.cpp 
b/clang/lib/InstallAPI/Frontend.cpp
index 1edbdf5bb98360..0d526fe1da6667 100644
--- a/clang/lib/InstallAPI/Frontend.cpp
+++ b/clang/lib/InstallAPI/Frontend.cpp
@@ -137,9 +137,9 @@ std::unique_ptr 
createInputBuffer(InstallAPIContext &Ctx) {
 else
   OS << "#import ";
 if (H.useIncludeName())
-  OS << "<" << H.getIncludeName() << ">";
+  OS << "<" << H.getIncludeName() << ">\n";
 else
-  OS << "\"" << H.getPath() << "\"";
+  OS << "\"" << H.getPath() << "\"\n";
 
 Ctx.addKnownHeader(H);
   }
diff --git a/clang/lib/InstallAPI/Visitor.cpp b/clang/lib/InstallAPI/Visitor.cpp
index 1f2ef08e5aa252..aded94f7a94a32 100644
--- a/clang/lib/InstallAPI/Visitor.cpp
+++ b/clang/lib/InstallAPI/Visitor.cpp
@@ -7,7 +7,9 @@
 
//===--===//
 
 #include "clang/InstallAPI/Visitor.h"
+#include "clang/AST/Availability.h"
 #include "clang/AST/ParentMapContext.h"
+#include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/InstallAPI/Frontend.h"
 #include "llvm/ADT/SmallString.h"
@@ -18,6 +20,15 @@
 using n

[clang] [InstallAPI] Add support for C++ headers (PR #84403)

2024-03-07 Thread Cyndy Ishida via cfe-commits

cyndyishida wrote:

Looks like I made the mistake of deleting the target branch for PR: 
https://github.com/llvm/llvm-project/pull/83953 before updating it. Anyway, I 
applied @ributzka's forward declaration's suggestion. 

https://github.com/llvm/llvm-project/pull/84403
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Collect C++ Decls (PR #84403)

2024-03-07 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida edited 
https://github.com/llvm/llvm-project/pull/84403
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Collect C++ Decls (PR #84403)

2024-03-11 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/84403
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Break up headers and add common header for TextAPI types (PR #84960)

2024-03-12 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/84960

Before it gets too unwieldy, add a common header for all MachO types that are 
used across InstallAPI. Also, break up the types in `InstallAPI/Frontend`. This 
both avoids circular dependencies and is logically easier to maintain as more 
functionality gets added.

>From 8fd706b935b1cdf75ace5f4882a512d38d5d557e Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 12 Mar 2024 10:35:50 -0700
Subject: [PATCH] [InstallAPI] Break up headers and add common header for
 TextAPI types

Before it gets too unwieldy, add a common header for all MachO types
that are used across InstallAPI. Also break up the types in
InstallAPI/Frontend. This both avoids circular dependencies and
logically easier to maintain as more functionality gets added.
---
 clang/include/clang/InstallAPI/Context.h  |   6 +-
 clang/include/clang/InstallAPI/Frontend.h |  94 ---
 .../clang/InstallAPI/FrontendRecords.h| 108 ++
 clang/include/clang/InstallAPI/MachO.h|  40 +++
 clang/lib/InstallAPI/Frontend.cpp |   1 +
 clang/lib/InstallAPI/Visitor.cpp  |   2 +-
 .../clang-installapi/ClangInstallAPI.cpp  |   6 +-
 clang/tools/clang-installapi/Options.h|  12 +-
 8 files changed, 159 insertions(+), 110 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/FrontendRecords.h
 create mode 100644 clang/include/clang/InstallAPI/MachO.h

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 4e9e90e5d2dbec..bdb576d7d85fb6 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -12,8 +12,8 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/InstallAPI/HeaderFile.h"
+#include "clang/InstallAPI/MachO.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/TextAPI/InterfaceFile.h"
 
 namespace clang {
 namespace installapi {
@@ -25,7 +25,7 @@ class FrontendRecordsSlice;
 struct InstallAPIContext {
 
   /// Library attributes that are typically passed as linker inputs.
-  llvm::MachO::RecordsSlice::BinaryAttrs BA;
+  BinaryAttrs BA;
 
   /// All headers that represent a library.
   HeaderSeq InputHeaders;
@@ -49,7 +49,7 @@ struct InstallAPIContext {
   llvm::StringRef OutputLoc{};
 
   /// What encoding to write output as.
-  llvm::MachO::FileType FT = llvm::MachO::FileType::TBD_V5;
+  FileType FT = FileType::TBD_V5;
 
   /// Populate entries of headers that should be included for TextAPI
   /// generation.
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
index cbc2b159ebd17a..873cb50d60a542 100644
--- a/clang/include/clang/InstallAPI/Frontend.h
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -25,100 +25,6 @@
 namespace clang {
 namespace installapi {
 
-using SymbolFlags = llvm::MachO::SymbolFlags;
-using RecordLinkage = llvm::MachO::RecordLinkage;
-using GlobalRecord = llvm::MachO::GlobalRecord;
-using ObjCContainerRecord = llvm::MachO::ObjCContainerRecord;
-using ObjCInterfaceRecord = llvm::MachO::ObjCInterfaceRecord;
-using ObjCCategoryRecord = llvm::MachO::ObjCCategoryRecord;
-using ObjCIVarRecord = llvm::MachO::ObjCIVarRecord;
-
-// Represents a collection of frontend records for a library that are tied to a
-// darwin target triple.
-class FrontendRecordsSlice : public llvm::MachO::RecordsSlice {
-public:
-  FrontendRecordsSlice(const llvm::Triple &T)
-  : llvm::MachO::RecordsSlice({T}) {}
-
-  /// Add non-ObjC global record with attributes from AST.
-  ///
-  /// \param Name The name of symbol.
-  /// \param Linkage The linkage of symbol.
-  /// \param GV The kind of global.
-  /// \param Avail The availability information tied to the active target
-  /// triple.
-  /// \param D The pointer to the declaration from traversing AST.
-  /// \param Access The intended access level of symbol.
-  /// \param Flags The flags that describe attributes of the symbol.
-  /// \param Inlined Whether declaration is inlined, only applicable to
-  /// functions.
-  /// \return The non-owning pointer to added record in slice.
-  GlobalRecord *addGlobal(StringRef Name, RecordLinkage Linkage,
-  GlobalRecord::Kind GV,
-  const clang::AvailabilityInfo Avail, const Decl *D,
-  const HeaderType Access,
-  SymbolFlags Flags = SymbolFlags::None,
-  bool Inlined = false);
-
-  /// Add ObjC Class record with attributes from AST.
-  ///
-  /// \param Name The name of class, not symbol.
-  /// \param Linkage The linkage of symbol.
-  /// \param Avail The availability information tied to the active target
-  /// triple.
-  /// \param D The pointer to the declaration from traversing AST.
-  /// \param Access The intended access level of symbol.
-  /// \param IsEHType Whether declaration has 

[clang] [InstallAPI] Break up headers and add common header for TextAPI types (PR #84960)

2024-03-12 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida closed 
https://github.com/llvm/llvm-project/pull/84960
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From b0cc1eeba893c24d5358cb49189da2e287daf972 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 78 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 474 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext &Ctx);
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice &Records)
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice &Records;
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/incl

[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From b0cc1eeba893c24d5358cb49189da2e287daf972 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH 1/2] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 78 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 474 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext &Ctx);
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice &Records)
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice &Records;
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/

[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From b0cc1eeba893c24d5358cb49189da2e287daf972 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH 1/2] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 78 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 474 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext &Ctx);
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice &Records)
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice &Records;
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/

[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-27 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From a7d0c1cf15764ee2ccbeb609fbaf014fdbde81b1 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 77 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 473 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..292992908aa129 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Records;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext &Ctx);
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice &Records)
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice &Records;
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/incl

[clang] [InstallAPI] Hookup Input files & basic ASTVisitor (PR #82552)

2024-02-28 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/82552

>From ab971dc5d38808fc884d39112b68675cf9ce3868 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 21 Feb 2024 14:56:02 -0800
Subject: [PATCH] [InstallAPI] Hookup Input files & basic ASTVisitor

This patch takes in json files as input to determine that header files to 
process, and in which order, to pass along for CC1 invocations.
This patch also includes an ASTVisitor to collect simple global variables.
---
 clang/include/clang/InstallAPI/Context.h  | 22 -
 clang/include/clang/InstallAPI/Frontend.h | 48 ++
 clang/include/clang/InstallAPI/HeaderFile.h   | 23 +
 clang/include/clang/InstallAPI/Visitor.h  | 51 ++
 clang/lib/InstallAPI/CMakeLists.txt   |  3 +
 clang/lib/InstallAPI/Frontend.cpp | 58 
 clang/lib/InstallAPI/Visitor.cpp  | 94 +++
 clang/test/InstallAPI/basic.test  |  5 +
 clang/test/InstallAPI/variables.test  | 63 +
 .../clang-installapi/ClangInstallAPI.cpp  | 76 +--
 clang/tools/clang-installapi/Options.cpp  | 29 ++
 clang/tools/clang-installapi/Options.h|  8 ++
 12 files changed, 472 insertions(+), 8 deletions(-)
 create mode 100644 clang/include/clang/InstallAPI/Frontend.h
 create mode 100644 clang/include/clang/InstallAPI/Visitor.h
 create mode 100644 clang/lib/InstallAPI/Frontend.cpp
 create mode 100644 clang/lib/InstallAPI/Visitor.cpp
 create mode 100644 clang/test/InstallAPI/variables.test

diff --git a/clang/include/clang/InstallAPI/Context.h 
b/clang/include/clang/InstallAPI/Context.h
index 7d105920734fde..3e2046642c7fe8 100644
--- a/clang/include/clang/InstallAPI/Context.h
+++ b/clang/include/clang/InstallAPI/Context.h
@@ -9,6 +9,9 @@
 #ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
 #define LLVM_CLANG_INSTALLAPI_CONTEXT_H
 
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/InstallAPI/HeaderFile.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/RecordVisitor.h"
 #include "llvm/TextAPI/RecordsSlice.h"
@@ -24,8 +27,23 @@ struct InstallAPIContext {
   /// Library attributes that are typically passed as linker inputs.
   llvm::MachO::RecordsSlice::BinaryAttrs BA;
 
-  /// Active target triple to parse.
-  llvm::Triple TargetTriple{};
+  /// All headers that represent a library.
+  HeaderSeq InputHeaders;
+
+  /// Active language mode to parse in.
+  Language LangMode = Language::ObjC;
+
+  /// Active header access type.
+  HeaderType Type = HeaderType::Unknown;
+
+  /// Active TargetSlice for symbol record collection.
+  std::shared_ptr Slice;
+
+  /// FileManager for all I/O operations.
+  FileManager *FM = nullptr;
+
+  /// DiagnosticsEngine for all error reporting.
+  DiagnosticsEngine *Diags = nullptr;
 
   /// File Path of output location.
   llvm::StringRef OutputLoc{};
diff --git a/clang/include/clang/InstallAPI/Frontend.h 
b/clang/include/clang/InstallAPI/Frontend.h
new file mode 100644
index 00..7ee87ae028d079
--- /dev/null
+++ b/clang/include/clang/InstallAPI/Frontend.h
@@ -0,0 +1,48 @@
+//===- InstallAPI/Frontend.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// Top level wrappers for InstallAPI frontend operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_INSTALLAPI_FRONTEND_H
+#define LLVM_CLANG_INSTALLAPI_FRONTEND_H
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/InstallAPI/Context.h"
+#include "clang/InstallAPI/Visitor.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace clang {
+namespace installapi {
+
+/// Create a buffer that contains all headers to scan
+/// for global symbols with.
+std::unique_ptr
+createInputBuffer(const InstallAPIContext &Ctx);
+
+class InstallAPIAction : public ASTFrontendAction {
+public:
+  explicit InstallAPIAction(llvm::MachO::RecordsSlice &Records)
+  : Records(Records) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override {
+return std::make_unique(CI.getASTContext(), Records);
+  }
+
+private:
+  llvm::MachO::RecordsSlice &Records;
+};
+} // namespace installapi
+} // namespace clang
+
+#endif // LLVM_CLANG_INSTALLAPI_FRONTEND_H
diff --git a/clang/include/clang/InstallAPI/HeaderFile.h 
b/clang/include/clang/InstallAPI/HeaderFile.h
index fc64a43b3def5c..70e83bbb3e76f6 100644
--- a/clang/include/clang/InstallAPI/HeaderFile.h
+++ b/clang/includ

  1   2   3   4   >