summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2017-10-19 04:47:48 +0000
committerwhitequark <whitequark@whitequark.org>2017-10-19 04:47:48 +0000
commita99ecf1bbb554df19b68805d2df8caa80ae0818d (patch)
tree2e2388d59e11a28afc9acf0d9f1b1482a9f321a1 /llvm
parentdeaba3862fc76fe82fede028c7046136b94031f7 (diff)
downloadbcm5719-llvm-a99ecf1bbb554df19b68805d2df8caa80ae0818d.tar.gz
bcm5719-llvm-a99ecf1bbb554df19b68805d2df8caa80ae0818d.zip
[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<GlobalValue *>. 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. llvm-svn: 316145
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Transforms/Utils/FunctionComparator.h4
-rw-r--r--llvm/lib/Transforms/IPO/MergeFunctions.cpp3
2 files changed, 7 insertions, 0 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/FunctionComparator.h b/llvm/include/llvm/Transforms/Utils/FunctionComparator.h
index e0c79a1027e..7698a068717 100644
--- a/llvm/include/llvm/Transforms/Utils/FunctionComparator.h
+++ b/llvm/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/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index bffbb8f060d..512de8f5c7e 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/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<GlobalValue *> 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);
OpenPOWER on IntegriCloud