]> granicus.if.org Git - llvm/commitdiff
Ensure non-null ProfileSummaryInfo passed to ModuleSummaryIndex builder
authorTeresa Johnson <tejohnson@google.com>
Wed, 10 May 2017 18:52:16 +0000 (18:52 +0000)
committerTeresa Johnson <tejohnson@google.com>
Wed, 10 May 2017 18:52:16 +0000 (18:52 +0000)
This fixes a ubsan bot failure after r302597, which made getProfileCount
non-static, but ended up invoking it on a null ProfileSummaryInfo object
in some cases from buildModuleSummaryIndex.

Most testing passed because the non-static getProfileCount currently
doesn't access any member variables, but I found this when testing a
follow on patch (D32877) that adds a member variable access.

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

lib/Analysis/ModuleSummaryAnalysis.cpp
lib/LTO/ThinLTOCodeGenerator.cpp
lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp

index 6c207f84286388d3bfd00009dd10f5a959a7434e..26706f5509bab0593a06611f2e524a10e9914039 100644 (file)
@@ -330,6 +330,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
     const Module &M,
     std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
     ProfileSummaryInfo *PSI) {
+  assert(PSI);
   ModuleSummaryIndex Index;
 
   // Identify the local values in the llvm.used and llvm.compiler.used sets,
index b4ee7c2b2fbc1fc0aa8ad1c488a58629e308dfce..f3d441db98cbba872f495a4adda74b6e887ae082 100644 (file)
@@ -446,7 +446,7 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
     {
       raw_svector_ostream OS(OutputBuffer);
       ProfileSummaryInfo PSI(TheModule);
-      auto Index = buildModuleSummaryIndex(TheModule, nullptr, nullptr);
+      auto Index = buildModuleSummaryIndex(TheModule, nullptr, &PSI);
       WriteBitcodeToFile(&TheModule, OS, true, &Index);
     }
     return make_unique<ObjectMemoryBuffer>(std::move(OutputBuffer));
index d3a3c24ce7b44a7d519ecb4cf49248aa1a1b2733..68884ce25bf8c00734364ddb94ac6e3a838e8f05 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "llvm/Analysis/BasicAliasAnalysis.h"
 #include "llvm/Analysis/ModuleSummaryAnalysis.h"
+#include "llvm/Analysis/ProfileSummaryInfo.h"
 #include "llvm/Analysis/TypeMetadataUtils.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
 #include "llvm/IR/Constants.h"
@@ -320,7 +321,8 @@ void splitAndWriteThinLTOBitcode(
 
 
   // FIXME: Try to re-use BSI and PFI from the original module here.
-  ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, nullptr);
+  ProfileSummaryInfo PSI(M);
+  ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
 
   SmallVector<char, 0> Buffer;