[llvm] r249327 - MergeFunctions: Clear GlobalNumbers ValueMap

Arnold Schwaighofer via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 10:26:37 PDT 2015


Author: arnolds
Date: Mon Oct  5 12:26:36 2015
New Revision: 249327

URL: http://llvm.org/viewvc/llvm-project?rev=249327&view=rev
Log:
MergeFunctions: Clear GlobalNumbers ValueMap

Otherwise, the map will observe changes as long as MergeFunctions is alive. This
is bad because follow-up passes could replace-all-uses-with on the key of an
entry in the map. The value handle callback of ValueMap however asserts that the
key type matches.

rdar://22971893

Added:
    llvm/trunk/test/Transforms/MergeFunc/crash2.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp

Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=249327&r1=249326&r2=249327&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Mon Oct  5 12:26:36 2015
@@ -164,6 +164,9 @@ class GlobalNumberState {
         NextNumber++;
       return MapIter->second;
     }
+    void clear() {
+      GlobalNumbers.clear();
+    }
 };
 
 /// FunctionComparator - Compares two functions to determine whether or not
@@ -1546,6 +1549,7 @@ bool MergeFunctions::runOnModule(Module
   } while (!Deferred.empty());
 
   FnTree.clear();
+  GlobalNumbers.clear();
 
   return Changed;
 }

Added: llvm/trunk/test/Transforms/MergeFunc/crash2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeFunc/crash2.ll?rev=249327&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/MergeFunc/crash2.ll (added)
+++ llvm/trunk/test/Transforms/MergeFunc/crash2.ll Mon Oct  5 12:26:36 2015
@@ -0,0 +1,54 @@
+; RUN: opt %s -mergefunc -globalopt -S -o - | FileCheck %s
+
+; Make sure we don't crash on this example. This test is supposed to test that
+; MergeFunctions clears its GlobalNumbers value map. If this map still contains
+; entries when running globalopt and the MergeFunctions instance is still alive
+; the optimization of @G would cause an assert because globalopt would do an
+; RAUW on @G which still exists as an entry in the GlobalNumbers ValueMap which
+; causes an assert in the ValueHandle call back because we are RAUWing with a
+; different type (AllocaInst) than its key type (GlobalValue).
+
+ at G = internal global i8** null
+ at G2 = internal global i8** null
+
+define i32 @main(i32 %argc, i8** %argv) {
+; CHECK: alloca
+  store i8** %argv, i8*** @G
+  ret i32 0
+}
+
+define internal i8** @dead1(i64 %p) {
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  %tmp = load i8**, i8*** @G
+  ret i8** %tmp
+}
+
+define internal i8** @dead2(i64 %p) {
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  %tmp = load i8**, i8*** @G2
+  ret i8** %tmp
+}
+
+define void @left(i64 %p) {
+entry-block:
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  call void @right(i64 %p)
+  ret void
+}
+
+define void @right(i64 %p) {
+entry-block:
+  call void @left(i64 %p)
+  call void @left(i64 %p)
+  call void @left(i64 %p)
+  call void @left(i64 %p)
+  ret void
+}




More information about the llvm-commits mailing list