[clang] [Clang][AST] Print attributes of Obj-C interfaces (PR #84772)

Egor Zhdan via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 11 08:21:49 PDT 2024


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

When pretty printing an Objective-C interface declaration, Clang previously didn't print any attributes that are applied to the declaration.

>From 71ce3d88b229ff604dff64172d1fd9bcc18d32ea Mon Sep 17 00:00:00 2001
From: Egor Zhdan <e_zhdan at apple.com>
Date: Mon, 11 Mar 2024 15:19:56 +0000
Subject: [PATCH] [Clang][AST] Print attributes of Obj-C interfaces

When pretty printing an Objective-C interface declaration, Clang previously didn't print any attributes that are applied to the declaration.
---
 clang/lib/AST/DeclPrinter.cpp         | 5 +++++
 clang/test/AST/ast-print-objectivec.m | 8 ++++++++
 2 files changed, 13 insertions(+)

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;
 



More information about the cfe-commits mailing list