================
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios12.0 -emit-llvm -o - %s | FileCheck 
%s
+
+// Test that isWeakImported() correctly traverses the redeclaration chain
+// to find availability attributes, even when a forward declaration (@class)
+// without availability attributes becomes the most recent declaration.
+
+// Case 1: @interface (with availability) first, then @class (without 
availability).
+// The @class becomes getMostRecentDecl(). Without the fix, isWeakImported()
+// would only check the @class's attributes and miss the availability 
attribute,
+// resulting in strong linkage instead of extern_weak.
+
+__attribute__((availability(ios,introduced=14.0)))
+@interface WeakRedecl1
+@end
+
+@class WeakRedecl1;
+
+@implementation WeakRedecl1 (TestCategory1)
+@end
+
+// CHECK: @"OBJC_CLASS_$_WeakRedecl1" = extern_weak global
----------------
localspook wrote:

When I run stock clang 22.1.2 (i.e., one that doesn't include this fix) on the 
following `foo.mm`:
```cpp
__attribute__((availability(ios,introduced=14.0)))
@interface WeakRedecl1
@end

@class WeakRedecl1;

@implementation WeakRedecl1 (TestCategory1)
@end
```
```sh
clang++ foo.mm -target arm64-apple-ios12.0 -emit-llvm -S -o -
```
I already see `@"OBJC_CLASS_$_WeakRedecl1" = extern_weak global 
%struct._class_t` in the output. Are you sure this is a valid reduction? It 
looks like you may need to mimic the setup with modules in the original issue.




https://github.com/llvm/llvm-project/pull/181482
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to