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

Egor Zhdan via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 11 06:38:48 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:

Nice!

> I am not sure if unspecified should have the semantics of removing safe/unsafe annotations.

I think it would make sense to be consistent with the nullability annotations here. I wonder if e.g. overriding the nullability specifier of a function parameter via API Notes would have a similar effect.

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


More information about the cfe-commits mailing list