This change puts the functionality in commit c5792aa90fa45a1842f190c146f19e2c71ea6fbd behind a flag that is off by default. The original commit is not in Apple's Clang fork (and blocks are an Apple extension in the first place), and there is one known issue that needs to be addressed before it can be enabled safely.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Sorry for the delay in responding.
Instead of reverting the commit, can we put this optimization behind an off-by-default flag? As far as we can tell, the only problem we have now that is preventing us to enable this optimization is that clang doesn't copy a block to the heap when the block is converted to a non-block type (e.g., const void *) in some cases.
For example, the block isn't copied to the heap in the following example. Note that this happens without the optimization this patch is reverting.
void foo1(const void *) __attribute__((cf_audited_transfer )); void foo2(id a) { // clang should copy the block to the heap, since foo1 doesn't know it's receiving a block, but it doesn't. foo1((const void *)^{ (void)a; }); }
This doesn't look too hard to fix. We probably just have to insert ARCExtendBlockObject into the AST.
Once we fix that problem, we can turn on the flag in both open source and Apple's compiler.
Do you need arc-blocks-avoid-heapify.m? It seems like the other tests already cover all the cases we care about.
You're right much of it is redundant, but test10a() and test10b() are still meaningful. I've deleted the redundant tests.
Can you add a driver test, which tests both -fobjc-avoid-heapify-local-blocks and -fno-objc-avoid-heapify-local-blocks?
Other than that, LGTM.
@ahatanak did you intend to ask Walt to add a driver flag for this?
I think we should not have one, since this isn't something we should be telling users to specify, or that we want to promise stability for.
I was just asking for test cases as I thought it was already a driver option, but it turns out it wasn't. I agree that this shouldn't be a driver option.
Sorry @waltl, please revert the changes that made it a driver option in the last patch.
clang/include/clang/Driver/Options.td | ||
---|---|---|
2376 | Needs to be marked [CC1Option, NoDriverOption] |
Needs to be marked [CC1Option, NoDriverOption]