OSDN Git Service

Avoid undefined behavior in LinkAllPasses.h
authorDimitry Andric <dimitry@andric.com>
Wed, 13 Jan 2016 18:29:46 +0000 (18:29 +0000)
committerDimitry Andric <dimitry@andric.com>
Wed, 13 Jan 2016 18:29:46 +0000 (18:29 +0000)
commit67e14a34127b6cb8392ccb64a500cb9581ba308b
tree4622413b10a823235e13a0df999e745d4fe6219f
parent92df1747f60ccfe9e3500850f04159b1642fa17a
Avoid undefined behavior in LinkAllPasses.h

The LinkAllPasses.h file is included in several main programs, to force
a large number of passes to be linked in.  However, the ForcePassLinking
constructor uses undefined behavior, since it calls member functions on
`nullptr`, e.g.:

      ((llvm::Function*)nullptr)->viewCFGOnly();
      llvm::RGPassManager RGM;
      ((llvm::RegionPass*)nullptr)->runOnRegion((llvm::Region*)nullptr, RGM);

When the optimization level is -O2 or higher, the code below the first
nullptr dereference is optimized away, and replaced by `ud2` (on x86).

Therefore, the calls after that first dereference are never emitted.  In
my case, I noticed there was no call to `llvm::sys::RunningOnValgrind()`!

Replace instances of dereferencing `nullptr` with either objects on the
stack, or regular function calls.

Differential Revision: http://reviews.llvm.org/D15996

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257645 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/LinkAllPasses.h