This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Don't allow applying address-of operator to a call to a function with __unknown_anytype return type
ClosedPublic

Authored by ahatanak on Nov 17 2016, 11:38 AM.

Details

Summary

This patch fixes an assert in CodeGenFunction::EmitCallExprLValue that is triggered when the CallExpr's return type is not a reference type:

assert(E->getCallReturnType(getContext())->isReferenceType() &&

"Can't have a scalar return unless the return type is a "
"reference type!");

Alternatively, since it's legal to apply the address-of operator to a reference return, we can change the function return type to be a reference (in the test case, that would be double&) in RebuildUnknownAnyExpr::VisitUnaryAddrOf when compiling for C++ (but not when compiling for C).

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak updated this revision to Diff 78396.Nov 17 2016, 11:38 AM
ahatanak retitled this revision from to [Sema] Don't allow applying address-of operator to a call to a function with __unknown_anytype return type.
ahatanak updated this object.
ahatanak added reviewers: doug.gregor, spyffe.
ahatanak added a subscriber: cfe-commits.
spyffe accepted this revision.Nov 18 2016, 11:08 AM
spyffe edited edge metadata.

I think it's all right to be conservative here. The inference rules could get quite complicated if (for example) the use looked like this

extern void foo (double *bar);
extern __unknown_anytype func();
// ...
foo(&func());

One could come up with even more complicated cases. It's probably not worth making sure they all work.

This revision is now accepted and ready to land.Nov 18 2016, 11:08 AM
This revision was automatically updated to reflect the committed changes.