]> granicus.if.org Git - clang/commit
[CodeGen][ObjC] Build the global block structure before emitting the
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 22 Sep 2017 21:32:06 +0000 (21:32 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 22 Sep 2017 21:32:06 +0000 (21:32 +0000)
commita3394c6dfe197d84e74eae9cc8b77dc4356cff54
tree965db59439351d8a775160f799b6e82f9ecc6afd
parentb20ea24998ffb8846c804b6e45f07660972e30db
[CodeGen][ObjC] Build the global block structure before emitting the
body of global block invoke functions.

This commit fixes an infinite loop in IRGen that occurs when compiling
the following code:

void FUNC2() {
  static void (^const block1)(int) = ^(int a){
    if (a--)
      block1(a);
  };
}

This is how IRGen gets stuck in the infinite loop:

1. GenerateBlockFunction is called to emit the body of "block1".

2. GetAddrOfGlobalBlock is called to get the address of "block1". The
   function calls getAddrOfGlobalBlockIfEmitted to check whether the
   global block has been emitted. If it hasn't been emitted, it then
   tries to emit the body of the block function by calling
   GenerateBlockFunction, which goes back to step 1.

This commit prevents the inifinite loop by building the global block in
GenerateBlockFunction before emitting the body of the block function.

rdar://problem/34541684

Differential Revision: https://reviews.llvm.org/D38118

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314029 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGen/mangle-blocks.c
test/CodeGenObjC/local-static-block.m
test/CodeGenObjC/mangle-blocks.m