[clang] [Clang] Fix isWeakImported() to traverse redeclaration chain for avai… (PR #181482)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 4 20:01:11 PDT 2026


================
@@ -3647,11 +3620,16 @@ void mergeInheritableAttributes(ASTReader &Reader, Decl *D, Decl *Previous) {
     D->addAttr(NewAttr);
   }
 
-  const auto *AA = Previous->getAttr<AvailabilityAttr>();
-  if (AA && !D->hasAttr<AvailabilityAttr>()) {
-    NewAttr = AA->clone(Context);
-    NewAttr->setInherited(true);
-    D->addAttr(NewAttr);
+  // getAttr<AvailabilityAttr>() only returns the first match, but a
+  // declaration can carry multiple AvailabilityAttrs (one per platform,
+  // e.g. macos + ios).  Iterate over all of them so every platform's
+  // availability is propagated to the new redeclaration.
----------------
kevinlzh1108 wrote:

> I think it is better to drop this comment as it doesn't add much value (and takes lots of space compared to the actual code).
> 
> Specifically, "Iterate over all of them[...]" redundantly repeats the actual implementation. Agree that "[...]only returns the first match[...]" is a "why" comment but in this case it seems to be simple enough not to warrant an explanation in the code. It seems more appropriate to have such information in the commit message.

Done. Removed the comment and updated the commit message — the explanation now lives there instead. Thanks for the review!

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


More information about the cfe-commits mailing list