Skip to content

Commit 816c975

Browse files
authored
Fix crash from [CGData] Global Merge Functions (llvm#112671) (llvm#116241)
Module summary index is optional for this pass, and we shouldn't run it, but import it as necessary.
1 parent 3be3b33 commit 816c975

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

llvm/include/llvm/CodeGen/GlobalMergeFunctions.h

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class GlobalMergeFunc {
7878

7979
/// Global function merging pass for new pass manager.
8080
struct GlobalMergeFuncPass : public PassInfoMixin<GlobalMergeFuncPass> {
81+
const ModuleSummaryIndex *ImportSummary = nullptr;
82+
GlobalMergeFuncPass() = default;
83+
GlobalMergeFuncPass(const ModuleSummaryIndex *ImportSummary)
84+
: ImportSummary(ImportSummary) {}
8185
PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
8286
};
8387

llvm/lib/CodeGen/GlobalMergeFunctions.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ bool GlobalMergeFuncPassWrapper::runOnModule(Module &M) {
637637

638638
PreservedAnalyses GlobalMergeFuncPass::run(Module &M,
639639
AnalysisManager<Module> &AM) {
640-
ModuleSummaryIndex *Index = &(AM.getResult<ModuleSummaryIndexAnalysis>(M));
641-
bool Changed = GlobalMergeFunc(Index).run(M);
640+
bool Changed = GlobalMergeFunc(ImportSummary).run(M);
642641
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
643642
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; This test checks if the global merge func pass should not build module summary.
2+
3+
; RUN: opt --passes=global-merge-func %s -o /dev/null
4+
5+
@0 = global { { ptr, i32, i32 } } { { ptr, i32, i32 } { ptr null, i32 19, i32 5 } }
6+
@1 = global { { ptr, i32, i32 } } { { ptr, i32, i32 } { ptr null, i32 22, i32 5 } }

0 commit comments

Comments
 (0)