-Warc-repeated-use-of-weak should produce the same warnings with -fobjc-weak as it does with -objc-arc. Also check for ObjCWeak along with ObjCAutoRefCount when recording the use of an evaluated weak variable. Add a -fobjc-weak run to the existing arc-repeated-weak test case and adapt it slightly to work in both modes.
Details
Diff Detail
Event Timeline
The warning-related parts look reasonable to me.
lib/Sema/SemaDecl.cpp | ||
---|---|---|
10184 | This condition's getting complicated, and it shows up in a few places. Would it make sense to factor it out? | |
lib/Sema/SemaExpr.cpp | ||
706–707 | This is the one section that isn't dealing with the warning. I'd like @rjmccall to verify that it's correct. | |
10336 | Does ObjCAutoRefCount imply ObjCWeak? If so, you could just use the latter. |
lib/Sema/SemaDecl.cpp | ||
---|---|---|
10184 | I'm fine with it myself but I don't work on Clang very much anymore. Maybe someone else can say whether it's actually a good idea. (By the way, the conventional abbreviation for this mode is "MRR" for "Manual Retain/Release", even though it's "ARC" and "Automated Reference Counting".) | |
lib/Sema/SemaExpr.cpp | ||
10336 | Sure, but in that case we don't need the warning, right? |
lib/Sema/SemaDecl.cpp | ||
---|---|---|
10184 | Do you want to extract the out the entire (!getLangOpts().ObjCAutoRefCount && getLangOpts().ObjCWeak && VDecl->getType().getObjCLifetime() != Qualifiers::OCL_Weak) ? It looks like the others patches use only getLangOpts().ObjCWeak && Type.getObjCLifetime() != Qualifiers::OCL_Weak so the use of hasMRCNonTrivialWeakObjCLifetime won't be equivalent to the original code in the other patches if you extract all code from lines 10183-10184. | |
test/SemaObjC/arc-repeated-weak.mm | ||
468 | NIT: You can keep the code in foo1 active and just use the #if on the expected-error, like: void foo1() { INTFPtrTy tmp = (INTFPtrTy)e1; #if __has_feature(objc_arc) // expected-error@-2 {{cast of 'E' to 'INTFPtrTy' (aka 'INTF *') is disallowed with ARC}} #endif } |
lib/Sema/SemaDecl.cpp | ||
---|---|---|
10184 | Yeah, my suspicion was that the addition of !getLangOpts().ObjCAutoRefCount() would have been fine, but most of the other code was simplified by using hasNonTrivialObjCLifetime() or another means, so this new function seems to only be necessary in this patch. I misnamed the proposed function, which would imply the qualifier is OCL_Weak, but we need not that, so my new proposed name is the odd looking isNonWeakInMRRWithObjCWeak(). | |
lib/Sema/SemaExpr.cpp | ||
10336 | Oh, I see. Yeah, looks like I can update most of the checks to just use ObjCWeak. I think we need both conditions here, however, since checkUnsafeExprAssigns() emits the "assigning retained object to unsafe property" warning, which is only applicable in ARC. |
Thanks again for the feedback. Is there anything further I should update in this diff or is it looking good?
Thanks!
Brian
Just a couple of minor requests.
lib/Sema/SemaExpr.cpp | ||
---|---|---|
707 | Much like the other patches, it's probably more efficient to just check the qualifier here instead of testing the language option first. | |
2515–2516 | Same thing. | |
lib/Sema/SemaExprMember.cpp | ||
1504–1505 | Same. | |
lib/Sema/SemaPseudoObject.cpp | ||
843–844 | Same. |
Sorry for missing the unnecessary LangOpts checks here. Thanks again for the feedback!
Thank you @rjmccall for the approval. I don't have commit access; would someone be willing to commit this path for me please? Thanks!
This condition's getting complicated, and it shows up in a few places. Would it make sense to factor it out?