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

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 01:01:11 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:

Thanks for looking into this @vsapsai 

  The `mergeDeclAttributes` → `mergeDeclAttribute` → `mergeAvailabilityAttr` chain in Sema actually works correctly — within a single TU, all availability attrs are properly merged from `@interface` to `@class`. The bug doesn't manifest in the
  single-TU case.

  The incomplete propagation happens in the **cross-module deserialization** path: `mergeInheritableAttributes()` in `ASTReaderDecl.cpp` (called from `attachPreviousDecl()`). It uses `getAttr<AvailabilityAttr>()` which returns only the **first**
   `AvailabilityAttr`, so when `@interface` has multiple platform attrs (e.g. `macos`, `ios`, `watchos`...), only the first one gets copied to the `@class` from the other module.

  I agree with both you and @localspook that fixing the root cause in `mergeInheritableAttributes` is the better approach. Happy to pivot to that fix, or do both. What do you think?

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


More information about the cfe-commits mailing list