Skip to content

Commit

Permalink
Fix crash from [CGData] Global Merge Functions (llvm#112671) (llvm#11…
Browse files Browse the repository at this point in the history
…6241)

Module summary index is optional for this pass, and we shouldn't run it,
but import it as necessary.
  • Loading branch information
kyulee-com authored Nov 15, 2024
1 parent 3be3b33 commit 816c975
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalMergeFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class GlobalMergeFunc {

/// Global function merging pass for new pass manager.
struct GlobalMergeFuncPass : public PassInfoMixin<GlobalMergeFuncPass> {
const ModuleSummaryIndex *ImportSummary = nullptr;
GlobalMergeFuncPass() = default;
GlobalMergeFuncPass(const ModuleSummaryIndex *ImportSummary)
: ImportSummary(ImportSummary) {}
PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
};

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/GlobalMergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ bool GlobalMergeFuncPassWrapper::runOnModule(Module &M) {

PreservedAnalyses GlobalMergeFuncPass::run(Module &M,
AnalysisManager<Module> &AM) {
ModuleSummaryIndex *Index = &(AM.getResult<ModuleSummaryIndexAnalysis>(M));
bool Changed = GlobalMergeFunc(Index).run(M);
bool Changed = GlobalMergeFunc(ImportSummary).run(M);
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
}
6 changes: 6 additions & 0 deletions llvm/test/CodeGen/Generic/cgdata-merge-crash.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; This test checks if the global merge func pass should not build module summary.

; RUN: opt --passes=global-merge-func %s -o /dev/null

@0 = global { { ptr, i32, i32 } } { { ptr, i32, i32 } { ptr null, i32 19, i32 5 } }
@1 = global { { ptr, i32, i32 } } { { ptr, i32, i32 } { ptr null, i32 22, i32 5 } }

0 comments on commit 816c975

Please sign in to comment.