[clang] [APINotes] Support `SwiftImportAs` for C++ structs (PR #65323)

2023-09-07 Thread Egor Zhdan via cfe-commits

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


[clang] [APINotes] Support `SwiftImportAs` for C++ structs (PR #65323)

2023-09-06 Thread Saleem Abdulrasool via cfe-commits

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


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


[clang] [APINotes] Support `SwiftImportAs` for C++ structs (PR #65323)

2023-09-05 Thread Egor Zhdan via cfe-commits

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


[clang] [APINotes] Support `SwiftImportAs` for C++ structs (PR #65323)

2023-09-05 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan created 
https://github.com/llvm/llvm-project/pull/65323:

This upstreams a few Clang API Notes attributes that were recently added 
downstream in the Apple fork (https://github.com/apple/llvm-project/pull/7386).

>From c0f45f6dcb2fc142df4f2f0ea30c03881b2126d7 Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Tue, 5 Sep 2023 14:02:04 +0100
Subject: [PATCH] [APINotes] Support `SwiftImportAs` for C++ structs

This upstreams a few Clang API Notes attributes that were recently added 
downstream in the Apple fork (https://github.com/apple/llvm-project/pull/7386).
---
 clang/include/clang/APINotes/Types.h| 14 
 clang/lib/APINotes/APINotesFormat.h |  2 +-
 clang/lib/APINotes/APINotesWriter.cpp   | 24 -
 clang/lib/APINotes/APINotesYAMLCompiler.cpp |  6 ++
 4 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index 79c8079191fef3b..354458588e30932 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -660,6 +660,10 @@ class TagInfo : public CommonTypeInfo {
   unsigned IsFlagEnum : 1;
 
 public:
+  std::optional SwiftImportAs;
+  std::optional SwiftRetainOp;
+  std::optional SwiftReleaseOp;
+
   std::optional EnumExtensibility;
 
   TagInfo() : HasFlagEnum(0), IsFlagEnum(0) {}
@@ -677,6 +681,13 @@ class TagInfo : public CommonTypeInfo {
   TagInfo |=(const TagInfo ) {
 static_cast(*this) |= RHS;
 
+if (!SwiftImportAs)
+  SwiftImportAs = RHS.SwiftImportAs;
+if (!SwiftRetainOp)
+  SwiftRetainOp = RHS.SwiftRetainOp;
+if (!SwiftReleaseOp)
+  SwiftReleaseOp = RHS.SwiftReleaseOp;
+
 if (!HasFlagEnum)
   setFlagEnum(RHS.isFlagEnum());
 
@@ -693,6 +704,9 @@ class TagInfo : public CommonTypeInfo {
 
 inline bool operator==(const TagInfo , const TagInfo ) {
   return static_cast(LHS) == RHS &&
+ LHS.SwiftImportAs == RHS.SwiftImportAs &&
+ LHS.SwiftRetainOp == RHS.SwiftRetainOp &&
+ LHS.SwiftReleaseOp == RHS.SwiftReleaseOp &&
  LHS.isFlagEnum() == RHS.isFlagEnum() &&
  LHS.EnumExtensibility == RHS.EnumExtensibility;
 }
diff --git a/clang/lib/APINotes/APINotesFormat.h 
b/clang/lib/APINotes/APINotesFormat.h
index b52f017901dbcab..5897b45d3796d0e 100644
--- a/clang/lib/APINotes/APINotesFormat.h
+++ b/clang/lib/APINotes/APINotesFormat.h
@@ -24,7 +24,7 @@ const uint16_t VERSION_MAJOR = 0;
 /// API notes file minor version number.
 ///
 /// When the format changes IN ANY WAY, this number should be incremented.
-const uint16_t VERSION_MINOR = 24; // EnumExtensibility + FlagEnum
+const uint16_t VERSION_MINOR = 25; // SwiftImportAs
 
 using IdentifierID = llvm::PointerEmbeddedInt;
 using IdentifierIDField = llvm::BCVBR<16>;
diff --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index 0126c5ec0798dc5..a92b379a8e56acb 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -1124,7 +1124,10 @@ class CommonTypeTableInfo
 class TagTableInfo : public CommonTypeTableInfo {
 public:
   unsigned getUnversionedInfoSize(const TagInfo ) {
-return 1 + getCommonTypeInfoSize(TI);
+return 2 + (TI.SwiftImportAs ? TI.SwiftImportAs->size() : 0) +
+   2 + (TI.SwiftRetainOp ? TI.SwiftRetainOp->size() : 0) +
+   2 + (TI.SwiftReleaseOp ? TI.SwiftReleaseOp->size() : 0) +
+   1 + getCommonTypeInfoSize(TI);
   }
 
   void emitUnversionedInfo(raw_ostream , const TagInfo ) {
@@ -1142,6 +1145,25 @@ class TagTableInfo : public 
CommonTypeTableInfo {
 
 writer.write(Flags);
 
+if (auto ImportAs = TI.SwiftImportAs) {
+  writer.write(ImportAs->size() + 1);
+  OS.write(ImportAs->c_str(), ImportAs->size());
+} else {
+  writer.write(0);
+}
+if (auto RetainOp = TI.SwiftRetainOp) {
+  writer.write(RetainOp->size() + 1);
+  OS.write(RetainOp->c_str(), RetainOp->size());
+} else {
+  writer.write(0);
+}
+if (auto ReleaseOp = TI.SwiftReleaseOp) {
+  writer.write(ReleaseOp->size() + 1);
+  OS.write(ReleaseOp->c_str(), ReleaseOp->size());
+} else {
+  writer.write(0);
+}
+
 emitCommonTypeInfo(OS, TI);
   }
 };
diff --git a/clang/lib/APINotes/APINotesYAMLCompiler.cpp 
b/clang/lib/APINotes/APINotesYAMLCompiler.cpp
index e430956e28d0808..647455111214c59 100644
--- a/clang/lib/APINotes/APINotesYAMLCompiler.cpp
+++ b/clang/lib/APINotes/APINotesYAMLCompiler.cpp
@@ -410,6 +410,9 @@ struct Tag {
   std::optional SwiftPrivate;
   std::optional SwiftBridge;
   std::optional NSErrorDomain;
+  std::optional SwiftImportAs;
+  std::optional SwiftRetainOp;
+  std::optional SwiftReleaseOp;
   std::optional EnumExtensibility;
   std::optional FlagEnum;
   std::optional EnumConvenienceKind;
@@ -440,6 +443,9 @@ template <> struct MappingTraits {
 IO.mapOptional("SwiftName", T.SwiftName, StringRef(""));
 

[clang] [APINotes] Support `SwiftImportAs` for C++ structs (PR #65323)

2023-09-05 Thread Egor Zhdan via cfe-commits

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


[clang] [APINotes] Support `SwiftImportAs` for C++ structs (PR #65323)

2023-09-05 Thread Egor Zhdan via cfe-commits

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