Page MenuHomePhabricator

[CodeGen] Emit destructor calls for non-trivial C structs returned by function calls and loaded from volatile objects
Needs ReviewPublic

Authored by ahatanak on Aug 12 2019, 10:14 AM.



This is the patch I split out of

The cleanup is pushed in EmitCallExpr and EmitObjCMessageExpr so that the destructor is called to destruct function call and ObjC message returns. I also added test cases for block function calls since the patch in wasn't handling that case correctly.


Diff Detail

rC Clang

Event Timeline

ahatanak created this revision.Aug 12 2019, 10:14 AM
ahatanak updated this revision to Diff 214660.Aug 12 2019, 10:26 AM

Revert changes I made to llvm that are unrelated to this patch.

rjmccall added inline comments.Aug 13 2019, 4:10 PM

Does llvm::Value* actually guarantee three bits? Presumably on 64-bit platforms, but we do support 32-bit hosts.

Fortunately, I don't actually think there's any reason to be space-conscious in this class; all the values are short-lived. Might as well pull all the fields out into a bit-field or something.


I think the "is externally destructed" semantics make more sense — that is, the *default* should be that a destructor needs to get pushed, and maybe specific contexts should suppress that. That will also let you avoid all the ugly code to compute whether destruction is required in a bunch of generic places.

Actually, "externally destructed" is a really problematic idea; we need to come up with a better solution for contexts that need to be careful about destructor ordering like this, and it should probably be based on passing around and deactivating destructors. But that's for later.