This is an archive of the discontinued LLVM Phabricator instance.

[ARC][ObjC++] Use ObjC semantic rules for comparisons between a pointer and objective-c object pointer
ClosedPublic

Authored by arphaman on Mar 21 2017, 3:03 AM.

Details

Summary

When ARC is enabled in Objective-C++, comparisons between a pointer and Objective-C object pointer typically result in errors like this: invalid operands to a binary expression. This error message can be quite confusing as it doesn't provide a solution to the problem, unlike the non-C++ diagnostic: implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast (it also provides fix-its). This patch forces comparisons between pointers and objective-c object pointers in ARC to use the Objective-C semantic rules to ensure that a better diagnostic is reported.

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman created this revision.Mar 21 2017, 3:03 AM
ahatanak added inline comments.Mar 21 2017, 1:05 PM
lib/Sema/SemaExpr.cpp
9431 ↗(On Diff #92445)

It wasn't clear to me why the code has to be added to the right hand side of the >= operator.

Is it equivalent to adding the following code, which I think is easier to understand? I'm assuming you are trying to avoid executing the statement when ObjCAutoRefCount is true and either LHSType or RHSType is an objc pointer type.

&& (!LangOpts.ObjCAutoRefCount || (!LHSType->isObjCObjectPointerType() && !RHSType->isObjCObjectPointerType()))
arphaman added inline comments.Mar 23 2017, 5:06 AM
lib/Sema/SemaExpr.cpp
9431 ↗(On Diff #92445)

Yes, that's correct. I think a more clear condition would be better here, I agree.

arphaman updated this revision to Diff 92783.Mar 23 2017, 5:07 AM
arphaman marked an inline comment as done.

The condition in the if is now more clear.

ahatanak accepted this revision.Mar 23 2017, 7:41 AM

Thanks, LGTM.

This revision is now accepted and ready to land.Mar 23 2017, 7:41 AM
This revision was automatically updated to reflect the committed changes.