[clang] [Clang][AST] Print attributes of Obj-C interfaces (PR #84772)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 11 08:22:17 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Egor Zhdan (egorzhdan)
<details>
<summary>Changes</summary>
When pretty printing an Objective-C interface declaration, Clang previously didn't print any attributes that are applied to the declaration.
---
Full diff: https://github.com/llvm/llvm-project/pull/84772.diff
2 Files Affected:
- (modified) clang/lib/AST/DeclPrinter.cpp (+5)
- (modified) clang/test/AST/ast-print-objectivec.m (+8)
``````````diff
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 43d221968ea3fb..b701581b2474a9 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1517,6 +1517,11 @@ void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
return;
}
bool eolnOut = false;
+ if (OID->hasAttrs()) {
+ prettyPrintAttributes(OID);
+ Out << "\n";
+ }
+
Out << "@interface " << I;
if (auto TypeParams = OID->getTypeParamListAsWritten()) {
diff --git a/clang/test/AST/ast-print-objectivec.m b/clang/test/AST/ast-print-objectivec.m
index 05a0a5d4aa74c4..a0652f38e713fa 100644
--- a/clang/test/AST/ast-print-objectivec.m
+++ b/clang/test/AST/ast-print-objectivec.m
@@ -21,6 +21,10 @@ - (void)MethI __attribute__((availability(macosx,introduced=10.1.0,deprecated=10
- (void)methodWithArg:(int)x andAnotherOne:(int)y { }
@end
+__attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)))
+ at interface InterfaceWithAttribute
+ at end
+
// CHECK: @protocol P
// CHECK: - (void)MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)));
// CHECK: @end
@@ -45,6 +49,10 @@ - (void)methodWithArg:(int)x andAnotherOne:(int)y { }
// CHECK: @end
+// CHECK: __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)))
+// CHECK: @interface InterfaceWithAttribute
+// CHECK: @end
+
@class C1;
struct __attribute__((objc_bridge_related(C1,,))) S1;
``````````
</details>
https://github.com/llvm/llvm-project/pull/84772
More information about the cfe-commits
mailing list