[clang] [APINotes] Support annotating safety of APIs (PR #157506)

Egor Zhdan via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 9 03:15:35 PDT 2025


================
@@ -291,6 +292,13 @@ static void ProcessAPINotes(Sema &S, Decl *D,
         });
   }
 
+  // swift_safety
+  if (auto SafetyKind = Info.getSwiftSafety();
+      SafetyKind != api_notes::SwiftSafetyKind::None)
+    D->addAttr(SwiftAttrAttr::Create(
+        S.Context,
+        SafetyKind == api_notes::SwiftSafetyKind::Safe ? "safe" : "unsafe"));
----------------
egorzhdan wrote:

Would this work with versioned API Notes, or when trying to override an attribute already specified in the header?

Could you please add a couple of tests:
* a decl in the header is annotated as `safe` or `unsafe`, and the API Notes says `unspecified`
* a decl is annotated as `unsafe` pre-Swift 6 and `unspecified` in Swift 6 and newer

https://github.com/llvm/llvm-project/pull/157506


More information about the cfe-commits mailing list