From: whitequark Date: Thu, 19 Oct 2017 04:47:48 +0000 (+0000) Subject: [MergeFunctions] Don't blindly RAUW a GlobalValue with a ConstantExpr. X-Git-Tag: android-x86-7.1-r4~9546 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1fd7e8c37af621d75b191deec9721b23ca36c9ea;p=android-x86%2Fexternal-llvm.git [MergeFunctions] Don't blindly RAUW a GlobalValue with a ConstantExpr. MergeFunctions uses (through FunctionComparator) a map of GlobalValues to identifiers because it needs to compare functions and globals do not have an inherent total order. Thus, FunctionComparator (through GlobalNumberState) has a ValueMap. r315852 added a RAUW on globals that may have been previously encountered by the FunctionComparator, which would replace a GlobalValue * key with a ConstantExpr *, which is illegal. This commit adjusts that code path to remove the function being replaced from the ValueMap as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316145 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Transforms/Utils/FunctionComparator.h b/include/llvm/Transforms/Utils/FunctionComparator.h index e0c79a1027e..7698a068717 100644 --- a/include/llvm/Transforms/Utils/FunctionComparator.h +++ b/include/llvm/Transforms/Utils/FunctionComparator.h @@ -78,6 +78,10 @@ public: return MapIter->second; } + void erase(GlobalValue *Global) { + GlobalNumbers.erase(Global); + } + void clear() { GlobalNumbers.clear(); } diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index bffbb8f060d..512de8f5c7e 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -629,6 +629,9 @@ void MergeFunctions::filterInstsUnrelatedToPDI( void MergeFunctions::writeThunk(Function *F, Function *G) { if (!G->isInterposable() && !MergeFunctionsPDI) { if (G->hasGlobalUnnamedAddr()) { + // G might have been a key in our GlobalNumberState, and it's illegal + // to replace a key in ValueMap with a non-global. + GlobalNumbers.erase(G); // If G's address is not significant, replace it entirely. Constant *BitcastF = ConstantExpr::getBitCast(F, G->getType()); G->replaceAllUsesWith(BitcastF);