[llvm-branch-commits] [llvm-branch] r257660 - Merging r257645:

Dimitry Andric via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 13 11:37:52 PST 2016


Author: dim
Date: Wed Jan 13 13:37:51 2016
New Revision: 257660

URL: http://llvm.org/viewvc/llvm-project?rev=257660&view=rev
Log:
Merging r257645:
------------------------------------------------------------------------
r257645 | dim | 2016-01-13 19:29:46 +0100 (Wed, 13 Jan 2016) | 22 lines

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

------------------------------------------------------------------------

Modified:
    llvm/branches/release_38/   (props changed)
    llvm/branches/release_38/include/llvm/LinkAllPasses.h

Propchange: llvm/branches/release_38/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 13 13:37:51 2016
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241
+/llvm/trunk:155241,257645

Modified: llvm/branches/release_38/include/llvm/LinkAllPasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_38/include/llvm/LinkAllPasses.h?rev=257660&r1=257659&r2=257660&view=diff
==============================================================================
--- llvm/branches/release_38/include/llvm/LinkAllPasses.h (original)
+++ llvm/branches/release_38/include/llvm/LinkAllPasses.h Wed Jan 13 13:37:51 2016
@@ -160,9 +160,11 @@ namespace {
       (void) llvm::createPostOrderFunctionAttrsPass();
       (void) llvm::createReversePostOrderFunctionAttrsPass();
       (void) llvm::createMergeFunctionsPass();
-      (void) llvm::createPrintModulePass(*(llvm::raw_ostream*)nullptr);
-      (void) llvm::createPrintFunctionPass(*(llvm::raw_ostream*)nullptr);
-      (void) llvm::createPrintBasicBlockPass(*(llvm::raw_ostream*)nullptr);
+      std::string buf;
+      llvm::raw_string_ostream os(buf);
+      (void) llvm::createPrintModulePass(os);
+      (void) llvm::createPrintFunctionPass(os);
+      (void) llvm::createPrintBasicBlockPass(os);
       (void) llvm::createModuleDebugInfoPrinterPass();
       (void) llvm::createPartialInliningPass();
       (void) llvm::createLintPass();
@@ -186,10 +188,10 @@ namespace {
 
       (void)new llvm::IntervalPartition();
       (void)new llvm::ScalarEvolutionWrapperPass();
-      ((llvm::Function*)nullptr)->viewCFGOnly();
+      llvm::Function::Create(nullptr, llvm::GlobalValue::ExternalLinkage)->viewCFGOnly();
       llvm::RGPassManager RGM;
-      ((llvm::RegionPass*)nullptr)->runOnRegion((llvm::Region*)nullptr, RGM);
-      llvm::AliasSetTracker X(*(llvm::AliasAnalysis*)nullptr);
+      llvm::AliasAnalysis AA;
+      llvm::AliasSetTracker X(AA);
       X.add(nullptr, 0, llvm::AAMDNodes()); // for -print-alias-sets
       (void) llvm::AreStatisticsEnabled();
       (void) llvm::sys::RunningOnValgrind();




More information about the llvm-branch-commits mailing list