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

via cfe-commits cfe-commits at lists.llvm.org
Sat May 2 01:52:48 PDT 2026


================
@@ -0,0 +1,8 @@
+// Mimics a class like UTType that has availability attrs for multiple platforms.
+// The 'macos' attr comes before 'ios', so getAttr<AvailabilityAttr>() returns
+// 'macos' first. When mergeInheritableAttributes copies only the first attr
+// across PCM boundaries, the 'ios' attr is lost on the @class redeclaration.
----------------
kevinlzh1108 wrote:

> The check `!D->hasAttr<AvailabilityAttr>()` is indeed incorrect but let's not increase the scope of this fix.

Done. I've narrowed the change to only ASTReaderDecl.cpp and updated the test:

  - **Dropped DeclBase.cpp** — as you pointed out, the Sema path already handles this correctly via `mergeDeclAttributes` + `specific_attrs<InheritableAttr>()`. The PCM path is the only one that needs fixing.
  - **Extended `decl-attr-merge.mm`** instead of adding a new test file — added `availability(ios, introduced=14.0)` to the existing `@interface INIntent` and an iOS triple RUN line.

  Re: `!D->hasAttr<AvailabilityAttr>()` — agreed it's not correct (if D has only some platform attrs, propagation from Previous is wrongly skipped for the missing ones), but as you said that's a separate issue. The `getAttr` →
  `specific_attrs` fix here is the right scope for this PR.

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


More information about the cfe-commits mailing list