libobjc2 icon indicating copy to clipboard operation
libobjc2 copied to clipboard

Add returns-retained annotation to class_createInstance.

Open davidchisnall opened this issue 1 year ago • 2 comments

davidchisnall avatar Jul 25 '22 08:07 davidchisnall

I'm a bit confused. With this change, clang generates the right IR for me. The error is coming from C files, where id is struct objc_object* and so isn't treated as an Objective-C type. We should gate that attribute on defined(__OBJC__).

davidchisnall avatar Jul 28 '22 12:07 davidchisnall

Sorry, you are correct. The change does fix the issue mentioned in https://github.com/llvm/llvm-project/issues/56056.

Also using #if defined(__OBJC__) && __has_attribute(ns_returns_retained) will fix the warnings.

I was looking at another crash with LLVM 14 when accessing GNUstep Base classes for the first time (e.g. calling [NSUserDefaults standardUserDefaults] crashes in _objc_block_trampoline_end_sret), which I incorrectly thought was the same issue. I will look into that in more detail and report it separately.

triplef avatar Jul 28 '22 16:07 triplef