BitcodeReader: Fix some BlockAddress forward reference corner cases
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 1 Aug 2014 21:11:34 +0000 (21:11 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 1 Aug 2014 21:11:34 +0000 (21:11 +0000)
commitcf8b959e8d938d39c0899365d98426cdbd96ed93
treec36e255a4d41e330f7ba4790375c3bb0bd9c7a2b
parentfc15e8a60f93f3e2a2075324c238e65754c5c6e7
BitcodeReader: Fix some BlockAddress forward reference corner cases

`BlockAddress`es are interesting in that they can reference basic blocks
from *outside* the block's function.  Since basic blocks are not global
values, this presents particular challenges for lazy parsing.

One corner case was found in PR11677 and fixed in r147425.  In that
case, a global variable references a block address.  It's necessary to
load the relevant function to resolve the forward reference before doing
anything with the module.

By inspection, I found (and have fixed here) two other cases:

  - An instruction from one function references a block address from
    another function, and only the first function is lazily loaded.

    I fixed this the same way as PR11677: by eagerly loading the
    referenced function.

  - A function whose block address is taken is dematerialized, leaving
    invalid references to it.

    I fixed this by refusing to dematerialize functions whose block
    addresses are taken (if you have to load it, you can't unload it).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214559 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Bitcode/ReaderWriter.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Reader/BitcodeReader.h
unittests/Bitcode/BitReaderTest.cpp