Skip to content

Commit 81368e2

Browse files
committed
[API Notes] Attach API notes to forward declarations of tags
Forward declarations can still have useful API notes applied to them. Fixes rdar://156288588.
1 parent 1e325b7 commit 81368e2

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19085,6 +19085,10 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1908519085
// record.
1908619086
AddPushedVisibilityAttribute(New);
1908719087

19088+
// If this is not a definition, process API notes for it now.
19089+
if (TUK != TagUseKind::Definition)
19090+
ProcessAPINotes(New);
19091+
1908819092
if (isMemberSpecialization && !New->isInvalidDecl())
1908919093
CompleteMemberSpecialization(New, Previous);
1909019094

clang/test/APINotes/Inputs/Headers/SwiftImportAs.apinotes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Tags:
1414
SwiftReleaseOp: RCRelease
1515
SwiftRetainOp: RCRetain
1616
SwiftConformsTo: MySwiftModule.MySwiftRefCountedProtocol
17+
- Name: OpaqueRefCountedType
18+
SwiftImportAs: reference
19+
SwiftReleaseOp: ORCRelease
20+
SwiftRetainOp: ORCRetain
1721
- Name: NonCopyableType
1822
SwiftCopyable: false
1923
SwiftConformsTo: MySwiftModule.MySwiftNonCopyableProtocol

clang/test/APINotes/Inputs/Headers/SwiftImportAs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ struct CopyableType { int value; };
1919

2020
struct NonEscapableType { int value; };
2121
struct EscapableType { int value; };
22+
23+
24+
struct OpaqueRefCountedType;
25+
26+
inline void ORCRetain(struct OpaqueRefCountedType *x);
27+
inline void ORCRelease(struct OpaqueRefCountedType *x);

clang/test/APINotes/swift-import-as.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers %s -x c++
33
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers %s -x c++ -ast-dump -ast-dump-filter ImmortalRefType | FileCheck -check-prefix=CHECK-IMMORTAL %s
44
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers %s -x c++ -ast-dump -ast-dump-filter RefCountedType | FileCheck -check-prefix=CHECK-REF-COUNTED %s
5+
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers %s -x c++ -ast-dump -ast-dump-filter OpaqueRefCountedType | FileCheck -check-prefix=CHECK-OPAQUE-REF-COUNTED %s
56
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers %s -x c++ -ast-dump -ast-dump-filter NonCopyableType | FileCheck -check-prefix=CHECK-NON-COPYABLE %s
67
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers %s -x c++ -ast-dump -ast-dump-filter CopyableType | FileCheck -check-prefix=CHECK-COPYABLE %s
78
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers %s -x c++ -ast-dump -ast-dump-filter NonEscapableType | FileCheck -check-prefix=CHECK-NON-ESCAPABLE %s
@@ -26,6 +27,12 @@
2627
// CHECK-REF-COUNTED: SwiftAttrAttr {{.+}} <<invalid sloc>> "release:RCRelease"
2728
// CHECK-REF-COUNTED: SwiftAttrAttr {{.+}} <<invalid sloc>> "conforms_to:MySwiftModule.MySwiftRefCountedProtocol"
2829

30+
// CHECK-OPAQUE-REF-COUNTED: Dumping OpaqueRefCountedType:
31+
// CHECK-OPAQUE-REF-COUNTED-NEXT: CXXRecordDecl {{.+}} imported in SwiftImportAs{{.*}}struct OpaqueRefCountedType
32+
// CHECK-OPAQUE-REF-COUNTED: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_reference"
33+
// CHECK-OPAQUE-REF-COUNTED: SwiftAttrAttr {{.+}} <<invalid sloc>> "retain:ORCRetain"
34+
// CHECK-OPAQUE-REF-COUNTED: SwiftAttrAttr {{.+}} <<invalid sloc>> "release:ORCRelease"
35+
2936
// CHECK-NON-COPYABLE: Dumping NonCopyableType:
3037
// CHECK-NON-COPYABLE-NEXT: CXXRecordDecl {{.+}} imported in SwiftImportAs {{.+}} struct NonCopyableType
3138
// CHECK-NON-COPYABLE: SwiftAttrAttr {{.+}} <<invalid sloc>> "conforms_to:MySwiftModule.MySwiftNonCopyableProtocol"

0 commit comments

Comments
 (0)