This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][ObjC] Fix infinite recursion in getObjCEncodingForTypeImpl
ClosedPublic

Authored by ahatanak on Jul 28 2016, 12:44 PM.

Details

Summary

This patch fixes a stack overflow bug in ASTContext::getObjCEncodingForTypeImpl where it keeps expanding a class recursively. I added a check to avoid expanding a class if ExpandStructures is false.

Diff Detail

Event Timeline

ahatanak updated this revision to Diff 65969.Jul 28 2016, 12:44 PM
ahatanak retitled this revision from to [CodeGen][ObjC] Fix infinite recursion in getObjCEncodingForTypeImpl.
ahatanak updated this object.
ahatanak added reviewers: doug.gregor, akyrtzi.
ahatanak added a subscriber: cfe-commits.

The fix looks reasonable to me.

Cheers,
Manman

test/CodeGenObjCXX/encode.mm
231

I wonder if we can further reduce the testing case. Is this necessary to cause the infinite recursion?

ahatanak added inline comments.Aug 16 2016, 2:53 PM
test/CodeGenObjCXX/encode.mm
231

Yes. If I remove the typedef and declare "t" as a pointer to "T", clang terminates normally. If you look at the code near ASTContext.cpp:5960, you'll see getObjCEncodingForTypeImpl is called recursively only if the pointee type is a typedef, which is why the typedef is necessary to cause infinite recursion in this case.

manmanren accepted this revision.Aug 16 2016, 4:48 PM
manmanren added a reviewer: manmanren.

LGTM.

Manman

This revision is now accepted and ready to land.Aug 16 2016, 4:48 PM
This revision was automatically updated to reflect the committed changes.