[PATCH] Fix a mergefunc crash caused by bitcasting intrinsics

Björn Steinbrink bsteinbr at gmail.com
Tue Apr 22 02:07:39 PDT 2014

  Generally skip the bitcast when dealing with function constants

  Bitcasting function constants is rather pointless here, as bitcasting one will
  not result in the other. So we can return early whenever one of the constants
  is a function, instead of having a special case for intrinsics.




Index: lib/Transforms/IPO/MergeFunctions.cpp
--- lib/Transforms/IPO/MergeFunctions.cpp
+++ lib/Transforms/IPO/MergeFunctions.cpp
@@ -465,6 +465,8 @@
     if (C1->isNullValue() && C2->isNullValue() &&
         isEquivalentType(C1->getType(), C2->getType()))
       return true;
+    if (isa<Function>(V1) || isa<Function>(V2))
+      return false;
     // Try bitcasting C2 to C1's type. If the bitcast is legal and returns C1
     // then they must have equal bit patterns.
     return C1->getType()->canLosslesslyBitCastTo(C2->getType()) &&
Index: test/Transforms/MergeFunc/intrinsics.ll
--- /dev/null
+++ test/Transforms/MergeFunc/intrinsics.ll
@@ -0,0 +1,22 @@
+; RUN: opt -mergefunc -disable-output < %s
+; This used to crash because mergefunc created a bitcast of an intrinsic.
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+declare i64 @llvm.bswap.i64(i64) unnamed_addr nounwind readnone
+declare i8* @breaker(i8*) unnamed_addr
+; Function Attrs: inlinehint uwtable
+define void @bswap_caller(i64) unnamed_addr {
+  call i64 @llvm.bswap.i64(i64 %0)
+  ret void
+; Function Attrs: inlinehint uwtable
+define internal void @collider(i8*) unnamed_addr {
+  call i8* @breaker(i8* %0)
+  ret void
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3437.2.patch
Type: text/x-patch
Size: 1543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140422/83723f15/attachment.bin>

More information about the llvm-commits mailing list