[PATCH] D15556: [RS4GC] Fix crash in the case that a live variable has a constant base.

Manuel Jacob via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 19:48:29 PST 2015


mjacob created this revision.
mjacob added a reviewer: reames.
mjacob added a subscriber: llvm-commits.
Herald added a subscriber: sanjoy.

Previously, RS4GC crashed in CreateGCRelocates() because it assumed
that every base is also in the array of live variables, which isn't true if a
live variable has a constant base.

This change fixes the crash by making sure CreateGCRelocates() won't try to
relocate a live variable with a constant base.  This would be unnecessary
anyway because anything with a constant base won't move.

http://reviews.llvm.org/D15556

Files:
  lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  test/Transforms/RewriteStatepointsForGC/base-pointers-12.ll

Index: test/Transforms/RewriteStatepointsForGC/base-pointers-12.ll
===================================================================
--- /dev/null
+++ test/Transforms/RewriteStatepointsForGC/base-pointers-12.ll
@@ -0,0 +1,19 @@
+; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s
+
+; CHECK: derived %select base %global
+
+ at global = external addrspace(1) global i8
+
+define i8 @test() gc "statepoint-example" {
+  %derived1 = getelementptr i8, i8 addrspace(1)* @global, i64 1
+  %derived2 = getelementptr i8, i8 addrspace(1)* @global, i64 2
+  %select = select i1 undef, i8 addrspace(1)* %derived1, i8 addrspace(1)* %derived2
+  %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @extern, i32 0, i32 0, i32 0, i32 0)
+; CHECK-NOT: relocate
+  %load = load i8, i8 addrspace(1)* %select
+  ret i8 %load
+}
+
+declare void @extern() gc "statepoint-example"
+
+declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
Index: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
===================================================================
--- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1617,9 +1617,11 @@
   LiveVec.reserve(LiveSet.size());
   BaseVec.reserve(LiveSet.size());
   for (Value *L : LiveSet) {
+    Value *Base = PointerToBase.find(L)->second;
+    if (isa<Constant>(Base))
+      continue;
     LiveVec.push_back(L);
     assert(PointerToBase.count(L));
-    Value *Base = PointerToBase.find(L)->second;
     BaseVec.push_back(Base);
   }
   assert(LiveVec.size() == BaseVec.size());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15556.42960.patch
Type: text/x-patch
Size: 1731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151216/0f5c9c7b/attachment-0001.bin>


More information about the llvm-commits mailing list