This is an archive of the discontinued LLVM Phabricator instance.

[Sema] More changes to fix Objective-C fallout from r249995.
ClosedPublic

Authored by bob.wilson on Feb 11 2016, 1:12 PM.

Details

Summary

This is a follow-up to PR26085. That was fixed in r257710 but the testcase there was incomplete. There is a related issue where the overload resolution for Objective-C incorrectly picks a method that is not valid without a bridge cast. The call to Sema::CheckSingleAssignmentConstraints that was added to SemaOverload.cpp's IsStandardConversion() function does not catch that case and reports that the method is Compatible even when it is not.

The root cause here is that various Objective-C-related functions in Sema do not consistently return a value to indicate whether there was an error. This was fine in the past because they would report diagnostics when needed, but r257710 changed them to suppress reporting diagnostics when checking during overload resolution.

This patch adds a new ACR_error result to the ARCConversionResult enum and updates Sema::CheckObjCARCConversion to return that value when there is an error. Most of the calls to that function do not check the return value, so adding this new result does not affect them. The one exception is in SemaCast.cpp where it specifically checks for ACR_unbridged, so that is also OK. The call in Sema::CheckSingleAssignmentConstraints can then check for an ACR_okay result and identify assignments as Incompatible. To preserve the existing behavior, it only changes the return value to Incompatible when the new Diagnose argument (from r257710) is false.

Similarly, the CheckObjCBridgeRelatedConversions and ConversionToObjCStringLiteralCheck need to identify when an assignment is Incompatible. Those functions already return appropriate values but they need some fixes related to the new Diagnose argument.

Diff Detail

Event Timeline

bob.wilson updated this revision to Diff 47692.Feb 11 2016, 1:12 PM
bob.wilson retitled this revision from to [Sema] More changes to fix Objective-C fallout from r249995..
bob.wilson updated this object.
george.burgess.iv edited edge metadata.

Sorry that the change to overload resolution turned out to be problematic. :)

One nit, and this LGTM.

lib/Sema/SemaExpr.cpp
7580

Because we're doing a similar thing at line 7573 (not necessarily replacing an expression, but still answering differently depending on the value of Diagnose), can we either put a similar comment there, or make this comment a bit more general and move it above if (getLangOpts().ObjCAutoRefCount && [...]?

This revision is now accepted and ready to land.Feb 11 2016, 2:36 PM
bob.wilson closed this revision.Feb 12 2016, 5:50 PM
bob.wilson marked an inline comment as done.

Committed in r260787.

I had previously missed a regression in one of the existing ovl-check.m tests. The testTakesCFTypeRef function was checking that the CFTypeRef overload was selected. However, that does not match the behavior prior to r249995, where neither overload candidate is chosen as the "best match" and clang falls back to using the first one. With my change here, the previous behavior is restored. I reordered the two overload candidates in the test to match that. While I was at it, I also merged my "Type2" typedef with the existing CFTypeRef in the test.

lib/Sema/SemaExpr.cpp
7580

Good idea. I'm going to put a comment above the "if" but I'll also leave something to explain why the expression is replaced. (I'm also going to change those "result = Incompatible" lines to just return, since there is no point in continuing with further checks if we're not reporting the diagnostics anyway.)