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 Mon, Aug 12, 10:14 AM.

Details

Reviewers
rjmccall
Summary

This is the patch I split out of https://reviews.llvm.org/D64464.

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 https://reviews.llvm.org/D64464 wasn't handling that case correctly.

rdar://problem/51867864

Diff Detail

Repository
rC Clang

Event Timeline

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

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

rjmccall added inline comments.Tue, Aug 13, 4:10 PM
clang/lib/CodeGen/CGCall.h
372

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.

390

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.